X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_mon%2Fcollector%2Fvnf_collectors%2Fopenstack.py;h=a57eb4672fafe879a927e81c8243957fc5744cdd;hb=refs%2Fchanges%2F44%2F10944%2F1;hp=2738d5c49584a5c2ab2db6c64631f5fefac08a06;hpb=4b9f79e2820a011f6ebbba7fb92cdc120b364650;p=osm%2FMON.git diff --git a/osm_mon/collector/vnf_collectors/openstack.py b/osm_mon/collector/vnf_collectors/openstack.py index 2738d5c..a57eb46 100644 --- a/osm_mon/collector/vnf_collectors/openstack.py +++ b/osm_mon/collector/vnf_collectors/openstack.py @@ -55,6 +55,16 @@ METRIC_MAPPINGS = { "cpu_utilization": "cpu", } +# Metrics which have new names in Rocky and higher releases +METRIC_MAPPINGS_FOR_ROCKY_AND_NEWER_RELEASES = { + "disk_read_ops": "disk.device.read.requests", + "disk_write_ops": "disk.device.write.requests", + "disk_read_bytes": "disk.device.read.bytes", + "disk_write_bytes": "disk.device.write.bytes", + "packets_received": "network.incoming.packets", + "packets_sent": "network.outgoing.packets" + } + METRIC_MULTIPLIERS = { "cpu": 0.0000001 } @@ -127,7 +137,23 @@ class OpenstackCollector(BaseVimCollector): metric_type, metric_name, resource_id) - value = self.backend.collect_metric(metric_type, openstack_metric_name, resource_id) + value = self.backend.collect_metric( + metric_type, openstack_metric_name, resource_id + ) + + if value is None and metric_name in METRIC_MAPPINGS_FOR_ROCKY_AND_NEWER_RELEASES: + # Reattempting metric collection with new metric names. + # Some metric names have changed in newer Openstack releases + log.info( + "Reattempting metric collection for type: %s and name: %s and resource_id %s", + metric_type, + metric_name, + resource_id + ) + openstack_metric_name = METRIC_MAPPINGS_FOR_ROCKY_AND_NEWER_RELEASES[metric_name] + value = self.backend.collect_metric( + metric_type, openstack_metric_name, resource_id + ) if value is not None: log.info("value: %s", value) metric = VnfMetric(nsr_id, vnf_member_index, vdur['name'], metric_name, value, tags) @@ -201,7 +227,8 @@ class GnocchiBackend(OpenstackBackend): total_measure = 0.0 total_measure += measures[-1][2] - except gnocchiclient.exceptions.NotFound as e: + except (gnocchiclient.exceptions.NotFound, TypeError) as e: + # Gnocchi in some Openstack versions raise TypeError instead of NotFound log.debug("No metric %s found for interface %s: %s", openstack_metric_name, interface['id'], e) return total_measure @@ -218,12 +245,13 @@ class GnocchiBackend(OpenstackBackend): resource_id=resource_id) if measures: value = measures[-1][2] - except gnocchiclient.exceptions.NotFound as e: + except (gnocchiclient.exceptions.NotFound, gnocchiclient.exceptions.BadRequest, TypeError) as e: # CPU metric in previous Openstack versions do not support rate:mean aggregation method + # Gnocchi in some Openstack versions raise TypeError instead of NotFound or BadRequest if openstack_metric_name == "cpu": log.debug("No metric %s found for instance %s: %s", openstack_metric_name, resource_id, e) - log.debug("Retrying to get metric %s for instance %s without aggregation", - openstack_metric_name, resource_id) + log.info("Retrying to get metric %s for instance %s without aggregation", + openstack_metric_name, resource_id) measures = self.client.metric.get_measures(openstack_metric_name, resource_id=resource_id, limit=1)