diff --git a/docker-compose/tango-prometheus-exporter/code/tango-prometheus-client.py b/docker-compose/tango-prometheus-exporter/code/tango-prometheus-client.py index 86298311c3247eef342becd6d2679c8cea41e6a8..f00be30ab836b2735b59c0b9c177ee450698a102 100644 --- a/docker-compose/tango-prometheus-exporter/code/tango-prometheus-client.py +++ b/docker-compose/tango-prometheus-exporter/code/tango-prometheus-client.py @@ -37,8 +37,33 @@ class ArchiverPolicy(object): def __init__(self, config: dict = None): self.config = config or self.EMPTY_POLICY + def device_list(self) -> list: + """ Retrieve the device list from TangoDB """ + device_list = [] + db = Database() + server_list = db.get_server_list() # e.g. SDP/STAT, RECV/STAT + for server in server_list: + # https://pytango.readthedocs.io/en/stable/database.html#tango.Database.get_device_class_list + class_list = db.get_device_class_list(server) + for cls in class_list[::2]: + if "dserver" in cls: + continue + device_list.append(cls.lower()) + return device_list + def devices(self) -> list: - return list(self.config["devices"].keys()) + """ Filter the device list from TangoDB following the lofar2-policy file """ + # Devices list from TangoDB + db_devices = self.device_list() + # Devices listed in policy file + config_devices = list(k.lower() for k in self.config["devices"].keys()) + # Match device names fetched from DB against device names in policy file + devices = [] + for config_dev in config_devices: + for db_dev in db_devices: + if fnmatch.fnmatch(db_dev, config_dev): + devices.append(db_dev) + return devices def attribute_list(self, device_name: str, attribute_list: list) -> dict: """ Return the full set of archiving policy for the given device. """ @@ -184,7 +209,7 @@ class CustomCollector(object): attribute_metrics = GaugeMetricFamily("device_attribute", 'Device attribute value', labels=['station', 'device', 'name', 'str_value', 'type', 'x', 'y', 'idx']) scraping_metrics = GaugeMetricFamily("device_scraping", 'Device scraping duration', labels=['station', 'device']) - + for device_name in self.policy.devices(): logger.debug(f"Processing device {device_name}") dev_scrape_begin = time.time() diff --git a/docker-compose/tango-prometheus-exporter/lofar2-policy.json b/docker-compose/tango-prometheus-exporter/lofar2-policy.json index 5ce4117166e120d82b85b85025371a6d4af568c8..994d9dd1877b87ab7ccecbcfe325c97333dd7f92 100644 --- a/docker-compose/tango-prometheus-exporter/lofar2-policy.json +++ b/docker-compose/tango-prometheus-exporter/lofar2-policy.json @@ -29,6 +29,10 @@ }, "STAT/Docker/1": { }, + "STAT/Observation/*":{ + }, + "STAT/ObservationControl/1":{ + }, "STAT/PSOC/1": { }, "STAT/PCON/1": {