|
This graph represents the output of the
uptime
command which is run at 10 minute intervals and logged
to a file. The output is then run through a simple
gnuplot
script to generate the image. See below for more info.
Notes:
- 12/21 00:00: bug in awk data parsing
- 12/22 00:00: bug in awk data parsing
- 12/22 22:00: awstats or httpd (?)
- 12/23 00:00: bug in perl data parsing
How this page was created
First, a cron job was created to take the last field from the output of
the uptime command - the one that shows the average system load
for the past fifteen minutes, and appends it, along with a timestamp to
a log file. This
cron
job also gives instructions to
gnuplot
to generate
an image from the data in the log file.
The crontab entry looks like this:
# log system uptime every 10 minutes
*/10 * * * * /usr/local/bin/loguptime
Note that the name of the script is arbitrary; loguptime just made sense...
The script that is run looks like this:
#!/bin/sh
PATH=/bin:/usr/bin
LOGFILE="$WWWSITE/uptime.log"
#IMGFILE="$WWWSITE/img/uptime.png"
IMGFILE="$WWWSITE/img/uptime.gif"
# get load avg for last 15min, append to log w/timestamp
uptime | perl -ne '
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = sprintf("%02d", $year % 100);
$mon = sprintf("%02d", $mon + 1);
$mday = sprintf("%02d", $mday);
$hour = sprintf("%02d", $hour);
$min = sprintf("%02d", $min);
chomp;
@line=split;
$curload = $line[-3] + 0.0;
system("ps aux|mail -s current_load_is_$curload dave") if $curload > 2;
print "$year$mon$mday$hour$min\t$line[-1]\n";
' >> $LOGFILE
# plot log to image
#
cat <<EOM | gnuplot
set title "Child-Abuse.COM: System Load"
set xlabel "Date/Time"
set ylabel "Load"
set grid
set format x "%m/%d\n%k:%M"
set xdata time
set timefmt "%y%m%d%H%M"
#set terminal png
set terminal gif medium size 800, 600
set output "$IMGFILE"
plot "$LOGFILE" using 1:2 t "System Load" w lines
EOM
exit $?
############################################################
# eof: loguptime
|
That's it!
enjoy,
...dave
|