Woffles Uptime Widget
Contents |
Introduction
The load average is a good indicator of current system stress, having it available for quick reference is essential. This tutorial will make a load average indicator that when clicked on will bring up the task manager of your choice.
Programs you will need:
- pcregrep -- grep using the PCRE syntax.
- uptime -- should be available everywhere.
Create the widget
textbox load_average {
text_align = "right"
align = "right"
# Task manager
mouse {
modkey = {}
button = "1"
command = "spawn"
arg = "xterm -e top"
}
}
To use a different tool than top' just change the value of arg.
Create the scripts
The first script you need contains the widget name, the text format to use and the speed which the widget should update in seconds:
~/.awesome/uptime-values.sh
handle() {
# $1 -- Uptime
# $2 -- Users
# $3 -- Load
echo " Load: $1 - $2 - $3 "
}
widget="load_average"
speed=5
Next we need a script to periodically update the widget:
~/.awesome/uptime-monitor.sh
while true do if [ -S ~/.awesome_ctl.0 ]; then while true do . ~/.awesome/uptime-values.sh uptime=`uptime`; up=`echo $uptime | pcregrep -o 'up\s+[0-9]+:[0-9]+' | pcregrep -o '[0-9]+:[0-9]+'` users=`echo $uptime | pcregrep -o '[0-9]+\s+users' | pcregrep -o '[0-9]+'` load=`echo $uptime | pcregrep -o '[0-9\.]+,\s+[0-9\.]+,\s+[0-9\.]+$'` echo "0 widget_tell $widget " "`handle \"$up\" \"$users\" \"$load\"`" | awesome-client sleep $speed done else sleep 1 fi done
Now, you might be wondering why that needed two scripts; I wrote it this way so that you can change the way the script works without needing to restart ~/.awesome/uptime-monitor.sh.
To make sure the scripts can be executed run:
chmod +x ~/.awesome/uptime-*
Final steps
The last thing you need to do is find a way to automatically run ~/.awesome/uptime-monitor.sh every time you start an X session.
The usual way is to edit your ~/.xinitrc file to include the script, this might look something line:
~/.awesome/uptime-monitor.sh & exec awesome
However, you'll probably need to figure something else out if you're using a display manager like xdm, gdm or kdm.
Finally, tell awesome to reload your configuration, the usual way is to press Control-Mod4-R.
That just about covers everything, if you have any question I'm woffle on IRC.