Skip to content

Instantly share code, notes, and snippets.

@diegopso
Created July 6, 2018 14:18
Show Gist options
  • Save diegopso/db351ad71d18d7db0afca61fd0012a61 to your computer and use it in GitHub Desktop.
Save diegopso/db351ad71d18d7db0afca61fd0012a61 to your computer and use it in GitHub Desktop.
Monitor Hardware Usage Ubuntu
#!/bin/bash
echo 'cpu,mem,args' >> ps.csv
while true; do
(ps -e -o pcpu,pmem,args --sort=-pmem,-pcpu --no-headers | sed 's/^[ \t]*//;s/[ \t]*$//' | sed -e 's/\s\+/,/' | sed -e 's/\s\+/,/' | sed -r -e 's/^([0-9\.]+),([0-9\.]+),([^ ]+)(.*)?/\1,\2,\3/g' | sed -r -e 's/^([0-9\.]+),([0-9\.]+),(.*\/)(.*)/\1,\2,\4/g') >> ps.csv;
sleep 10;
done
import pandas as pd
if __name__ == '__main__':
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
df = pd.read_csv('ps.csv')
# average relative impact
# df = df.groupby(by='args').mean() / df.groupby(by='args').max()
# total percentage impact
df = df.groupby(by='args').sum()
total = df.sum()
df = df / total
df = df[(df['mem'] > 0.01) | (df['cpu'] > 0.01)]
# df = df.sort_values(by='mem')
df.plot(kind='bar')
plt.tight_layout()
plt.savefig('ps.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment