├── README └── sarplot /README: -------------------------------------------------------------------------------- 1 | sarplot - a script to turn the extremly useful data produced from sar/sysstat into ASCII graphs using gnuplot 2 | 3 | Example plot of 1 minute load averages: 4 | 5 | $ ./sarplot -m load 6 | 7 | 1 Minute Load Average 8 | 9 | 0.08 ++--+----+---+---+---+----+--*+---+---+----+---*---+---+----+---+--++ 10 | + + + + * + 1 Minute Load Average+****** + 11 | 0.07 ++ * * ++ 12 | | * * | 13 | 0.06 ++ * * ++ 14 | | * * | 15 | | * * | 16 | 0.05 ++ * * * ++ 17 | | * * * | 18 | 0.04 ++ * * ** * ++ 19 | | ** * * * * | 20 | 0.03 ++ * ** * * * * * ++ 21 | | * ** * * * * * | 22 | 0.02 ++ * ** * ** * * * * ** ++ 23 | | * ** * ** * * * * * * | 24 | | ** ** * **** * * * * * | 25 | 0.01 ++ ** * *** ***** ** * * * * ++ 26 | + + **+ * + *** ***** ** + * * + * * + + 27 | 0 ***************-***************-***************+******-******---+--++ 28 | 00:00 02:00 04:00 06:00 08:00 10:00 12:00 14:00 16:00 29 | Time 30 | 31 | Example with date and metric specified: 32 | 33 | $ sarplot -m load -d 25 34 | 1 Minute Load Average 35 | 36 | 3 ++-+--+--+--+--+--+-+--+--+--+--+--+--+--+--+--+--+--+-+--+--+--+--+-++ 37 | + + + + + + + 1 Minute Load Average ****** + 38 | | * | 39 | 2.5 ++ * ++ 40 | | * | 41 | | * | 42 | 2 ++ * * ++ 43 | | * * | 44 | | * * * * | 45 | 1.5 ++ * ** * * *** ++ 46 | | * ** * * *** | 47 | | * * * *** **** ** * | 48 | 1 ++ * * ** * **** ***** ** ** **+ 49 | | * * **** ** ** * * ***** ** ******* *** **| 50 | | * ************************* ** ****** ******* 51 | 0.5 *+ * * **************** *** ** * ** * * ** 52 | |*** *** ** * *********** ****** ** * * *| 53 | +*****+******** *** **+*****+ *+* * + + + + + 54 | 0 ++-*-**********************--+--+--+--+--+--+--+--+--+-+--+--+--+--+-++ 55 | 25/11 25/11 25/11 25/1125/11 25/11 25/11 25/11 25/11 25/1125/11 25/11 26/11 56 | 00:00 02:00 04:00 06:0008:00 10:00 12:00 14:00 16:00 18:0020:00 22:00 00:00 57 | -------------------------------------------------------------------------------- /sarplot: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## sarplot.sh 4 | ## Hereward Cooper - 14/10/2009- 5 | ## James Hannah - 14/10/2009- 6 | ## A hack to plot various system resource information from sar using gnuplot 7 | 8 | # Begin new option parsing code... 9 | usage="Usage: $0 [-m METRIC] [-d DAY]" 10 | metric="" 11 | sadate="" 12 | while getopts ":wm:d:" options; do 13 | case $options in 14 | m ) metric=$OPTARG;; 15 | d ) sadate=$OPTARG 16 | if [ -d /var/log/sa ]; then 17 | saprefix="/var/log/sa/sa" 18 | else 19 | if [ -d /var/log/sysstat ]; then 20 | saprefix="/var/log/sysstat/sa" 21 | fi 22 | fi;; 23 | w ) FROMFIRST=true;; 24 | : ) echo "Missing parameter to option: -$OPTARG" 25 | echo $usage 26 | exit 1;; 27 | \? ) echo $usage 28 | exit 1;; 29 | * ) echo $usage 30 | exit 1;; 31 | esac 32 | done 33 | if [ "xxx${metric}yyy" == "xxxyyy" ]; then 34 | metric="cpu" 35 | fi 36 | 37 | ## Start off doing some checks for required programs 38 | if [ ! -f /usr/bin/gnuplot ] 39 | then 40 | echo "CRITICAL: gnuplot missing!" 41 | exit 1; 42 | fi 43 | 44 | if [ ! -f /usr/bin/sadf ] 45 | then 46 | echo "CRITICAL: sar missing!" 47 | exit 1; 48 | fi 49 | 50 | 51 | ##################################################### 52 | ## Next Define some of the graphs you want to plot ## 53 | ## metric = the flag to pass sar ## 54 | ## field = the coloumn in the output to plot ## 55 | ## title = human readable version of the field ## 56 | ##################################################### 57 | 58 | # Swap Usage 59 | if [[ $metric == "swap" ]] 60 | then 61 | sar -r | grep swpused || echo "No Swap Detected"; exit 1 62 | metric="-r" 63 | field="kbbuffers" 64 | title="% Swap Usage" 65 | 66 | # 1 Minute Load Average 67 | elif [[ $metric == "load" ]] 68 | then 69 | metric="-q" 70 | field="ldavg-1" 71 | title="1 Minute Load Average" 72 | 73 | # Disk Read IO 74 | elif [[ $metric == "io" ]] 75 | then 76 | metric="-b" 77 | field="rtps" 78 | title="Read Requests per Second" 79 | 80 | # Disk Write IO 81 | elif [[ $metric == "iow" ]] 82 | then 83 | metric="-b" 84 | field="wtps" 85 | title="Write Requests per Second" 86 | 87 | # Network Inbound 88 | elif [[ $metric == "netin" ]] 89 | then 90 | metric="-n DEV " 91 | field="eth0.*rxbyt" 92 | title="kB/s Recieved on eth0" 93 | 94 | elif [[ $metric == "ctx" ]] 95 | then 96 | metric="-w" 97 | field="cswch" 98 | title="Context switches/second" 99 | 100 | elif [[ $metric == "iowait" ]] 101 | then 102 | metric="-u" 103 | field="iowait" 104 | title="Context switches/second" 105 | 106 | 107 | # Failback to CPU %idle if nothing defined 108 | elif [[ $metric == "cpu" || $# -eq 0 ]] 109 | then 110 | metric="-u" 111 | field="%idle" 112 | title="CPU %Idle" 113 | else 114 | echo "Invalid metric specified!" 115 | exit 1 116 | fi 117 | 118 | ##################################### 119 | ## This is where the magic happens ## 120 | ##################################### 121 | 122 | TMPFILE=`mktemp /tmp/sarplot.XXXXXXXXXX` 123 | 124 | if [ "xxx$FROMSTARTyyy" != "xxxyyy" ]; then 125 | weekstart=$(($sadate-7)) 126 | for d in `seq $weekstart $(($sadate-1))`; do 127 | /usr/bin/sadf $saprefix$d -- $metric | awk "/$field/ {print \$3,\$6}" >> $TMPFILE 128 | done 129 | fi 130 | /usr/bin/sadf $saprefix$sadate -- $metric | awk "/$field/ {print \$3,\$6}" >> $TMPFILE 131 | echo "set terminal dumb; 132 | set title '$title'; 133 | set xdata time; 134 | set timefmt '%s'; 135 | set xlabel 'Time'; 136 | plot '$TMPFILE' using 1:2 with lines title '$title';" | gnuplot 137 | rm -f $TMPFILE 138 | --------------------------------------------------------------------------------