Merge "Change PTL informatin in INFO"
[bottlenecks.git] / utils / dashboard / rubbos_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
14 def exec_shell(cmd):
15     out, err = subp.Popen(cmd, stdout=subp.PIPE, shell=True).communicate()
16     return out.strip()
17
18
19 def get_onetime_data(dir_name):
20     cmd = ("grep -in 'remote client nodes' %s/index.html|awk "
21            "'{print $5}'|awk -F '<' '{print $1}'" % dir_name)
22     client_node_num = int(exec_shell(cmd))
23     cmd = ("grep -n 'Number of clients' %s/index.html|awk "
24            "'{print $5}'|awk -F '<' '{print $1}'" % dir_name)
25     each_client_num = int(exec_shell(cmd))
26     total_client = (client_node_num + 1) * each_client_num
27
28     cmd = ('grep -n "throughput" %s/stat_client*.html |awk -F "<B>"'
29            ' \'{if (FNR%%2==0 && FNR%%4!=0) {printf "%%s\\n", $3}}\'|awk \''
30            'BEGIN{sum=0;}{sum=sum+$1;}END{print sum}\'' % dir_name)
31     throughput = int(exec_shell(cmd))
32
33     cmd = ('grep -n "Total" %s/stat_client*.html |awk -F "<B>"'
34            ' \'{if (FNR==4) {printf "%%s\\n", $4}}\'|awk -F "</B>"'
35            ' \'BEGIN{sum=0;}{sum=sum+$1;}END{print sum}\'' % dir_name)
36     request = int(exec_shell(cmd))
37
38     cmd = ('grep -n "Total" %s/stat_client*.html |awk -F "<B>"'
39            ' \'{if (FNR==4) {printf "%%s\\n", $5}}\'|awk -F "</B>"'
40            ' \'BEGIN{sum=0;}{sum=sum+$1;}END{print sum}\'' % dir_name)
41     error_request = int(exec_shell(cmd))
42
43     return total_client, throughput, request, error_request
44
45
46 class RubbosCollector(object):
47
48     def __init__(self):
49         pass
50
51     def collect_data(self, data_home):
52         cmd = 'ls -l %s |grep ^d|awk \'{print $9}\'' % data_home
53         result = []
54         for subdir in exec_shell(cmd).split('\n'):
55             total_client, throughput, request, error_request = \
56                 get_onetime_data(data_home + '/' + subdir)
57             result.append({'client': total_client,
58                            'throughput': throughput,
59                            'request': request,
60                            'error_request': error_request})
61         result.sort(key=lambda x: x['client'])
62
63         return result