Adding more labels to Prometheus metrics 41/8141/14
authorlavado <glavado@whitestack.com>
Mon, 11 Nov 2019 11:41:38 +0000 (06:41 -0500)
committerlavado <glavado@whitestack.com>
Mon, 11 Nov 2019 21:17:41 +0000 (16:17 -0500)
Change-Id: I412de4ee47808af09e4156b703a95d1edb5fbca7
Signed-off-by: lavado <glavado@whitestack.com>
osm_mon/collector/vnf_collectors/juju.py
osm_mon/collector/vnf_collectors/openstack.py
osm_mon/collector/vnf_collectors/vio.py
osm_mon/collector/vnf_collectors/vmware.py
osm_mon/collector/vnf_collectors/vrops/vrops_helper.py
osm_mon/collector/vnf_metric.py

index b8c8b4e..8be9e28 100644 (file)
@@ -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
 
index 16b9152..122fdd6 100644 (file)
@@ -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)
index ada6be6..77129e1 100644 (file)
@@ -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 []
index 0070b56..0e76bfd 100644 (file)
@@ -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 []
index 430cf86..75819fc 100644 (file)
@@ -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)
 
index 92d3905..49e7842 100644 (file)
@@ -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)