From 1ef77027e420874e945cc7d49b0856e742da8444 Mon Sep 17 00:00:00 2001 From: stevenvanrossem Date: Thu, 12 May 2016 16:36:10 +0200 Subject: [PATCH] cleanup monitoring commands --- src/emuvim/api/zerorpc/network.py | 4 ++-- src/emuvim/cli/monitor.py | 2 +- src/emuvim/dcemulator/monitoring.py | 24 +++++++++++++++++++++++- src/emuvim/dcemulator/net.py | 3 +-- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/emuvim/api/zerorpc/network.py b/src/emuvim/api/zerorpc/network.py index 5fccf4e..d55e775 100755 --- a/src/emuvim/api/zerorpc/network.py +++ b/src/emuvim/api/zerorpc/network.py @@ -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.") diff --git a/src/emuvim/cli/monitor.py b/src/emuvim/cli/monitor.py index 1f2cc36..34853a6 100755 --- a/src/emuvim/cli/monitor.py +++ b/src/emuvim/cli/monitor.py @@ -93,7 +93,7 @@ parser = argparse.ArgumentParser(description='son-emu monitor') parser.add_argument( "command", choices=['setup_metric', 'stop_metric', 'setup_flow', 'stop_flow','prometheus'], - help="setup/stop a metric/flow to be monitored") + help="setup/stop a metric/flow to be monitored or Prometheus query") parser.add_argument( "--vnf_name", "-vnf", dest="vnf_name", help="vnf name:interface to be monitored") diff --git a/src/emuvim/dcemulator/monitoring.py b/src/emuvim/dcemulator/monitoring.py index 762c947..e663cae 100755 --- a/src/emuvim/dcemulator/monitoring.py +++ b/src/emuvim/dcemulator/monitoring.py @@ -139,6 +139,28 @@ class DCNetworkMonitor(): logging.exception("setup_metric error.") return ex.message + def stop_flow(self, vnf_name, vnf_interface=None, metric=None, cookie=0): + for flow_dict in self.flow_metrics: + if flow_dict['vnf_name'] == vnf_name and flow_dict['vnf_interface'] == vnf_interface \ + and flow_dict['metric_key'] == metric and flow_dict['cookie'] == cookie: + + self.monitor_flow_lock.acquire() + + self.flow_metrics.remove(flow_dict) + + for collector in self.registry._collectors: + if (vnf_name, vnf_interface, cookie) in collector._metrics: + #logging.info('2 name:{0} labels:{1} metrics:{2}'.format(collector._name, collector._labelnames, + # collector._metrics)) + collector.remove(vnf_name, vnf_interface, cookie) + + delete_from_gateway(self.pushgateway, job='sonemu-SDNcontroller') + + self.monitor_flow_lock.release() + + logging.info('Stopped monitoring flow {3}: {2} on {0}:{1}'.format(vnf_name, vnf_interface, metric, cookie)) + return 'Stopped monitoring flow {3}: {2} on {0}:{1}'.format(vnf_name, vnf_interface, metric, cookie) + # first set some parameters, before measurement can start def setup_metric(self, vnf_name, vnf_interface=None, metric='tx_packets'): @@ -297,7 +319,7 @@ class DCNetworkMonitor(): ret = self.net.ryu_REST('stats/flow', dpid=flow_dict['switch_dpid'], data=data) flow_stat_dict = ast.literal_eval(ret) - logging.info('received flow stat:{0} '.format(flow_stat_dict)) + #logging.info('received flow stat:{0} '.format(flow_stat_dict)) self.set_flow_metric(flow_dict, flow_stat_dict) self.monitor_flow_lock.release() diff --git a/src/emuvim/dcemulator/net.py b/src/emuvim/dcemulator/net.py index c29c786..39c4a96 100755 --- a/src/emuvim/dcemulator/net.py +++ b/src/emuvim/dcemulator/net.py @@ -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 = {} -- 2.25.1