#!/bin/bash
. ~/.cronenv
dir=`dirname "$0"`
if [ -z "$3" ]; then
echo "USAGE: stackgraphs <target-dir> <time-span> <title>"
exit 1
fi
tgt="$1"
span="$2"
title="$3"
width=700
height=320
total_color='#FF0000'
CommonsTicker_color='#00BB00'
updateCommonsTicker_color='#FF88DD'
CategoryTree_color='#FFFF00'
CatScan_color='#FF00FF'
CheckUsage_color='#0000BB'
Gallery_color='#BB00FF'
WikiProxy_color='#00FF00'
MediaSearch_color='#00BBFF'
i=0
for f in "$dir"/*.rrd; do
name=`basename ${f%%.rrd}`
eval color=\$${name}_color
if [ -z "$color" ]; then color='#000000'; fi
if [ "$name" == "total" ]; then continue; fi
if [ "$i" == "0" ]; then mode="AREA"; else mode="STACK"; fi
#echo "$name: $color"
rungraphs[$i]="DEF:$name=$f:runs:AVERAGE"
timegraphs[$i]="DEF:$name=$f:time:AVERAGE"
errgraphs[$i]="DEF:$name=$f:errors:AVERAGE"
ftimegraphs[$i]="DEF:$name=$f:ftime:AVERAGE"
ferrgraphs[$i]="DEF:$name=$f:ferrors:AVERAGE"
let i++
rungraphs[$i]="$mode:$name$color:$name"
timegraphs[$i]="$mode:$name$color:$name"
errgraphs[$i]="$mode:$name$color:$name"
ftimegraphs[$i]="LINE:$name$color:$name"
ferrgraphs[$i]="LINE:$name$color:$name"
let i++
done
rungraphs[$i]="DEF:total=$dir/total.rrd:runs:AVERAGE"
timegraphs[$i]="DEF:total=$dir/total.rrd:time:AVERAGE"
errgraphs[$i]="DEF:total=$dir/total.rrd:errors:AVERAGE"
ftimegraphs[$i]="DEF:total=$dir/total.rrd:ftime:AVERAGE"
ferrgraphs[$i]="DEF:total=$dir/total.rrd:ferrors:AVERAGE"
let i++
rungraphs[$i]="LINE2:total#FF0000:total"
timegraphs[$i]="LINE2:total#FF0000:total"
errgraphs[$i]="LINE2:total#FF0000:total"
ftimegraphs[$i]="LINE2:total#FF0000:total"
ferrgraphs[$i]="LINE2:total#FF0000:total"
let i++
runsimg="$tgt/all-$span-runs.png"
timeimg="$tgt/all-$span-time.png"
errimg="$tgt/all-$span-errors.png"
ftimeimg="$tgt/all-$span-ftime.png"
ferrimg="$tgt/all-$span-ferrors.png"
rm "$runsimg" "$timeimg" "$errimg" "$ftimeimg" "$ferrimg"
rrdtool graph "$runsimg" -t "Calls - $title" -v "amount" -A -z -l 0 --imginfo '%s'\
--start="now-$span" --width="$width" --height="$height" --end=now \
"${rungraphs[@]}"
rrdtool graph "$timeimg" -t "Time - $title" -v "seconds" -A -z -l 0 --imginfo '%s'\
--start="now-$span" --width="$width" --height="$height" --end=now \
"${timegraphs[@]}"
rrdtool graph "$errimg" -t "Errors - $title" -v "errors" -A -z -l 0 --imginfo '%s'\
--start="now-$span" --width="$width" --height="$height" --end=now \
"${errgraphs[@]}"
rrdtool graph "$ftimeimg" -t "Time per Call - $title" -v "seconds/call" -A -z -l 0 --imginfo '%s'\
--start="now-$span" --width="$width" --height="$height" --end=now \
"${ftimegraphs[@]}"
rrdtool graph "$ferrimg" -t "Errors per Call - $title" -v "errors/call" -A -z -l 0 --imginfo '%s'\
--start="now-$span" --width="$width" --height="$height" --end=now \
"${ferrgraphs[@]}"
chmod a+r "$runsimg" "$timeimg" "$errimg" "$ftimeimg" "$ferrimg"
stackgraphs
text/x-shellscript, 2971 bytes (load raw)

