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