I'd like to thank those who helped me to accomplish this feat. After a
lot of head pounding and squinting at some of the proc files funny, I
get it working and accomplished a lot of the goals that I had. The idea
was to have a very unobtrusive way to get instant cpu usage and possibly
memory info. I wound up using three separate shell scripts and offloaded
most of the work to the master node which is dedicated to this kind of
stuff.

mystat.sh (each node accesses this script)

#! /bin/bash

stats=(`head -n 1 /proc/stat`)
((prev=${stats[1]} + ${stats[2]}))
sleep 3
stats=(`head -n 1 /proc/stat`)
((now=${stats[1]} + ${stats[2]}))
((total=($now-$prev)))
tmp=(`cat /proc/meminfo | grep MemTotal`)
memstat[0]=${tmp[1]}
tmp=(`cat /proc/meminfo | grep MemFree`)
((memstat[1]=${memstat[0]}-${tmp[1]}))
tmp=(`cat /proc/meminfo | grep SwapTotal`)
memstat[2]=${tmp[1]}
tmp=(`cat /proc/meminfo | grep SwapFree`)
((memstat[3]=${memstat[2]}-${tmp[1]}))

echo $total ${memstat[0]} ${memstat[1]} ${memstat[2]} ${memstat[3]}


mystat_c.sh (since the nodes don't have bc the master node does the
"high level" math)
#! /bin/bash

        ticks=$(rsh $1 /usr/local/bin/mystat.sh)
        stats=(`echo $ticks`)
        percent=$(echo "scale=1; ${stats[0]}/6" | bc)
        mem=$(echo "scale=1; ${stats[2]}*100/${stats[1]}" | bc)
        swap=$(echo "scale=1; ${stats[4]}*100/${stats[3]}" | bc)
        echo "$1 ${percent} ${mem} ${swap}"

mystat_s.sh (runs mystat_s.sh for each node and redirects output)
#! /bin/bash

mv stats.out.new stats.out
for i in `seq -f "%02g" 01 65`;
do
        /var/www/mystat_c.sh beast$i >> stats.out.new &
done

I have this running as a cron job every minute and then the web page
looks for the stats.out file and parses it. If anyone else wants to
calculate the cpu utilization from the proc file, take the difference of
the jiffies and divide by the number of procs times the time difference
(if you use the summary line). That took me a long time to figure out
(it's always the easy things!), but it matches pretty close to what top
reads and doesn't have such a performance hit for a single 3 sec read.

The final product: http://babeast.byu.edu/screenshot.jpg

--------------------
BYU Unix Users Group 
http://uug.byu.edu/ 

The opinions expressed in this message are the responsibility of their
author.  They are not endorsed by BYU, the BYU CS Department or BYU-UUG. 
___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list

Reply via email to