From: stevenvanrossem Date: Fri, 15 Apr 2016 13:18:44 +0000 (+0200) Subject: start cadvisor and prometheus at startup X-Git-Tag: v3.1~148^2~1 X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2Fvim-emu.git;a=commitdiff_plain;h=bbdb5ee7e82d1280be34501dd12a382d2892473a start cadvisor and prometheus at startup --- diff --git a/src/emuvim/api/zerorpc/network.py b/src/emuvim/api/zerorpc/network.py index f21ce99..d4ca794 100644 --- a/src/emuvim/api/zerorpc/network.py +++ b/src/emuvim/api/zerorpc/network.py @@ -101,7 +101,7 @@ class DCNetworkApi(object): return ex.message # remove the rate measurement for a vnf interface - def remove_metric(self, vnf_name, vnf_interface, metric): + def stop_metric(self, vnf_name, vnf_interface, metric): logging.debug("RPC CALL: setup metric") try: c = self.net.monitor_agent.remove_metric(vnf_name, vnf_interface, metric) diff --git a/src/emuvim/cli/monitor.py b/src/emuvim/cli/monitor.py index bae0c07..040fa13 100755 --- a/src/emuvim/cli/monitor.py +++ b/src/emuvim/cli/monitor.py @@ -37,7 +37,7 @@ class ZeroRpcClient(object): args.get("metric")) pp.pprint(r) - def remove_metric(self, args): + def stop_metric(self, args): vnf_name = self._parse_vnf_name(args.get("vnf_name")) vnf_interface = self._parse_vnf_interface(args.get("vnf_name")) r = self.c.remove_metric( @@ -61,10 +61,10 @@ class ZeroRpcClient(object): parser = argparse.ArgumentParser(description='son-emu network') parser.add_argument( "command", - help="Action to be executed: get_rate") + help="Action to be executed") parser.add_argument( "--vnf_name", "-vnf", dest="vnf_name", - help="vnf name to be monitored") + help="vnf name:interface to be monitored") parser.add_argument( "--metric", "-m", dest="metric", help="tx_bytes, rx_bytes, tx_packets, rx_packets") diff --git a/src/emuvim/dcemulator/monitoring.py b/src/emuvim/dcemulator/monitoring.py index 7fa5e18..82411fd 100755 --- a/src/emuvim/dcemulator/monitoring.py +++ b/src/emuvim/dcemulator/monitoring.py @@ -5,7 +5,7 @@ import logging from mininet.node import OVSSwitch import ast import time -from prometheus_client import start_http_server, Summary, Histogram, Gauge, Counter +from prometheus_client import start_http_server, Summary, Histogram, Gauge, Counter, REGISTRY import threading from subprocess import Popen, PIPE import os @@ -121,21 +121,28 @@ class DCNetworkMonitor(): network_metric['switch_dpid'] = int(str(next_node.dpid), 16) network_metric['metric_key'] = metric - self.network_metrics.append(network_metric) logging.info('Started monitoring: {2} on {0}:{1}'.format(vnf_name, vnf_interface, metric)) return 'Started monitoring: {2} on {0}:{1}'.format(vnf_name, vnf_interface, metric) except Exception as ex: - logging.exception("get_rate error.") + logging.exception("setup_metric error.") return ex.message - def remove_metric(self, vnf_name, vnf_interface, metric): + def stop_metric(self, vnf_name, vnf_interface, metric): for metric_dict in self.network_metrics: if metric_dict['vnf_name'] == vnf_name and metric_dict['vnf_interface'] == vnf_interface \ - and metric_dict['metric'] == metric: + and metric_dict['metric_key'] == metric: + self.network_metrics.remove(metric_dict) + + #this removes the complete metric, all labels... + #REGISTRY.unregister(self.prom_metrics[metric_dict['metric_key']]) + + # set values to NaN, prometheus api currently does not support removal of metrics + self.prom_metrics[metric_dict['metric_key']].labels(vnf_name, vnf_interface).set(float('nan')) + logging.info('Stopped monitoring: {2} on {0}:{1}'.format(vnf_name, vnf_interface, metric)) return 'Stopped monitoring: {2} on {0}:{1}'.format(vnf_name, vnf_interface, metric) @@ -179,7 +186,7 @@ class DCNetworkMonitor(): #logging.info('set prom packets:{0} {1}:{2}'.format(this_measurement, vnf_name, vnf_interface)) # set prometheus metric - self.prom_metrics[metric_key].labels(vnf_name, vnf_interface).set(this_measurement) + self.prom_metrics[metric_dict['metric_key']].labels(vnf_name, vnf_interface).set(this_measurement) if previous_monitor_time <= 0 or previous_monitor_time >= port_uptime: metric_dict['previous_measurement'] = int(port_stat[metric_key]) diff --git a/src/emuvim/dcemulator/net.py b/src/emuvim/dcemulator/net.py index c3c3c03..ede593a 100755 --- a/src/emuvim/dcemulator/net.py +++ b/src/emuvim/dcemulator/net.py @@ -175,12 +175,16 @@ class DCNetwork(Dockernet): Dockernet.start(self) def stop(self): - # stop Ryu controller - Dockernet.stop(self) - self.stopRyu() # stop the monitor agent self.monitor_agent.stop() + # stop emulator net + Dockernet.stop(self) + + # stop Ryu controller + self.stopRyu() + + def CLI(self): CLI(self)