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.")
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
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
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