1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
|
#!/bin/bash
# find where to put the vertical lines
awk -f vrules.awk $1 > vrules
. ./vrules
i=0
VRULES=""
while [ $i -lt $NUM_VRULES ]
do
VRULES="$VRULES VRULE:${VRULE_TIME[$i]}#${VRULE_COLR[$i]}:${VRULE_TEXT[$i]}"
i=`expr $i + 1`
done
# echo $VRULES
if [ -f kitsink ]
then
rm kitsink
fi
prefix=${1%.log}
echo "Prefix is $prefix"
for i in ${prefix}*.out
do
# find some boundaries for this .out file
awk -F "," -f mins_maxes.awk $i > minsn
. ./minsn
#echo "MAX_INTERVAL $MAX_INTERVAL MIN_TIMESTAMP $MIN_TIMESTAMP MAX_TIMESTAMP $MAX_TIMESTAMP"
LENGTH=`expr $MAX_TIMESTAMP - $MIN_TIMESTAMP`
SIZE="-w $LENGTH -h 400"
# ooh, rick learns how to strip a suffix
basename=${i%\.out}
# echo "Post-processing ${basename}"
rrdtool create ${basename}.rrd --step 1 --start $MIN_TIMESTAMP \
DS:mbps:GAUGE:$MAX_INTERVAL:U:U RRA:AVERAGE:0.5:1:$LENGTH
# keep in mind that rrd only likes timestamps to milliseconds
# at some point it would be nice to do more than one data point
# at a time
awk -v rrdfile=${basename}.rrd -F "," '(NF == 4){printf("rrdtool update %s %.3f:%f\n",rrdfile,$4,$1)}' \
$i | sh
# this and the way things are handled for overall.rrd is massively
# kludgey and I would love to know a better way to do this
rrdtool fetch ${basename}.rrd AVERAGE \
--start $MIN_TIMESTAMP --end $MAX_TIMESTAMP | \
awk -F ":" '{printf("%d %f\n",$1,$2)}' | grep -v -e "nan" -e "^0" >> kitsink
done
echo Performing overall summary computations
# find some overall boundaries. at some point we should build this up
# based on what we were doing one file at a time above
awk -F "," -f mins_maxes.awk ${prefix}*.out > minsn
. ./minsn
# echo "MAX_INTERVAL $MAX_INTERVAL MIN_TIMESTAMP $MIN_TIMESTAMP MAX_TIMESTAMP $MAX_TIMESTAMP"
LENGTH=`expr $MAX_TIMESTAMP - $MIN_TIMESTAMP`
WIDTH=$LENGTH
if [ $WIDTH -lt 800 ]
then
WIDTH=800
fi
SIZE="-w $WIDTH -h 400"
# ok time for the overall results
# by now all the large intervals have been dealt with so we do not
# have to use MAX_INTERVAL
rrdtool create ${prefix}_overall.rrd --step 1 --start `expr $MIN_TIMESTAMP - 1` \
DS:mbps:GAUGE:1:U:U RRA:AVERAGE:0.5:1:$LENGTH
for i in `seq $MIN_TIMESTAMP $MAX_TIMESTAMP`
do
SUM=`grep $i kitsink | awk '{sum += $2}END{print sum}'`
rrdtool update ${prefix}_overall.rrd ${i}:$SUM
done
# get out labels set correctly
UNITS="bits/s"
MULTIPLIER="1000000"
DIRECTION="Bidirectional"
case $prefix in
*pps* | *tps* )
UNITS="Trans/s"
MULTIPLIER="1"
;;
*inbound* )
DIRECTION="Inbound"
;;
*outbound* )
DIRECTION="Outbound"
;;
esac
# find the interval with the highest AVERAGE. we can use the
# timestamps in the vrules file to check this. while we are doing so,
# might as well find the average, minimum and maximum for each
# interval and we will chart the interval averages with some
# reasonable transparancy. if someone wants to chart the interval
# mins and maxes hopefully it will be fairly clear what to do
rrdtool create ${prefix}_intervals.rrd --step 1 \
--start `expr $MIN_TIMESTAMP - 1` \
DS:avg:GAUGE:1:U:U RRA:AVERAGE:0.5:1:$LENGTH \
DS:min:GAUGE:1:U:U RRA:AVERAGE:0.5:1:$LENGTH \
DS:max:GAUGE:1:U:U RRA:AVERAGE:0.5:1:$LENGTH
i=0
AVG=0
end=`expr $NUM_VRULES - 1`
while [ $i -lt $end ]
do
start=`expr ${VRULE_TIME[$i]} + 1`
j=`expr $i + 1`
endtime=`expr ${VRULE_TIME[$j]} - 1`
avgminmax=`rrdtool graph /dev/null --start $start --end $endtime \
DEF:foo=${prefix}_overall.rrd:mbps:AVERAGE \
VDEF:avg=foo,AVERAGE \
VDEF:min=foo,MINIMUM \
VDEF:max=foo,MAXIMUM \
PRINT:avg:"%6.2lf" \
PRINT:min:"%6.2lf" \
PRINT:max:"%6.2lf" | sed 1d `
# there is probably some clever way to do this without spawning
# processes but I guess I'm just a fan of stone knives and
# bearskins
avg=`echo $avgminmax | awk '{print int($1)}'`
min=`echo $avgminmax | awk '{print int($2)}'`
max=`echo $avgminmax | awk '{print int($3)}'`
# echo "Updating intervals from $start to $endtime with $avg $min $max"
for k in `seq $start $endtime`
do
rrdtool update ${prefix}_intervals.rrd $k:$avg:$min:$max
done
if [ $avg -gt $AVG ]
then
peakintvid=`expr $i / 2`
peakintvid=`expr $peakintvid + 1`
maxstart=$start
maxend=$endtime
AVG=$avg
MIN=$min
MAX=$max
fi
i=`expr $i + 2`
done
# multiply it by the MULTIPLIER
AVG=`expr $AVG \* $MULTIPLIER`
MIN=`expr $MIN \* $MULTIPLIER`
MAX=`expr $MAX \* $MULTIPLIER`
# now graph it. if you want the min and max on the graph then add
# HRULE:${MIN}#0F0F0F:"Minimum of peak interval is $MIN" \
# HRULE:${MAX}#0000FF:"Maximum of peak interval is $MAX" \
# HRULE:${AVG}#0000FF80:"Average of peak interval (${peakintvid}) is $AVG" \
# to the rrdtool command though it can make the chart rather busy
rrdtool graph ${prefix}_overall.png \
--start $MIN_TIMESTAMP --end $MAX_TIMESTAMP \
$SIZE \
--imgformat PNG \
--font DEFAULT:0:Helvetica \
-t "Overall ${1%.log}" \
-v "$DIRECTION $UNITS" \
DEF:foo=${prefix}_overall.rrd:mbps:AVERAGE \
CDEF:bits=foo,$MULTIPLIER,\* \
$VRULES \
LINE2:bits#00FF0080:"$UNITS" > /dev/null \
DEF:bar=${prefix}_intervals.rrd:avg:AVERAGE \
CDEF:intvl=bar,$MULTIPLIER,\* \
LINE2:intvl#0F0F0F40:"Interval average. Peak of $AVG during interval ${peakintvid}."
# now we can do the individual run graphs using the same x axis limits
# as the overall graph
for i in ${prefix}*.out
do
basename=${i%\.out}
rrdtool graph ${basename}.png --start $MIN_TIMESTAMP --end $MAX_TIMESTAMP \
$SIZE \
--imgformat PNG \
--font DEFAULT:0:Helvetica \
-t "$basename ${1%.log}" \
-v "$DIRECTION $UNITS" \
DEF:foo=${basename}.rrd:mbps:AVERAGE \
CDEF:bits=foo,$MULTIPLIER,\* \
$VRULES \
LINE2:bits#00FF0080:"$UNITS" > /dev/null
done
echo "Average of peak interval is $AVG $UNITS from $maxstart to $maxend"
echo "Minimum of peak interval is $MIN $UNITS from $maxstart to $maxend"
echo "Maximum of peak interval is $MAX $UNITS from $maxstart to $maxend"
|