575fccfc9aa363d4b84c487c32ba7b043eb9da62
[wyse_ntpd.git] / src / graphit / make_graphs.php
1 <?php
2
3 $time_lapse_start = 3;
4 $time_lapse_end = 24;
5
6 if(isset($argc)) {
7         if($argc!=2) {
8                 error_log("Sorry, wrong arguments, need at least the log file name");
9                 exit(0);
10         }
11 }
12
13 echo "argc: $argc\n";
14 print_r($argv);
15
16 // first, load the data from the log
17 $fh = fopen($argv[1], "r");
18
19 // in a way, we're fudging here cause we just add 30 to time all the time
20 $ta = array();
21 $time = 0;
22 $time_begin = 0;
23 $time_end = 0;
24 while(($line = fgets($fh)) !== false) {
25         if($time == 0) {
26                 $time = ((int)(trim($line)/30))*30;
27                 $time_begin = $time;
28         }
29         else $time += 30;
30
31         $epl_line = fgets($fh);
32
33         // parse the line... oh crap
34         $lini = preg_split("/ +/", $epl_line);
35         $ta[$time]["offset"] = trim($lini[8])*1000;
36         $ta[$time]["jitter"] = trim($lini[9])*1000;
37
38         $time_end = $time;
39
40         //print_r($lini);
41         //print_r($ta);
42         //exit(0);
43 }
44
45 // create archive 1 - only has 4 hours
46 $options = array(
47 "--step", "30",
48 "--start", "$time_begin",
49 "DS:offset:GAUGE:30:U:U",
50 "DS:jitter:GAUGE:30:U:U",
51 "RRA:AVERAGE:0.5:1:2880"
52 );
53
54 $ret = rrd_create("first_4_hours.rrd", $options);
55
56 if(!$ret) {
57         echo "RRD Creation problem: ".rrd_error()."\n";
58 }
59
60 // create archive 1 everything
61 $options = array(
62 "--step", "30",
63 "--start", "$time_begin",
64 "DS:offset:GAUGE:30:U:U",
65 "DS:jitter:GAUGE:30:U:U",
66 "RRA:AVERAGE:0.5:1:2880",
67 "RRA:AVERAGE:0.5:7:2880",
68 "RRA:AVERAGE:0.5:30:2880",
69 "RRA:AVERAGE:0.5:365:2880"
70 );
71
72 $ret = rrd_create("all_data.rrd", $options);
73
74 if(!$ret) {
75         echo "RRD Creation problem: ".rrd_error()."\n";
76 }
77
78 $end_time_4 = $time_begin + (3600*$time_lapse_start);
79
80 foreach($ta as $key => $val) {
81
82         // first, update all data
83         $off = $val["offset"];
84         $jit = $val["jitter"];
85         $ret = rrd_update("all_data.rrd", array("$key:$off:$jit"));
86
87         // if we're previous to 4 hours, update 4hours as well
88         
89         if($key < $end_time_4) $ret = rrd_update("first_4_hours.rrd", array("$key:$off:$jit"));
90 }
91
92
93 // do the first four hour graphs
94 // create first four hours graph of jit
95 $options = array(
96 "--start","$time_begin",
97 "-w","600",
98 "-h","300",
99 "-l","-1",
100 "--end","$end_time_4",
101 "DEF:".$time_lapse_start."hr_jit=first_4_hours.rrd:jitter:AVERAGE",
102 "LINE2:".$time_lapse_start."hr_jit#00FF00"
103 );
104
105 // graph of jit
106 rrd_graph($time_lapse_start."hour_first_jit.png", $options);
107
108 // create first four hours graph of off
109 $options = array(
110 "--start","$time_begin",
111 "-w","600",
112 "-h","300",
113 "-l","-1000",
114 "--end","$end_time_4",
115 "DEF:".$time_lapse_start."hr_jit=first_4_hours.rrd:offset:AVERAGE",
116 "LINE2:".$time_lapse_start."hr_jit#00FF00"
117 );
118
119 // graph of offset
120 rrd_graph($time_lapse_start."hour_first_off.png", $options);
121
122
123
124 $time_last_four = $time_end-(3600*$time_lapse_end);
125
126 // do the last four hour graphs
127 // create first four hours graph of jit
128 $options = array(
129 "--start","$time_last_four",
130 "-w","600",
131 "-h","300",
132 "--end","$time_end",
133 "DEF:".$time_lapse_end."hr_jit=all_data.rrd:jitter:AVERAGE",
134 "LINE2:".$time_lapse_end."hr_jit#00FF00"
135 );
136
137 // graph of jit
138 rrd_graph($time_lapse_end."hour_last_jit.png", $options);
139
140 // create first four hours graph of off
141 $options = array(
142 "--start","$time_last_four",
143 "-w","600",
144 "-h","300",
145 "--end","$time_end",
146 "DEF:".$time_lapse_end."hr_jit=all_data.rrd:offset:AVERAGE",
147 "LINE2:".$time_lapse_end."hr_jit#00FF00"
148 );
149
150 // graph of offset
151 rrd_graph($time_lapse_end."hour_last_off.png", $options);
152 ?>