From 5d61e264565b4ae5f3114122d4007720216751e4 Mon Sep 17 00:00:00 2001 From: stevenvanrossem Date: Sun, 7 May 2017 22:40:44 +0200 Subject: [PATCH] fix monitoring bug (cleanup monitored metrics list after vnf removal) --- src/emuvim/dcemulator/monitoring.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/emuvim/dcemulator/monitoring.py b/src/emuvim/dcemulator/monitoring.py index 78b8007..6418e37 100755 --- a/src/emuvim/dcemulator/monitoring.py +++ b/src/emuvim/dcemulator/monitoring.py @@ -38,6 +38,7 @@ from subprocess import Popen, check_call import os import docker import json +from copy import deepcopy logging.basicConfig(level=logging.INFO) @@ -272,7 +273,7 @@ class DCNetworkMonitor(): link_dict = self.net.DCNetwork_graph[vnf_name][connected_sw] vnf_interface = link_dict[0]['src_port_id'] - for metric_dict in self.network_metrics: + for metric_dict in deepcopy(self.network_metrics): if metric_dict['vnf_name'] == vnf_name and metric_dict['vnf_interface'] == vnf_interface \ and metric_dict['metric_key'] == metric: @@ -302,20 +303,17 @@ class DCNetworkMonitor(): elif metric_dict['vnf_name'] == vnf_name and vnf_interface is None and metric is None: self.monitor_lock.acquire() self.network_metrics.remove(metric_dict) - for collector in self.registry._collectors: - collector_dict = collector._metrics.copy() - for name, interface, id in collector_dict: - if name == vnf_name: - logging.info('3 name:{0} labels:{1} metrics:{2}'.format(collector._name, collector._labelnames, - collector._metrics)) - collector.remove(name, interface, 'None') + logging.info('remove metric from monitor: vnf_name:{0} vnf_interface:{1} mon_port:{2}'.format(metric_dict['vnf_name'], metric_dict['vnf_interface'], metric_dict['mon_port'])) delete_from_gateway(self.pushgateway, job='sonemu-SDNcontroller') self.monitor_lock.release() - logging.info('Stopped monitoring vnf: {0}'.format(vnf_name)) - return 'Stopped monitoring: {0}'.format(vnf_name) + continue - return 'Error stopping monitoring metric: {0} on {1}:{2}'.format(metric, vnf_name, vnf_interface) + if vnf_interface is None and metric is None: + logging.info('Stopped monitoring vnf: {0}'.format(vnf_name)) + return 'Stopped monitoring: {0}'.format(vnf_name) + else: + return 'Error stopping monitoring metric: {0} on {1}:{2}'.format(metric, vnf_name, vnf_interface) # get all metrics defined in the list and export it to Prometheus @@ -430,7 +428,7 @@ class DCNetworkMonitor(): else: time_delta = (port_uptime - metric_dict['previous_monitor_time']) - metric_rate = (this_measurement - metric_dict['previous_measurement']) / float(time_delta) + #metric_rate = (this_measurement - metric_dict['previous_measurement']) / float(time_delta) metric_dict['previous_measurement'] = this_measurement metric_dict['previous_monitor_time'] = port_uptime @@ -438,6 +436,7 @@ class DCNetworkMonitor(): logging.exception('metric {0} not found on {1}:{2}'.format(metric_key, vnf_name, vnf_interface)) logging.exception('monport:{0}, dpid:{1}'.format(mon_port, switch_dpid)) + logging.exception('monitored network_metrics:{0}'.format(self.network_metrics)) logging.exception('port dict:{0}'.format(port_stat_dict)) return 'metric {0} not found on {1}:{2}'.format(metric_key, vnf_name, vnf_interface) -- 2.25.1