From: lavado Date: Mon, 11 Nov 2019 11:41:38 +0000 (-0500) Subject: Adding more labels to Prometheus metrics X-Git-Tag: v7.0.0rc1~13^2 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F41%2F8141%2F14;p=osm%2FMON.git Adding more labels to Prometheus metrics Change-Id: I412de4ee47808af09e4156b703a95d1edb5fbca7 Signed-off-by: lavado --- diff --git a/osm_mon/collector/vnf_collectors/juju.py b/osm_mon/collector/vnf_collectors/juju.py index b8c8b4e..8be9e28 100644 --- a/osm_mon/collector/vnf_collectors/juju.py +++ b/osm_mon/collector/vnf_collectors/juju.py @@ -47,6 +47,12 @@ class VCACollector(BaseCollector): nsr_id = vnfr['nsr-id-ref'] vnf_member_index = vnfr['member-vnf-index-ref'] vnfd = self.common_db.get_vnfd(vnfr['vnfd-id']) + + # Populate extra tags for metrics + tags = {} + tags['ns_name'] = self.common_db.get_nsr(nsr_id)['name'] + tags['project_id'] = vnfr['_admin']['projects_read'][0] + metrics = [] for vdur in vnfr['vdur']: # This avoids errors when vdur records have not been completely filled @@ -69,7 +75,7 @@ class VCACollector(BaseCollector): for measure in measure_list: log.debug("Measure: %s", measure) metric = VnfMetric(nsr_id, vnf_member_index, vdur['name'], measure['key'], - float(measure['value'])) + float(measure['value'], tags)) metrics.append(metric) if 'vnf-configuration' in vnfd and 'metrics' in vnfd['vnf-configuration']: try: @@ -83,7 +89,7 @@ class VCACollector(BaseCollector): for measure_list in measures.values(): for measure in measure_list: log.debug("Measure: %s", measure) - metric = VnfMetric(nsr_id, vnf_member_index, '', measure['key'], float(measure['value'])) + metric = VnfMetric(nsr_id, vnf_member_index, '', measure['key'], float(measure['value'], tags)) metrics.append(metric) return metrics diff --git a/osm_mon/collector/vnf_collectors/openstack.py b/osm_mon/collector/vnf_collectors/openstack.py index 16b9152..122fdd6 100644 --- a/osm_mon/collector/vnf_collectors/openstack.py +++ b/osm_mon/collector/vnf_collectors/openstack.py @@ -80,6 +80,12 @@ class OpenstackCollector(BaseVimCollector): nsr_id = vnfr['nsr-id-ref'] vnf_member_index = vnfr['member-vnf-index-ref'] vnfd = self.common_db.get_vnfd(vnfr['vnfd-id']) + + # Populate extra tags for metrics + tags = {} + tags['ns_name'] = self.common_db.get_nsr(nsr_id)['name'] + tags['project_id'] = vnfr['_admin']['projects_read'][0] + metrics = [] for vdur in vnfr['vdur']: # This avoids errors when vdur records have not been completely filled @@ -106,7 +112,6 @@ class OpenstackCollector(BaseVimCollector): value = self.backend.collect_metric(metric_type, openstack_metric_name, resource_id, interface_name) if value is not None: - tags = {} if interface_name: tags['interface'] = interface_name metric = VnfMetric(nsr_id, vnf_member_index, vdur['name'], metric_name, value, tags) diff --git a/osm_mon/collector/vnf_collectors/vio.py b/osm_mon/collector/vnf_collectors/vio.py index ada6be6..77129e1 100644 --- a/osm_mon/collector/vnf_collectors/vio.py +++ b/osm_mon/collector/vnf_collectors/vio.py @@ -48,6 +48,12 @@ class VIOCollector(BaseVimCollector): vnfd = self.common_db.get_vnfd(vnfr['vnfd-id']) vdu_mappings = {} + # Populate extra tags for metrics + nsr_id = vnfr['nsr-id-ref'] + tags = {} + tags['ns_name'] = self.common_db.get_nsr(nsr_id)['name'] + tags['project_id'] = vnfr['_admin']['projects_read'][0] + # Fetch the list of all known resources from vROPS. resource_list = self.vrops.get_vm_resource_list_from_vrops() @@ -76,6 +82,8 @@ class VIOCollector(BaseVimCollector): if len(vdu_mappings) != 0: return self.vrops.get_metrics(vdu_mappings=vdu_mappings, monitoring_params=vdu['monitoring-param'], - vnfr=vnfr) + vnfr=vnfr, + tags=tags + ) else: return [] diff --git a/osm_mon/collector/vnf_collectors/vmware.py b/osm_mon/collector/vnf_collectors/vmware.py index 0070b56..0e76bfd 100644 --- a/osm_mon/collector/vnf_collectors/vmware.py +++ b/osm_mon/collector/vnf_collectors/vmware.py @@ -184,6 +184,12 @@ class VMwareCollector(BaseVimCollector): vnfd = self.common_db.get_vnfd(vnfr['vnfd-id']) vdu_mappings = {} + # Populate extra tags for metrics + nsr_id = vnfr['nsr-id-ref'] + tags = {} + tags['ns_name'] = self.common_db.get_nsr(nsr_id)['name'] + tags['project_id'] = vnfr['_admin']['projects_read'][0] + # Fetch the list of all known resources from vROPS. resource_list = self.vrops.get_vm_resource_list_from_vrops() @@ -218,6 +224,8 @@ class VMwareCollector(BaseVimCollector): if len(vdu_mappings) != 0: return self.vrops.get_metrics(vdu_mappings=vdu_mappings, monitoring_params=vdu['monitoring-param'], - vnfr=vnfr) + vnfr=vnfr, + tags=tags + ) else: return [] diff --git a/osm_mon/collector/vnf_collectors/vrops/vrops_helper.py b/osm_mon/collector/vnf_collectors/vrops/vrops_helper.py index 430cf86..75819fc 100644 --- a/osm_mon/collector/vnf_collectors/vrops/vrops_helper.py +++ b/osm_mon/collector/vnf_collectors/vrops/vrops_helper.py @@ -82,7 +82,8 @@ class vROPS_Helper(): def get_metrics(self, vdu_mappings={}, monitoring_params={}, - vnfr=None): + vnfr=None, + tags={}): monitoring_keys = {} # Collect the names of all the metrics we need to query @@ -155,7 +156,9 @@ class vROPS_Helper(): vnfr['member-vnf-index-ref'], vdu_name, metric_name, - metric_value) + metric_value, + tags + ) metrics.append(metric) diff --git a/osm_mon/collector/vnf_metric.py b/osm_mon/collector/vnf_metric.py index 92d3905..49e7842 100644 --- a/osm_mon/collector/vnf_metric.py +++ b/osm_mon/collector/vnf_metric.py @@ -20,6 +20,9 @@ # contact: bdiaz@whitestack.com or glavado@whitestack.com ## from osm_mon.collector.metric import Metric +import logging + +log = logging.getLogger(__name__) class VnfMetric(Metric): @@ -31,4 +34,5 @@ class VnfMetric(Metric): } if extra_tags: tags.update(extra_tags) + log.debug('Tags: %s', tags) super().__init__(tags, name, value)