Skip to content
Snippets Groups Projects
Commit 8e10f54c authored by Stefano Di Frischia's avatar Stefano Di Frischia
Browse files

Merge branch 'L2SS-777-add-observations-to-prometheus-exporter' into 'master'

Resolve L2SS-777 "Add observations to prometheus exporter"

Closes L2SS-777

See merge request !387
parents 4b96231f ef484dc1
No related branches found
No related tags found
1 merge request!387Resolve L2SS-777 "Add observations to prometheus exporter"
...@@ -37,8 +37,33 @@ class ArchiverPolicy(object): ...@@ -37,8 +37,33 @@ class ArchiverPolicy(object):
def __init__(self, config: dict = None): def __init__(self, config: dict = None):
self.config = config or self.EMPTY_POLICY 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: 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: def attribute_list(self, device_name: str, attribute_list: list) -> dict:
""" Return the full set of archiving policy for the given device. """ """ Return the full set of archiving policy for the given device. """
...@@ -184,7 +209,7 @@ class CustomCollector(object): ...@@ -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']) 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']) scraping_metrics = GaugeMetricFamily("device_scraping", 'Device scraping duration', labels=['station', 'device'])
for device_name in self.policy.devices(): for device_name in self.policy.devices():
logger.debug(f"Processing device {device_name}") logger.debug(f"Processing device {device_name}")
dev_scrape_begin = time.time() dev_scrape_begin = time.time()
......
...@@ -29,6 +29,10 @@ ...@@ -29,6 +29,10 @@
}, },
"STAT/Docker/1": { "STAT/Docker/1": {
}, },
"STAT/Observation/*":{
},
"STAT/ObservationControl/1":{
},
"STAT/PSOC/1": { "STAT/PSOC/1": {
}, },
"STAT/PCON/1": { "STAT/PCON/1": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment