make graphs via php
[wyse_ntpd.git] / src / graphit / make_graphs.php
diff --git a/src/graphit/make_graphs.php b/src/graphit/make_graphs.php
new file mode 100644 (file)
index 0000000..74c5208
--- /dev/null
@@ -0,0 +1,149 @@
+<?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);
+?>