X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_mon%2Fdashboarder%2Fservice.py;h=9f184d26cca809b0bea7e08de584df71339bd2b3;hb=refs%2Fchanges%2F41%2F8741%2F3;hp=10dc0f771214d8a5e31fca77eded3885031919c7;hpb=456d0f323cfcb5fe6b8cad5a6c3e6633875633cd;p=osm%2FMON.git diff --git a/osm_mon/dashboarder/service.py b/osm_mon/dashboarder/service.py index 10dc0f7..9f184d2 100644 --- a/osm_mon/dashboarder/service.py +++ b/osm_mon/dashboarder/service.py @@ -24,7 +24,8 @@ import logging from osm_mon.core.common_db import CommonDbClient from osm_mon.core.config import Config -import osm_mon.dashboarder.backends.grafana as grafana +from osm_mon.dashboarder.backends.grafana import GrafanaBackend +from osm_mon import __path__ as mon_path log = logging.getLogger(__name__) @@ -33,11 +34,12 @@ class DashboarderService: def __init__(self, config: Config): self.conf = config self.common_db = CommonDbClient(self.conf) + self.grafana = GrafanaBackend(self.conf) def create_dashboards(self): # TODO lavado: migrate these methods to mongo change streams # Lists all dashboards and OSM resources for later comparisons - dashboard_uids = grafana.get_all_dashboard_uids() + dashboard_uids = self.grafana.get_all_dashboard_uids() osm_resource_uids = [] # Reads existing project list and creates a dashboard for each @@ -46,11 +48,11 @@ class DashboarderService: project_id = project['_id'] # Collect Project IDs for periodical dashboard clean-up osm_resource_uids.append(project_id) - dashboard_path = '/mon/osm_mon/dashboarder/templates/project_scoped.json' + dashboard_path = '{}/dashboarder/templates/project_scoped.json'.format(mon_path[0]) if project_id not in dashboard_uids: project_name = project['name'] - grafana.create_dashboard(project_id, project_name, - dashboard_path) + self.grafana.create_dashboard(project_id, project_name, + dashboard_path) log.debug('Created dashboard for Project: %s', project_id) else: log.debug('Dashboard already exists') @@ -60,7 +62,7 @@ class DashboarderService: nsrs = self.common_db.get_nsrs() for nsr in nsrs: nsr_id = nsr['_id'] - dashboard_path = '/mon/osm_mon/dashboarder/templates/ns_scoped.json' + dashboard_path = '{}/dashboarder/templates/ns_scoped.json'.format(mon_path[0]) # Collect NS IDs for periodical dashboard clean-up osm_resource_uids.append(nsr_id) # Check if the NSR's VNFDs contain metrics @@ -72,8 +74,8 @@ class DashboarderService: if 'monitoring-param' in vnfd: if nsr_id not in dashboard_uids: nsr_name = nsr['name'] - grafana.create_dashboard(nsr_id, nsr_name, - dashboard_path) + self.grafana.create_dashboard(nsr_id, nsr_name, + dashboard_path) log.debug('Created dashboard for NS: %s', nsr_id) else: log.debug('Dashboard already exists') @@ -87,7 +89,7 @@ class DashboarderService: # Delete obsolete dashboards for dashboard_uid in dashboard_uids: if dashboard_uid not in osm_resource_uids: - grafana.delete_dashboard(dashboard_uid) + self.grafana.delete_dashboard(dashboard_uid) log.debug('Deleted obsolete dashboard: %s', dashboard_uid) else: log.debug('All dashboards in use')