#!/bin/bash FACILITY=`echo "$1" | tr '/' '_'` TIME="$2" [ "$TIME" ] || exit 1 COLOR[0]="#0000ff" COLOR[1]="#00aa00" COLOR[2]="#ff0000" COLOR[3]="#ffff00" COLOR[4]="#00ffff" COLOR[5]="#ff00ff" OUTPUT=/var/lib/mon/graph/$FACILITY RRD=/var/lib/mon/rrd/$FACILITY/data.rrd if ! [ -e $RRD ]; then echo "rrd database $RRD not found!" exit 1 fi #load custom graph-settings [ -e /var/lib/mon/rrd/$FACILITY/config ] && source /var/lib/mon/rrd/$FACILITY/config DATASOURCES=`rrdtool info $RRD |grep ^ds|cut -f2 -d'[' | cut -f1 -d']'|uniq` CF=`rrdtool info $RRD | grep ^rra | head -1 | egrep -o '[A-Z]+'` DRAW="" DRAWTHUMB="" COLORNR=0 for DATASOURCE in $DATASOURCES; do DRAW="$DRAW DEF:$DATASOURCE=$RRD:$DATASOURCE:$CF " eval CUSTOM_DRAW="\$graph_$DATASOURCE" eval ALERT_MAX="\$alert_max_$DATASOURCE" eval ALERT_MIN="\$alert_min_$DATASOURCE" eval CAUTION_MAX="\$caution_max_$DATASOURCE" eval CAUTION_MIN="\$caution_min_$DATASOURCE" #use custom draw parameters for this datasource? if [ "$CUSTOM_DRAW" ]; then DRAW="$DRAW $CUSTOM_DRAW" else DRAW="$DRAW LINE:$DATASOURCE${COLOR[$COLORNR]}:$DATASOURCE" (( COLORNR++ )) fi #draw alert and caution lines on background [ "$ALERT_MIN" ] && DRAW="HRULE:$ALERT_MIN#ff0000 $DRAW" [ "$ALERT_MAX" ] && DRAW="HRULE:$ALERT_MAX#ff0000 $DRAW" [ "$CAUTION_MAX" ] && DRAW="HRULE:$CAUTION_MAX#aaaa00 $DRAW" [ "$CAUTION_MIN" ] && DRAW="HRULE:$CAUTION_MIN#aaaa00 $DRAW" done mkdir -p $OUTPUT 2>/dev/null trap "rm $OUTPUT/new.$$ 2>/dev/null" 0 if [ "$TIME" == "thumb" ]; then rrdtool graph $OUTPUT/new.$$ \ --color CANVAS#ffffff00 \ --color BACK#ffffff00 \ --color SHADEA#ffffff00 \ --color SHADEB#ffffff00 \ --zoom .8 \ --x-grid none \ --end now \ --disable-rrdtool-tag \ --start end-1h \ --no-legend \ --width=60 \ --height=32 \ $DRAW > /dev/null mv $OUTPUT/{new.$$,thumb.png} elif [ "$TIME" == "hour" ]; then rrdtool graph $OUTPUT/new.$$ \ --title $FACILITY \ --end now \ --start end-21600 \ $DRAW > /dev/null mv $OUTPUT/{new.$$,hour.png} elif [ "$TIME" == "day" ]; then rrdtool graph $OUTPUT/new.$$ \ --title $FACILITY \ --end now \ --start end-86400 \ $DRAW > /dev/null mv $OUTPUT/{new.$$,day.png} elif [ "$TIME" == "week" ]; then rrdtool graph $OUTPUT/new.$$ \ --title $FACILITY \ --end now \ --start end-604800 \ $DRAW > /dev/null mv $OUTPUT/{new.$$,week.png} elif [ "$TIME" == "month" ]; then rrdtool graph $OUTPUT/new.$$ \ --title $FACILITY \ --end now \ --start end-2592000 \ $DRAW > /dev/null mv $OUTPUT/{new.$$,month.png} elif [ "$TIME" == "year" ]; then rrdtool graph $OUTPUT/new.$$ \ --title $FACILITY \ --end now \ --start end-31536000 \ $DRAW > /dev/null mv $OUTPUT/{new.$$,year.png} fi