start cadvisor and prometheus at startup
authorstevenvanrossem <steven.vanrossem@intec.ugent.be>
Fri, 15 Apr 2016 13:18:44 +0000 (15:18 +0200)
committerstevenvanrossem <steven.vanrossem@intec.ugent.be>
Fri, 15 Apr 2016 13:18:44 +0000 (15:18 +0200)
src/emuvim/api/zerorpc/network.py
src/emuvim/cli/monitor.py
src/emuvim/dcemulator/monitoring.py
src/emuvim/dcemulator/net.py

index f21ce99..d4ca794 100644 (file)
@@ -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)
index bae0c07..040fa13 100755 (executable)
@@ -37,7 +37,7 @@ class ZeroRpcClient(object):
             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
@@ -61,10 +61,10 @@ class ZeroRpcClient(object):
 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
index 7fa5e18..82411fd 100755 (executable)
@@ -5,7 +5,7 @@ import logging
 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
@@ -121,21 +121,28 @@ class DCNetworkMonitor():
             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
@@ -179,7 +186,7 @@ class DCNetworkMonitor():
                 #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
index c3c3c03..ede593a 100755 (executable)
@@ -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)