Adds partial support for interface metrics in OpenStack plugin 92/7392/2
authorBenjamin Diaz <bdiaz@whitestack.com>
Thu, 4 Apr 2019 19:33:01 +0000 (16:33 -0300)
committerBenjamin Diaz <bdiaz@whitestack.com>
Wed, 10 Apr 2019 19:38:56 +0000 (16:38 -0300)
Adds support for 'packets_in_dropped', 'packets_out_dropped', 'packets_received', 'packets_sent'
All of this metrics correspond to a sum of the metric for each interface in the vdu

Change-Id: I93b4fb760b927f98417ae2e65a27c0c2b3fb5b6f
Signed-off-by: Benjamin Diaz <bdiaz@whitestack.com>
osm_mon/collector/vnf_collectors/openstack.py
osm_mon/collector/vnf_metric.py

index 33d6299..da98cc6 100644 (file)
@@ -42,16 +42,19 @@ log = logging.getLogger(__name__)
 
 METRIC_MAPPINGS = {
     "average_memory_utilization": "memory.usage",
-    "disk_read_ops": "disk.read.requests",
-    "disk_write_ops": "disk.write.requests",
-    "disk_read_bytes": "disk.read.bytes",
-    "disk_write_bytes": "disk.write.bytes",
-    "packets_dropped": "interface.if_dropped",
-    "packets_received": "interface.if_packets",
-    "packets_sent": "interface.if_packets",
+    "disk_read_ops": "disk.read.requests.rate",
+    "disk_write_ops": "disk.write.requests.rate",
+    "disk_read_bytes": "disk.read.bytes.rate",
+    "disk_write_bytes": "disk.write.bytes.rate",
+    "packets_in_dropped": "network.outgoing.packets.drop",
+    "packets_out_dropped": "network.incoming.packets.drop",
+    "packets_received": "network.incoming.packets.rate",
+    "packets_sent": "network.outgoing.packets.rate",
     "cpu_utilization": "cpu_util",
 }
 
+INTERFACE_METRICS = ['packets_in_dropped', 'packets_out_dropped', 'packets_received', 'packets_sent']
+
 
 class OpenstackCollector(BaseVimCollector):
     def __init__(self, config: Config, vim_account_id: str):
@@ -133,17 +136,39 @@ class OpenstackCollector(BaseVimCollector):
                     elif self.backend == 'gnocchi':
                         delta = 10 * self.granularity
                         start_date = datetime.datetime.now() - datetime.timedelta(seconds=delta)
-                        try:
-                            measures = self.client.metric.get_measures(openstack_metric_name,
-                                                                       start=start_date,
-                                                                       resource_id=resource_id,
-                                                                       granularity=self.granularity)
-                            if len(measures):
-                                metric = VnfMetric(nsr_id, vnf_member_index, vdur['name'], metric_name, measures[-1][2])
-                                metrics.append(metric)
-                        except gnocchiclient.exceptions.NotFound as e:
-                            log.debug("No metric found: %s", e)
-                            pass
+                        if metric_name in INTERFACE_METRICS:
+                            total_measure = 0.0
+                            interfaces = self.client.resource.search(resource_type='instance_network_interface',
+                                                                     query={'=': {'instance_id': resource_id}})
+                            for interface in interfaces:
+                                try:
+                                    measures = self.client.metric.get_measures(openstack_metric_name,
+                                                                               start=start_date,
+                                                                               resource_id=interface['id'],
+                                                                               granularity=self.granularity)
+                                    if len(measures):
+                                        total_measure += measures[-1][2]
+
+                                except gnocchiclient.exceptions.NotFound as e:
+                                    log.debug("No metric %s found for interface %s: %s", openstack_metric_name,
+                                              interface['id'], e)
+                            metric = VnfMetric(nsr_id, vnf_member_index, vdur['name'], metric_name,
+                                               total_measure)
+                            metrics.append(metric)
+                        else:
+                            try:
+                                measures = self.client.metric.get_measures(openstack_metric_name,
+                                                                           start=start_date,
+                                                                           resource_id=resource_id,
+                                                                           granularity=self.granularity)
+                                if len(measures):
+                                    metric = VnfMetric(nsr_id, vnf_member_index, vdur['name'], metric_name,
+                                                       measures[-1][2])
+                                    metrics.append(metric)
+                            except gnocchiclient.exceptions.NotFound as e:
+                                log.debug("No metric %s found for instance %s: %s", openstack_metric_name, resource_id,
+                                          e)
+
                     else:
                         raise Exception('Unknown metric backend: %s', self.backend)
         return metrics
index d0f39c3..92d3905 100644 (file)
@@ -23,10 +23,12 @@ from osm_mon.collector.metric import Metric
 
 
 class VnfMetric(Metric):
-    def __init__(self, nsr_id, vnf_member_index, vdur_name, name, value):
+    def __init__(self, nsr_id, vnf_member_index, vdur_name, name, value, extra_tags: dict = None):
         tags = {
             'ns_id': nsr_id,
             'vnf_member_index': vnf_member_index,
             'vdu_name': vdur_name
         }
+        if extra_tags:
+            tags.update(extra_tags)
         super().__init__(tags, name, value)