#!/bin/sh date 1>&2 counterlog=/bat/mudlib/log/c/counterd rrd_dir=/bat/data/rrd-graphs if [ ! -f $counterlog ]; then exit 0 fi sleep 1 mv $counterlog $counterlog- counterlog="$counterlog-" #time::graphname:derivative:mortalvisible:h1:h2:n1:v1:n2:v2 #h1, h2, h3 = three hex digit hash IFS=: function create_data_source { name="$1" type="$2" echo -n "DS:$name:$type:600:U:U " # 1week at full res echo -n "RRA:AVERAGE:0.1:1:2016 " echo -n "RRA:MIN:0.1:1:2016 " echo -n "RRA:MAX:0.1:1:2016 " # 10 weeks at res/10 echo -n "RRA:AVERAGE:0.1:10:2016 " echo -n "RRA:MIN:0.1:10:2016 " echo -n "RRA:MAX:0.1:10:2016 " # 100 weeks at res/100 echo -n "RRA:AVERAGE:0.1:100:2016 " echo -n "RRA:MIN:0.1:100:2016 " echo -n "RRA:MAX:0.1:100:2016 " # 1000 weeks at res/1000 echo -n "RRA:AVERAGE:0.1:1000:2016 " echo -n "RRA:MIN:0.1:1000:2016 " echo -n "RRA:MAX:0.1:1000:2016 " } cat $counterlog | tr -d '[|&`$;]' | sed 's/\.\.//g' | while read time graph derivative mortalvisible h1 h2 h3 n1 v1 n2 v2; do echo "t=$time,g=$graph,d=$derivative,m=$mortalvisible,h1=$h1,h2=$h2,n1=$n1,v1=$v1,n2=$n2,v2=$v2" 1>&2 dir="$rrd_dir" [ -x "$dir" ] || mkdir -m 775 -p "$dir" fn="$dir/$graph.rrd" [ "$derivative" -eq 1 ] && type=COUNTER || type=GAUGE if [ ! -f "$fn" ]; then echo "$fn,$derivative,$mortalvisible,$n1,$n2" > $fn.desc echo -n create "$fn" --step 300 " " create_data_source "$n1" "$type" [ ! -z "$n2" ] && create_data_source "$n2" "$type" echo "" fi [ ! -z "$v2" ] && v2=":$v2" echo update "$fn" "$time:$v1$v2" done | /bat/bin/rrdtool.dura2 - 1>&2 rsync -e ssh --delete -r /bat/data/rrd-graphs root@www.bat.org:/x