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

L2SS-777: update archiver-policy devices

parent af11f405
Branches
Tags
1 merge request!387Resolve L2SS-777 "Add observations to prometheus exporter"
...@@ -6,6 +6,7 @@ from tango import Database, DeviceProxy, CmdArgType as ArgType, AttrDataFormat, ...@@ -6,6 +6,7 @@ from tango import Database, DeviceProxy, CmdArgType as ArgType, AttrDataFormat,
import logging import logging
import json import json
import fnmatch import fnmatch
import re
from logstash_async.handler import AsynchronousLogstashHandler, LogstashFormatter from logstash_async.handler import AsynchronousLogstashHandler, LogstashFormatter
logger = logging.getLogger() logger = logging.getLogger()
...@@ -37,8 +38,42 @@ class ArchiverPolicy(object): ...@@ -37,8 +38,42 @@ 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 i in range(0, len(server_list)):
# https://pytango.readthedocs.io/en/stable/database.html#tango.Database.get_device_class_list
class_list = db.get_device_class_list(server_list[i])
for j in range(0, len(class_list), 2):
if "dserver" in class_list[j]:
continue
device_list.append(class_list[j].lower())
return device_list
def multimember_device_list(config_devices: list) -> list:
""" Retrieve multimember devices if there are any regulare expressions in the policy file """
multimember_devices = []
for device in config_devices:
if re.match('.*/.*/[*]', device):
members = Database().get_device_member(device)
retrieved_devices = [f"{device[:-1]}{m}" for m in members]
multimember_devices += retrieved_devices
return multimember_devices
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())
# Multimember device list
multimember_devices = self.multimember_device_list
# Filter devices following policy file
devices = [x for x in db_devices if x in config_devices]
devices += multimember_devices
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. """
...@@ -176,20 +211,6 @@ class CustomCollector(object): ...@@ -176,20 +211,6 @@ class CustomCollector(object):
return metrics return metrics
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 i in range(0, len(server_list)):
# https://pytango.readthedocs.io/en/stable/database.html#tango.Database.get_device_class_list
class_list = db.get_device_class_list(server_list[i])
for j in range(0, len(class_list), 2):
if "dserver" in class_list[j]:
continue
device_list.append(class_list[j].lower())
return device_list
def collect(self): def collect(self):
""" Yield all scraped metrics from all devices, as configured. """ """ Yield all scraped metrics from all devices, as configured. """
......
...@@ -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/RECV/1": { "STAT/RECV/1": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment