self.pushgateway = 'localhost:9091'\r
# when sdk is started with docker-compose, we could use\r
# self.pushgateway = 'pushgateway:9091'\r
- # Start up the server to expose the metrics to Prometheus\r
- #start_http_server(8000)\r
\r
# supported Prometheus metrics\r
self.registry = CollectorRegistry()\r
self.monitor_flow_thread.start()\r
\r
# helper tools\r
- # Prometheus pushgateway and DB are started as external contianer, outside of son-emu\r
- #self.pushgateway_process = self.start_PushGateway()\r
- #self.prometheus_process = self.start_Prometheus()\r
- self.cadvisor_process = self.start_cadvisor()\r
+ # cAdvisor, Prometheus pushgateway and DB are started as external container, outside of son-emu\r
+\r
\r
# first set some parameters, before measurement can start\r
def setup_flow(self, vnf_name, vnf_interface=None, metric='tx_packets', cookie=0):\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
+ def stop_flow(self, vnf_name, vnf_interface=None, metric=None, cookie=0,):\r
+\r
+ # check if port is specified (vnf:port)\r
+ if vnf_interface is None and metric is not None:\r
+ # take first interface by default\r
+ connected_sw = self.net.DCNetwork_graph.neighbors(vnf_name)[0]\r
+ link_dict = self.net.DCNetwork_graph[vnf_name][connected_sw]\r
+ vnf_interface = link_dict[0]['src_port_id']\r
+\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
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
+ return 'Error stopping monitoring flow: {0} on {1}:{2}'.format(metric, vnf_name, vnf_interface)\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
\r
def stop_metric(self, vnf_name, vnf_interface=None, metric=None):\r
\r
+ # check if port is specified (vnf:port)\r
+ if vnf_interface is None and metric is not None:\r
+ # take first interface by default\r
+ connected_sw = self.net.DCNetwork_graph.neighbors(vnf_name)[0]\r
+ link_dict = self.net.DCNetwork_graph[vnf_name][connected_sw]\r
+ vnf_interface = link_dict[0]['src_port_id']\r
+\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_key'] == metric:\r
logging.info('Stopped monitoring vnf: {0}'.format(vnf_name))\r
return 'Stopped monitoring: {0}'.format(vnf_name)\r
\r
+ return 'Error stopping monitoring metric: {0} on {1}:{2}'.format(metric, vnf_name, vnf_interface)\r
+\r
+\r
+\r
\r
- # get all metrics defined in the list and export it to Prometheus\r
+\r
+# get all metrics defined in the list and export it to Prometheus\r
def get_flow_metrics(self):\r
while self.start_monitoring:\r
\r
cookie = metric_dict['cookie']\r
\r
# TODO aggregate all found flow stats\r
- flow_stat = flow_stat_dict[str(switch_dpid)][0]\r
- if 'bytes' in metric_key:\r
- counter = flow_stat['byte_count']\r
- elif 'packet' in metric_key:\r
- counter = flow_stat['packet_count']\r
+ #flow_stat = flow_stat_dict[str(switch_dpid)][0]\r
+ #if 'bytes' in metric_key:\r
+ # counter = flow_stat['byte_count']\r
+ #elif 'packet' in metric_key:\r
+ # counter = flow_stat['packet_count']\r
+\r
+ counter = 0\r
+ for flow_stat in flow_stat_dict[str(switch_dpid)]:\r
+ if 'bytes' in metric_key:\r
+ counter += flow_stat['byte_count']\r
+ elif 'packet' in metric_key:\r
+ counter += flow_stat['packet_count']\r
\r
+ flow_stat = flow_stat_dict[str(switch_dpid)][0]\r
flow_uptime = flow_stat['duration_sec'] + flow_stat['duration_nsec'] * 10 ** (-9)\r
\r
self.prom_metrics[metric_dict['metric_key']]. \\r
self.monitor_thread.join()\r
self.monitor_flow_thread.join()\r
\r
+ # these containers are used for monitoring but are started now outside of son-emu\r
'''\r
if self.prometheus_process is not None:\r
logging.info('stopping prometheus container')\r
self.pushgateway_process.terminate()\r
self.pushgateway_process.kill()\r
self._stop_container('pushgateway')\r
- '''\r
\r
if self.cadvisor_process is not None:\r
logging.info('stopping cadvisor container')\r
self.cadvisor_process.terminate()\r
self.cadvisor_process.kill()\r
self._stop_container('cadvisor')\r
+ '''\r
\r
def switch_tx_rx(self,metric=''):\r
# when monitoring vnfs, the tx of the datacenter switch is actually the rx of the vnf\r