#!/bin/sh # # system-graph.sh # # Developed by Lubomir Host # Copyright (c) 2003 Platon SDG, http://platon.sk/ # Licensed under terms of GNU General Public License. # All rights reserved. # # Run this script 1 minute after midnight (cron) # # $Platon: scripts/syswatcher/create-graph.sh,v 1.2 2003/11/12 12:11:25 rajo Exp $ DB_USER="syswatcher" DATABASE="system" output_dir="$HOME/public_html/graph" umask 022 generate_loadavg() { # {{{ DATE=$1 output_loadavg="loadavg_$DATE" xlabel="Date: [`echo $DATE | sed 's|-|/|g;'`]" # LIMIT 90000 is for reason, if more than 1 row per second was inserted into table # (1 day was 86400 seconds); if [ ! -f "${output_loadavg}.dat" ]; then echo "SELECT date_format(time, '%Y/%m/%d/%T'), load1, load5, load15, procs_run, procs_total, last_pid, time FROM loadavg WHERE time > '$DATE' AND time < '$DATE' + INTERVAL 1 DAY ORDER BY time LIMIT 90000;" \ | mysql -B -u $DB_USER $DATABASE > "${output_loadavg}.dat"; fi cat < /dev/null 2>&1 set terminal png set grid set time set xdata time set timefmt "%Y/%m/%d/%H:%M:%S" set format x " %H:%M" set xlabel "$xlabel" set xtics rotate set output "$output_dir/loadavg_load01-$DATE.png" plot [] [0:2.0] "${output_loadavg}.dat" using 1:2 title "load per 1 min" with lines 1 set output "$output_dir/loadavg_load05-$DATE.png" plot [] [0:2.0] "${output_loadavg}.dat" using 1:3 title "load per 5 min" with lines 2 set output "$output_dir/loadavg_load15-$DATE.png" plot [] [0:2.0] "${output_loadavg}.dat" using 1:4 title "load per 15 min" with lines 3 set output "$output_dir/loadavg_procs-$DATE.png" plot [] [0:200] "${output_loadavg}.dat" using 1:(20 * \$5) title "running processes (20 x zoom)" with lines 4, \ "" using 1:6 title "processes total" with lines 5 EOF # generate html document cat < "$output_dir/statistics-$DATE.html" Statistics of server `uname -n`:

Statistics of server `uname -n`:




EOF } # }}} if [ $# -lt 1 ]; then echo "Usage: $0 2003-11-10 [2003-11-11 [2003-11-12]]" exit 1; fi for date in $*; do generate_loadavg $date; done # vim600: fdm=marker fdc=3 fdl=0