#!/bin/bash # sargraph - a simple sketch on how to generate graphs from sadf XML output # by Lans.Carstensen@dreamworks.com # Our dependencies - bail out if they are not found set -e ZENITY=`which zenity` XSLTPROC=`which xsltproc` SADF=`which sadf` GNUPLOT=`which gnuplot` MKTEMP=`which mktemp` FIND=`which find` SORT=`which sort` CUT=`which cut` GZIP=`which gzip` set +e # Default for --sa-dir SA_DIR="/var/log/sysstat" SA_REGEX='/sa[0-9][0-9]+(\.(gz|bz2|xz|lz|lzo))?$' ######### OPTION PARSING ########### set -e parsed_opts=`getopt -o "" -l sa-dir: -- "$@"` eval set -- "$parsed_opts" DONE=no while [ $DONE != yes ] do case $1 in --sa-dir) shift SA_DIR="$1" ;; --) # End of options DONE=yes ;; *) echo Unexpected argument: $1 exit 1 ;; esac shift # should shift the last arg or '--' if DONE=yes done set +e #################################### # sar / sysstat DTD is published here: # http://pagesperso-orange.fr/sebastien.godard/sysstat.dtd # compare against output of "sadf -x" # and pull apart data into gnuplot tabular data files # Subroutines # Graph for "sar -u" cpu_xslt() { # Create the XSLT transform to make a GNUplot data file out of "sar -u" type data # test with "sadf -x | xsltproc - cat > $1 < EOF } cpu_gnuplot() { # Create the GNUplot rendering file, largely based on "isag" Tk script from sysstat package #set yrange [0:100] cat > $1 < - cat > $1 < EOF } rq_gnuplot() { cat > $1 < - cat > $1 < EOF } rqnoplistsz_gnuplot() { cat > $1 < - cat > $1 < EOF } io_gnuplot() { cat > $1 < - cat > $1 < EOF } nfsclient_gnuplot() { cat > $1 < - cat > $1 < EOF } paging_gnuplot() { cat > $1 < - cat > $1 < EOF } memuse_gnuplot() { cat > $1 < - cat > $1 < EOF } swapuse_gnuplot() { cat > $1 < $UNCOMPRESSED_SA_FILE SA_FILE=$UNCOMPRESSED_SA_FILE fi # Prompt for graph GRAPH=`$ZENITY --list --text "Select a graph" --column "Graph Type" "CPU" "Run Queue" "Run Queue w/o Process List Size" "IO Transfer Rate" "NFS Client" "Paging Stats" "Memory Utilization" "Memory Utilization (Swap)"` case "$GRAPH" in "CPU") XSLTFILE=`mktemp` cpu_xslt $XSLTFILE DATAFILE=`mktemp` $SADF -t -x $SA_FILE -- -u | $XSLTPROC --novalid $XSLTFILE - > $DATAFILE GNUPLOTFILE=`mktemp` cpu_gnuplot $GNUPLOTFILE $DATAFILE $GNUPLOT $GNUPLOTFILE ;; "Run Queue") XSLTFILE=`mktemp` rq_xslt $XSLTFILE DATAFILE=`mktemp` $SADF -t -x $SA_FILE -- -q | $XSLTPROC --novalid $XSLTFILE - > $DATAFILE GNUPLOTFILE=`mktemp` rq_gnuplot $GNUPLOTFILE $DATAFILE $GNUPLOT $GNUPLOTFILE ;; "Run Queue w/o Process List Size") XSLTFILE=`mktemp` rqnoplistsz_xslt $XSLTFILE DATAFILE=`mktemp` $SADF -t -x $SA_FILE -- -q | $XSLTPROC --novalid $XSLTFILE - > $DATAFILE GNUPLOTFILE=`mktemp` rqnoplistsz_gnuplot $GNUPLOTFILE $DATAFILE $GNUPLOT $GNUPLOTFILE ;; "IO Transfer Rate") XSLTFILE=`mktemp` io_xslt $XSLTFILE DATAFILE=`mktemp` $SADF -t -x $SA_FILE -- -b | $XSLTPROC --novalid $XSLTFILE - > $DATAFILE GNUPLOTFILE=`mktemp` io_gnuplot $GNUPLOTFILE $DATAFILE $GNUPLOT $GNUPLOTFILE ;; "NFS Client") XSLTFILE=`mktemp` nfsclient_xslt $XSLTFILE DATAFILE=`mktemp` $SADF -t -x $SA_FILE -- -n NFS | $XSLTPROC --novalid $XSLTFILE - > $DATAFILE GNUPLOTFILE=`mktemp` nfsclient_gnuplot $GNUPLOTFILE $DATAFILE $GNUPLOT $GNUPLOTFILE ;; "Paging Stats") XSLTFILE=`mktemp` paging_xslt $XSLTFILE DATAFILE=`mktemp` $SADF -t -x $SA_FILE -- -B | $XSLTPROC --novalid $XSLTFILE - > $DATAFILE GNUPLOTFILE=`mktemp` paging_gnuplot $GNUPLOTFILE $DATAFILE $GNUPLOT $GNUPLOTFILE ;; "Memory Utilization") XSLTFILE=`mktemp` memuse_xslt $XSLTFILE DATAFILE=`mktemp` $SADF -t -x $SA_FILE -- -r | $XSLTPROC --novalid $XSLTFILE - > $DATAFILE GNUPLOTFILE=`mktemp` memuse_gnuplot $GNUPLOTFILE $DATAFILE $GNUPLOT $GNUPLOTFILE ;; "Memory Utilization (Swap)") XSLTFILE=`mktemp` swapuse_xslt $XSLTFILE DATAFILE=`mktemp` $SADF -t -x $SA_FILE -- -S | $XSLTPROC --novalid $XSLTFILE - > $DATAFILE GNUPLOTFILE=`mktemp` swapuse_gnuplot $GNUPLOTFILE $DATAFILE $GNUPLOT $GNUPLOTFILE ;; *) # If you click "Cancel", you end up here DONE=yes ;; esac [ -f "$UNCOMPRESSED_SA_FILE" ] && rm $UNCOMPRESSED_SA_FILE [ -f "$GNUPLOTFILE" ] && rm $GNUPLOTFILE [ -f "$DATAFILE" ] && rm $DATAFILE [ -f "$XSLTFILE" ] && rm $XSLTFILE done exit # Local Variables: # sh-basic-offset: 4 # indent-tabs-mode: nil # sh-indent-for-case-label: 0 # sh-indent-for-case-alt: + # End: