rm -f data.rrd
-START_TIME=`head -1 $INPUT`
+START_TIME_A=`head -1 $INPUT`
+START_TIME=`echo $START_TIME_A-10|bc`
echo "Createing rrd archive"
rrdtool create data.rrd --step 30 \
--start $START_TIME \
DS:offset:GAUGE:30:U:U \
DS:jitter:GAUGE:30:U:U \
-RRA:AVERAGE:0.5:1:480 \
RRA:AVERAGE:0.5:1:2880 \
RRA:AVERAGE:0.5:7:2880 \
RRA:AVERAGE:0.5:30:2880 \
RRA:AVERAGE:0.5:365:2880
+TIME=`echo "$START_TIME+30"|bc`
+#END_TIME=`echo "$START_TIME
cat $INPUT | while read line
do
- TIME="$line"
+ #TIME="$line"
+ TIME=`echo "$TIME+30"|bc`
read line2
OFFSET=`echo $line2 |awk '{ print $9 }'`
JITTER=`echo $line2 |awk '{ print $10 }'`
END_4HR=`echo $START_TIME+14400|bc`
rrdtool graph 4hr_off.png --start $START_TIME \
- -w 600 -h 300 \
+ -w 600 -h 300 -l -1 \
--end $END_4HR \
DEF:4hr_jit=data.rrd:jitter:AVERAGE \
LINE2:4hr_jit#00FF00
--- /dev/null
+<?php
+
+if(isset($argc)) {
+ if($argc!=2) {
+ error_log("Sorry, wrong arguments, need at least the log file name");
+ exit(0);
+ }
+}
+
+echo "argc: $argc\n";
+print_r($argv);
+
+// first, load the data from the log
+$fh = fopen($argv[1], "r");
+
+// in a way, we're fudging here cause we just add 30 to time all the time
+$ta = array();
+$time = 0;
+$time_begin = 0;
+$time_end = 0;
+while(($line = fgets($fh)) !== false) {
+ if($time == 0) {
+ $time = ((int)(trim($line)/30))*30;
+ $time_begin = $time;
+ }
+ else $time += 30;
+
+ $epl_line = fgets($fh);
+
+ // parse the line... oh crap
+ $lini = preg_split("/ +/", $epl_line);
+ $ta[$time]["offset"] = trim($lini[8]);
+ $ta[$time]["jitter"] = trim($lini[9]);
+
+ $time_end = $time;
+
+ //print_r($lini);
+ //print_r($ta);
+ //exit(0);
+}
+
+// create archive 1 - only has 4 hours
+$options = array(
+"--step", "30",
+"--start", "$time_begin",
+"DS:offset:GAUGE:30:U:U",
+"DS:jitter:GAUGE:30:U:U",
+"RRA:AVERAGE:0.5:1:2880"
+);
+
+$ret = rrd_create("first_4_hours.rrd", $options);
+
+if(!$ret) {
+ echo "RRD Creation problem: ".rrd_error()."\n";
+}
+
+// create archive 1 everything
+$options = array(
+"--step", "30",
+"--start", "$time_begin",
+"DS:offset:GAUGE:30:U:U",
+"DS:jitter:GAUGE:30:U:U",
+"RRA:AVERAGE:0.5:1:2880",
+"RRA:AVERAGE:0.5:7:2880",
+"RRA:AVERAGE:0.5:30:2880",
+"RRA:AVERAGE:0.5:365:2880"
+);
+
+$ret = rrd_create("all_data.rrd", $options);
+
+if(!$ret) {
+ echo "RRD Creation problem: ".rrd_error()."\n";
+}
+
+$end_time_4 = $time_begin + (3600*4);
+
+foreach($ta as $key => $val) {
+
+ // first, update all data
+ $off = $val["offset"];
+ $jit = $val["jitter"];
+ $ret = rrd_update("all_data.rrd", array("$key:$off:$jit"));
+
+ // if we're previous to 4 hours, update 4hours as well
+
+ if($key < $end_time_4) $ret = rrd_update("first_4_hours.rrd", array("$key:$off:$jit"));
+}
+
+
+// do the first four hour graphs
+// create first four hours graph of jit
+$options = array(
+"--start","$time_begin",
+"-w","600",
+"-h","300",
+"-l","-1",
+"--end","$end_time_4",
+"DEF:4hr_jit=first_4_hours.rrd:jitter:AVERAGE",
+"LINE2:4hr_jit#00FF00"
+);
+
+// graph of jit
+rrd_graph("4hour_first_jit.png", $options);
+
+// create first four hours graph of off
+$options = array(
+"--start","$time_begin",
+"-w","600",
+"-h","300",
+"-l","-1",
+"--end","$end_time_4",
+"DEF:4hr_jit=first_4_hours.rrd:offset:AVERAGE",
+"LINE2:4hr_jit#00FF00"
+);
+
+// graph of offset
+rrd_graph("4hour_first_off.png", $options);
+
+
+
+$time_last_four = $time_end-(3600*4);
+
+// do the last four hour graphs
+// create first four hours graph of jit
+$options = array(
+"--start","$time_last_four",
+"-w","600",
+"-h","300",
+"--end","$time_end",
+"DEF:4hr_jit=all_data.rrd:jitter:AVERAGE",
+"LINE2:4hr_jit#00FF00"
+);
+
+// graph of jit
+rrd_graph("4hour_last_jit.png", $options);
+
+// create first four hours graph of off
+$options = array(
+"--start","$time_last_four",
+"-w","600",
+"-h","300",
+"--end","$time_end",
+"DEF:4hr_jit=all_data.rrd:offset:AVERAGE",
+"LINE2:4hr_jit#00FF00"
+);
+
+// graph of offset
+rrd_graph("4hour_last_off.png", $options);
+?>