#!/bin/sh

outdir="."
file="logged"

rrdtool graph ${outdir}/${file}-${period}aa.gif \
 --start -86400 \
 --width 900 \
 --height 500 \
 --title "Logged users ($period)" \
 --rigid \
 --vertical-label "Percent(%)" \
 DEF:male=${outdir}/${file}.rrd:male:MAX \
 DEF:female=${outdir}/${file}.rrd:female:MAX \
 DEF:other=${outdir}/${file}.rrd:other:MAX \
 LINE2:male:\#FF0000 \
 LINE2:female:\#FF0000 \
 LINE2:other:\#FF0000

for period in day week month year; do
	time=""
	[ $period = "day" ]   && time="86400";
	[ $period = "week" ]  && time="604800";
	[ $period = "month" ] && time="2600640";
	[ $period = "year" ]  && time="31557600";

# --upper-limit 100 \
# --lower-limit 0 \

	rrdtool graph ${outdir}/${file}-${period}.gif \
 --start -${time} \
 --width 900 \
 --height 500 \
 --title "Logged users ($period)" \
 --rigid \
 --vertical-label "Percent(%)" \
 DEF:male=${outdir}/${file}.rrd:male:MAX \
 DEF:female=${outdir}/${file}.rrd:female:MAX \
 DEF:other=${outdir}/${file}.rrd:other:MAX \
 LINE1:male \
 AREA:male:\#FF00FF:"    male" \
 GPRINT:male:AVERAGE:"Avg  %8.2lf %s" \
 GPRINT:male:MIN:"Min  %8.2lf %s" \
 GPRINT:male:MAX:"Max  %8.2lf %s\n" \
 STACK:female:\#FFFF00:"   female" \
 GPRINT:female:AVERAGE:"Avg  %8.2lf %s" \
 GPRINT:female:MIN:"Min  %8.2lf %s" \
 GPRINT:female:MAX:"Max  %8.2lf %s\n" \
 STACK:other:\#FF0000:"   other" \
 GPRINT:other:AVERAGE:"Avg  %8.2lf %s" \
 GPRINT:other:MIN:"Min  %8.2lf_%s" \
 GPRINT:other:MAX:"Max  %8.2lf_%s\n"
done

exit

rm ${outdir}/${file}.rrd
if [ ! -f ${outdir}/${file} ]; then
	rrdtool create ${outdir}/${file}.rrd --step 300 --start 1000000000 \
		DS:male:GAUGE:600:0:U \
		DS:female:GAUGE:600:0:U \
		DS:other:GAUGE:600:0:U \
		RRA:AVERAGE:0.5:1:600 \
		RRA:AVERAGE:0.5:6:700 \
		RRA:AVERAGE:0.5:24:775 \
		RRA:AVERAGE:0.5:288:797 \
		RRA:LAST:0.5:1:600 \
		RRA:LAST:0.5:6:700 \
		RRA:LAST:0.5:24:775 \
		RRA:LAST:0.5:288:797 \
		RRA:MIN:0.5:1:600 \
		RRA:MIN:0.5:6:700 \
		RRA:MIN:0.5:24:775 \
		RRA:MIN:0.5:288:797 \
		RRA:MAX:0.5:1:600 \
		RRA:MAX:0.5:6:700 \
		RRA:MAX:0.5:24:775 \
		RRA:MAX:0.5:288:797
fi

typeset -i x
now=`date +%s`
x=$(($now-605101))
while [ $x -lt $now ]; do
	rrdtool update ${outdir}/${file}.rrd $x:${RANDOM}:${RANDOM}:${RANDOM}
	x=$(($x+300))
done

