From: Benjamin Diaz Date: Thu, 4 Apr 2019 19:33:01 +0000 (-0300) Subject: Adds partial support for interface metrics in OpenStack plugin X-Git-Tag: v6.0.0~15 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=197909586553113bb7e28124f96d4a239f5a94b2;p=osm%2FMON.git Adds partial support for interface metrics in OpenStack plugin 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 --- diff --git a/osm_mon/collector/vnf_collectors/openstack.py b/osm_mon/collector/vnf_collectors/openstack.py index 33d6299..da98cc6 100644 --- a/osm_mon/collector/vnf_collectors/openstack.py +++ b/osm_mon/collector/vnf_collectors/openstack.py @@ -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 diff --git a/osm_mon/collector/vnf_metric.py b/osm_mon/collector/vnf_metric.py index d0f39c3..92d3905 100644 --- a/osm_mon/collector/vnf_metric.py +++ b/osm_mon/collector/vnf_metric.py @@ -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)