from subprocess import Popen\r
import os\r
import docker\r
+import json\r
\r
logging.basicConfig(level=logging.INFO)\r
\r
self.monitor_flow_lock = threading.Lock()\r
self.network_metrics = []\r
self.flow_metrics = []\r
+ self.skewmon_metrics = {}\r
\r
# start monitoring thread\r
self.start_monitoring = True\r
container = self.dockercli.containers.get(name)\r
container.remove(force=True)\r
\r
+ def update_skewmon(self, vnf_name, resource_name, action):\r
+\r
+ ret = ''\r
+\r
+ config_file_path = '/tmp/skewmon.cfg'\r
+ configfile = open(config_file_path, 'a+')\r
+ try:\r
+ config = json.load(configfile)\r
+ except:\r
+ #not a valid json file or empty\r
+ config = {}\r
+\r
+ #initialize config file\r
+ if len(self.skewmon_metrics) == 0:\r
+ config = {}\r
+ json.dump(config, configfile)\r
+ configfile.close()\r
+\r
+ docker_name = 'mn.' + vnf_name\r
+ vnf_container = self.dockercli.containers.get(docker_name)\r
+ key = resource_name + '_' + vnf_container.short_id\r
+ vnf_id = vnf_container.id\r
+\r
+ if action == 'start':\r
+ # add a new vnf to monitor\r
+ config[key] = dict(VNF_NAME=vnf_name,\r
+ VNF_ID=vnf_id,\r
+ VNF_METRIC=resource_name)\r
+ ret = 'adding to skewness monitor: {0} {1} '.format(vnf_name, resource_name)\r
+ logging.info(ret)\r
+ elif action == 'stop':\r
+ # remove vnf to monitor\r
+ config.pop(key)\r
+ ret = 'removing from skewness monitor: {0} {1} '.format(vnf_name, resource_name)\r
+ logging.info(ret)\r
+\r
+ self.skewmon_metrics = config\r
+ configfile = open(config_file_path, 'w')\r
+ json.dump(config, configfile)\r
+ configfile.close()\r
+\r
+ try:\r
+ skewmon_container = self.dockercli.containers.get('skewmon')\r
+\r
+ # remove container if config is empty\r
+ if len(config) == 0:\r
+ ret += 'stopping skewness monitor'\r
+ logging.info('stopping skewness monitor')\r
+ skewmon_container.remove(force=True)\r
+\r
+ except docker.errors.NotFound:\r
+ # start container if not running\r
+ ret += 'starting skewness monitor'\r
+ logging.info('starting skewness monitor')\r
+ volumes = {'/sys/fs/cgroup':{'bind':'/sys/fs/cgroup', 'mode':'ro'},\r
+ '/tmp/skewmon.cfg':{'bind':'/config.txt', 'mode':'ro'}}\r
+ self.dockercli.containers.run('skewmon',\r
+ detach=True,\r
+ volumes=volumes,\r
+ labels=['com.containernet'],\r
+ name='skewmon'\r
+ )\r
+ return ret\r
+\r
+\r
+\r
+\r
\r