Mercurial > hg > cc > azure
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/master/src/wecu/graph_hardware_usage.py Thu May 28 09:56:42 2020 +0000 @@ -0,0 +1,46 @@ +#!/usr/bin/python +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt + +HOSTS_PATH = 'hosts' + +def get_hosts(): + hosts = set() + with open(HOSTS_PATH, 'r') as hosts_f: + for line in hosts_f: + if line.strip() != '': + hosts.add(line) + return hosts + +def get_data_for_host(host): + data = [] + with open(host + '.usage.txt') as f: + for line in f: + val = float(line.strip()) + data.append(float(val)) + return data + +def generate_hardware_graph(output_filepath): + # MAIN + hosts = get_hosts() + + # Common + plt.rcParams.update({'font.size': 20}) + fig, axes = plt.subplots(len(hosts), 1, figsize=(12.1, len(hosts) * 6.2), sharex=False) + + i = 0 + for host in hosts: + vals = axes[i].get_yticks() + axes[i].set_yticklabels(['{:,.0%}'.format(x) for x in vals]) + axes[i].set_ylabel("Utilisation") + + axes[i].plot(get_data_for_host(host.strip())) + axes[i].set_ylim([0, 105]) + + i += 1 + + axes[0].set_title("CPU usage") + axes[len(hosts) - 1].set_xlabel("Time [seconds]") + + plt.savefig(output_filepath, dpi=300, pad_inches = 0.1, bbox_inches = 'tight',) \ No newline at end of file