- def profile(self, mgmt_ip, rate, input_ip, vnf_uuid ):\r
-\r
- ssh = paramiko.SSHClient()\r
- ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())\r
- #ssh.connect(mgmt_ip, username='steven', password='test')\r
- ssh.connect(mgmt_ip, username='root', password='root')\r
-\r
- iperf_cmd = 'iperf -c {0} -u -l18 -b{1}M -t1000 &'.format(input_ip, rate)\r
- if rate > 0:\r
- stdin, stdout, stderr = ssh.exec_command(iperf_cmd)\r
-\r
- start_time = time.time()\r
- query_cpu = '(sum(rate(container_cpu_usage_seconds_total{{id="/docker/{0}"}}[{1}s])))'.format(vnf_uuid, 1)\r
- while (time.time() - start_time) < 15:\r
- data = self.query_Prometheus(query_cpu)\r
- # logging.info('rate: {1} data:{0}'.format(data, rate))\r
- gevent.sleep(0)\r
- time.sleep(1)\r
-\r
- query_cpu2 = '(sum(rate(container_cpu_usage_seconds_total{{id="/docker/{0}"}}[{1}s])))'.format(vnf_uuid, 8)\r
- cpu_load = float(self.query_Prometheus(query_cpu2)[1])\r
- output = 'rate: {1}Mbps; cpu_load: {0}%'.format(round(cpu_load * 100, 2), rate)\r
- output_line = output\r
- logging.info(output_line)\r
-\r
- stop_iperf = 'pkill -9 iperf'\r
- stdin, stdout, stderr = ssh.exec_command(stop_iperf)\r
-\r
- return output_line\r
-\r