cleanup monitoring commands
authorstevenvanrossem <steven.vanrossem@intec.ugent.be>
Thu, 12 May 2016 14:36:10 +0000 (16:36 +0200)
committerstevenvanrossem <steven.vanrossem@intec.ugent.be>
Thu, 12 May 2016 14:36:10 +0000 (16:36 +0200)
src/emuvim/api/zerorpc/network.py
src/emuvim/cli/monitor.py
src/emuvim/dcemulator/monitoring.py
src/emuvim/dcemulator/net.py

index 5fccf4e..d55e775 100755 (executable)
@@ -135,10 +135,10 @@ class DCNetworkApi(object):
             return ex.message
 
     # remove the flow metrics measurement
-    def setup_flow(self, vnf_name, vnf_interface, metric, cookie):
+    def stop_flow(self, vnf_name, vnf_interface, metric, cookie):
         logging.debug("RPC CALL: stop flow")
         try:
-            c = self.net.monitor_agent.setup_flow(vnf_name, vnf_interface, metric, cookie)
+            c = self.net.monitor_agent.stop_flow(vnf_name, vnf_interface, metric, cookie)
             return c
         except Exception as ex:
             logging.exception("RPC error.")
index 1f2cc36..34853a6 100755 (executable)
@@ -93,7 +93,7 @@ parser = argparse.ArgumentParser(description='son-emu monitor')
 parser.add_argument(\r
     "command",\r
     choices=['setup_metric', 'stop_metric', 'setup_flow', 'stop_flow','prometheus'],\r
-    help="setup/stop a metric/flow to be monitored")\r
+    help="setup/stop a metric/flow to be monitored or Prometheus query")\r
 parser.add_argument(\r
     "--vnf_name", "-vnf", dest="vnf_name",\r
     help="vnf name:interface to be monitored")\r
index 762c947..e663cae 100755 (executable)
@@ -139,6 +139,28 @@ class DCNetworkMonitor():
             logging.exception("setup_metric error.")\r
             return ex.message\r
 \r
+    def stop_flow(self, vnf_name, vnf_interface=None, metric=None, cookie=0):\r
+        for flow_dict in self.flow_metrics:\r
+            if flow_dict['vnf_name'] == vnf_name and flow_dict['vnf_interface'] == vnf_interface \\r
+                    and flow_dict['metric_key'] == metric and flow_dict['cookie'] == cookie:\r
+\r
+                self.monitor_flow_lock.acquire()\r
+\r
+                self.flow_metrics.remove(flow_dict)\r
+\r
+                for collector in self.registry._collectors:\r
+                    if (vnf_name, vnf_interface, cookie) in collector._metrics:\r
+                        #logging.info('2 name:{0} labels:{1} metrics:{2}'.format(collector._name, collector._labelnames,\r
+                        #                                                        collector._metrics))\r
+                        collector.remove(vnf_name, vnf_interface, cookie)\r
+\r
+                delete_from_gateway(self.pushgateway, job='sonemu-SDNcontroller')\r
+\r
+                self.monitor_flow_lock.release()\r
+\r
+                logging.info('Stopped monitoring flow {3}: {2} on {0}:{1}'.format(vnf_name, vnf_interface, metric, cookie))\r
+                return 'Stopped monitoring flow {3}: {2} on {0}:{1}'.format(vnf_name, vnf_interface, metric, cookie)\r
+\r
 \r
     # first set some parameters, before measurement can start\r
     def setup_metric(self, vnf_name, vnf_interface=None, metric='tx_packets'):\r
@@ -297,7 +319,7 @@ class DCNetworkMonitor():
                 ret = self.net.ryu_REST('stats/flow', dpid=flow_dict['switch_dpid'], data=data)\r
                 flow_stat_dict = ast.literal_eval(ret)\r
 \r
-                logging.info('received flow stat:{0} '.format(flow_stat_dict))\r
+                #logging.info('received flow stat:{0} '.format(flow_stat_dict))\r
                 self.set_flow_metric(flow_dict, flow_stat_dict)\r
 \r
             self.monitor_flow_lock.release()\r
index c29c786..39c4a96 100755 (executable)
@@ -406,9 +406,8 @@ class DCNetwork(Containernet):
         elif cmd == 'del-flows':
             prefix = 'stats/flowentry/delete'
 
-            # if cookie is given, only delete flows by cookie
-            # do not specify other match -> also other cookies can be matched
             if cookie:
+                # TODO: add cookie_mask as argument
                 flow['cookie_mask'] = int('0xffffffffffffffff', 16)  # need full mask to match complete cookie
 
             action = {}