comparison master/src/wecu/graph_hardware_usage.py @ 58:a3edba8dab11

move to right place in tree
author Henry S. Thompson <ht@markup.co.uk>
date Thu, 28 May 2020 09:56:42 +0000
parents master/wecu/graph_hardware_usage.py@ac1a20e627a9
children
comparison
equal deleted inserted replaced
57:ac1a20e627a9 58:a3edba8dab11
1 #!/usr/bin/python
2 import matplotlib
3 matplotlib.use('Agg')
4 import matplotlib.pyplot as plt
5
6 HOSTS_PATH = 'hosts'
7
8 def get_hosts():
9 hosts = set()
10 with open(HOSTS_PATH, 'r') as hosts_f:
11 for line in hosts_f:
12 if line.strip() != '':
13 hosts.add(line)
14 return hosts
15
16 def get_data_for_host(host):
17 data = []
18 with open(host + '.usage.txt') as f:
19 for line in f:
20 val = float(line.strip())
21 data.append(float(val))
22 return data
23
24 def generate_hardware_graph(output_filepath):
25 # MAIN
26 hosts = get_hosts()
27
28 # Common
29 plt.rcParams.update({'font.size': 20})
30 fig, axes = plt.subplots(len(hosts), 1, figsize=(12.1, len(hosts) * 6.2), sharex=False)
31
32 i = 0
33 for host in hosts:
34 vals = axes[i].get_yticks()
35 axes[i].set_yticklabels(['{:,.0%}'.format(x) for x in vals])
36 axes[i].set_ylabel("Utilisation")
37
38 axes[i].plot(get_data_for_host(host.strip()))
39 axes[i].set_ylim([0, 105])
40
41 i += 1
42
43 axes[0].set_title("CPU usage")
44 axes[len(hosts) - 1].set_xlabel("Time [seconds]")
45
46 plt.savefig(output_filepath, dpi=300, pad_inches = 0.1, bbox_inches = 'tight',)