Graphing per-user CPU usage on a Linux machine

I know I can get the real-time stats using top but have no idea what to do with them

Batch mode could be useful:

   -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.

For example:

$ top -b -n 1 -u <user> | awk 'NR > 7 { sum += $9 } END { print sum }'

Ganglia Gmetric can be used to plot a graph for this.

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

and here's the result:

enter image description here


The tload command represents the pictorial representation of the average system load through ASCII graph. This command can be used to provide the graph on a terminal. The syntax for the command is:

tload [options] [terminal]

If terminal is not provided as the argument to this command, then by default it outputs the graph on the current terminal. So the simplest forms of this command are:

$ tload
  • See more at: http://linoxide.com/monitoring-2/tload-command-displays-current-system-load-average-on-linux/#sthash.hYOvoF40.dpuf

Perhaps you could use collectd and adapt one of the available plugins? Yes, none of the listed will do exactly what you want, but on the other hand they are pretty simple to modify and I think you could start with for example processes plugin and start working from there.