This geeklet is pretty useful. It’s effectively like running
top on your desktop (but without the overhead) to see what processes are currently taking up the most cycles on your CPU. It works best in combination with a 1 minute CPU load monitor. I set this geeklet to update every 5 seconds. Within 5 seconds, things can change a lot, but any process that is taking up a significant portion of the current load will generally stay at the top and offer a clear idea of what might be slowing things down. It generally keeps running when other things start hanging, so it’s much more convenient than using Activity Monitor or
top at the command line.
The script parses the
ps command (process status, information about all of your processes). It uses the arguments
ps -arcwwwxo "command %cpu" to display all processes (including other users’ and processes without terminals) by their executable name, sort by CPU and limit the columns in the output to just the command name and CPU percentage. That handles the bulk of the work right there. The rest of my script simply pulls out the top processes, limiting the number to 10 and cutting it short if there are more than five processes listed at 0%.
It color codes the output based on percentage, giving you red, yellow and blue lines if processes are above 10%, 20%, and 30%, respectively. It also justifies the output, truncating the process name if necessary and adding the percentage in parenthesis with a stretched space to right justify them. In order for the justification to work, you need to use a monospaced font such as Menlo or Droid Sans Mono (Inconsolata looks pretty good, too).
The script accepts one command line argument:
-t "title". If you leave that off, it will automatically put “Top CPU processes” and a newline at the top of the output. If you add
-t without an argument after it, it will remove the title entirely. If you use
-t "Custom title" it will replace the default with your custom title (and automatic newline). Any other customization (colors, removing justification) will require manually editing the script. You’re on your own for that.
Here’s the script in its entirety. Just copy and paste it into a file called
cpumeter.rb, place it in a script folder and make it executable (
chmod a+x cpumeter.rb). Add the path to it as a shell geeklet and you’re good to go. In NerdTool, you may need to specify that the output is colorized.
Updated to work with non-US systems
Next up, the same type of system monitor, but for physical memory size.