args.get("metric"))\r
pp.pprint(r)\r
\r
- def remove_metric(self, args):\r
+ def stop_metric(self, args):\r
vnf_name = self._parse_vnf_name(args.get("vnf_name"))\r
vnf_interface = self._parse_vnf_interface(args.get("vnf_name"))\r
r = self.c.remove_metric(\r
parser = argparse.ArgumentParser(description='son-emu network')\r
parser.add_argument(\r
"command",\r
- help="Action to be executed: get_rate")\r
+ help="Action to be executed")\r
parser.add_argument(\r
"--vnf_name", "-vnf", dest="vnf_name",\r
- help="vnf name to be monitored")\r
+ help="vnf name:interface to be monitored")\r
parser.add_argument(\r
"--metric", "-m", dest="metric",\r
help="tx_bytes, rx_bytes, tx_packets, rx_packets")\r
from mininet.node import OVSSwitch\r
import ast\r
import time\r
-from prometheus_client import start_http_server, Summary, Histogram, Gauge, Counter\r
+from prometheus_client import start_http_server, Summary, Histogram, Gauge, Counter, REGISTRY\r
import threading\r
from subprocess import Popen, PIPE\r
import os\r
network_metric['switch_dpid'] = int(str(next_node.dpid), 16)\r
network_metric['metric_key'] = metric\r
\r
-\r
self.network_metrics.append(network_metric)\r
\r
logging.info('Started monitoring: {2} on {0}:{1}'.format(vnf_name, vnf_interface, metric))\r
return 'Started monitoring: {2} on {0}:{1}'.format(vnf_name, vnf_interface, metric)\r
\r
except Exception as ex:\r
- logging.exception("get_rate error.")\r
+ logging.exception("setup_metric error.")\r
return ex.message\r
\r
- def remove_metric(self, vnf_name, vnf_interface, metric):\r
+ def stop_metric(self, vnf_name, vnf_interface, metric):\r
for metric_dict in self.network_metrics:\r
if metric_dict['vnf_name'] == vnf_name and metric_dict['vnf_interface'] == vnf_interface \\r
- and metric_dict['metric'] == metric:\r
+ and metric_dict['metric_key'] == metric:\r
+\r
self.network_metrics.remove(metric_dict)\r
+\r
+ #this removes the complete metric, all labels...\r
+ #REGISTRY.unregister(self.prom_metrics[metric_dict['metric_key']])\r
+\r
+ # set values to NaN, prometheus api currently does not support removal of metrics\r
+ self.prom_metrics[metric_dict['metric_key']].labels(vnf_name, vnf_interface).set(float('nan'))\r
+\r
logging.info('Stopped monitoring: {2} on {0}:{1}'.format(vnf_name, vnf_interface, metric))\r
return 'Stopped monitoring: {2} on {0}:{1}'.format(vnf_name, vnf_interface, metric)\r
\r
#logging.info('set prom packets:{0} {1}:{2}'.format(this_measurement, vnf_name, vnf_interface))\r
\r
# set prometheus metric\r
- self.prom_metrics[metric_key].labels(vnf_name, vnf_interface).set(this_measurement)\r
+ self.prom_metrics[metric_dict['metric_key']].labels(vnf_name, vnf_interface).set(this_measurement)\r
\r
if previous_monitor_time <= 0 or previous_monitor_time >= port_uptime:\r
metric_dict['previous_measurement'] = int(port_stat[metric_key])\r