I know I can get the real-time stats using top but have no idea what to do with them
O modo em lote pode ser útil:
-b : Batch mode operation
Starts top in ’Batch mode’, which could be useful for sending output from top to other programs or
to a file. In this mode, top will not accept input and runs until the iterations limit you’ve set
with the ’-n’ command-line option or until killed.
Por exemplo:
$ top -b -n 1 -u <user> | awk 'NR > 7 { sum += $9 } END { print sum }'
Ganglia Gmetric pode ser usado para traçar um gráfico para isso.
cpu_per_user_gmetric.sh
#!/bin/bash
USERS="a b c"
for user in $USERS; do
/usr/bin/gmetric --name CPU_per_"$user"_user --value 'top -b -n 1 -u $user | awk 'NR>7 { sum += $9; } END { print sum; }'' --type uint8 --unit Percent
done
crontab -l
* * * * * /path/to/cpu_per_user_gmetric.sh
e aqui está o resultado: