Merge "bugfix for Dockerfile"
[bottlenecks.git] / utils / dashboard / collector.py
1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd. and others
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10
11 import subprocess as subp
12
13 def exec_shell(cmd):
14     out,err = subp.Popen(cmd, stdout=subp.PIPE, shell=True).communicate()
15     return out.strip()
16
17
18 def get_onetime_data(dir_name):
19     cmd = "grep -in 'remote client nodes' %s/index.html|awk '{print $5}'|awk -F '<' '{print $1}'" % dir_name
20     client_node_num = int(exec_shell(cmd))
21     cmd = "grep -n 'Number of clients' %s/index.html|awk '{print $5}'|awk -F '<' '{print $1}'" % dir_name
22     each_client_num = int(exec_shell(cmd))
23     total_client = (client_node_num+1) * each_client_num
24     cmd = 'grep -n "throughput" %s/stat_client*.html |awk -F "<B>" \'FNR%%4==0 {printf "%%s\\n", $3 }\'|awk \'BEGIN{sum=0;}{sum=sum+$1;}END{print sum}\'' % dir_name
25     throughput = int(exec_shell(cmd))
26
27     return total_client, throughput
28
29
30 class Collector(object):
31
32
33     def __init__(self):
34         pass
35
36
37     def collect_data(self, data_home):
38         cmd =  'ls -l %s |grep ^d|awk \'{print $9}\'' % data_home
39         result = []
40         for subdir in exec_shell(cmd).split('\n'):
41             total_client, throughput = get_onetime_data(data_home+'/'+subdir)
42             result.append({'client':total_client, 'throughput':throughput})
43             result.sort(key=lambda x:x['client'])
44
45         return result;
46