1 | <?php |
---|
2 | /* |
---|
3 | * |
---|
4 | * This file is part of Jobmonarch |
---|
5 | * |
---|
6 | * Copyright (C) 2006 Ramon Bastiaans |
---|
7 | * |
---|
8 | * Jobmonarch is free software; you can redistribute it and/or modify |
---|
9 | * it under the terms of the GNU General Public License as published by |
---|
10 | * the Free Software Foundation; either version 2 of the License, or |
---|
11 | * (at your option) any later version. |
---|
12 | * |
---|
13 | * Jobmonarch is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
21 | * |
---|
22 | * SVN $Id: graph.php 433 2007-07-08 21:30:02Z bastiaans $ |
---|
23 | */ |
---|
24 | |
---|
25 | global $metrics, $rrds, $range, $start, $r; |
---|
26 | $range = $r; |
---|
27 | |
---|
28 | include "./libtoga.php"; |
---|
29 | |
---|
30 | if ( !empty( $_GET ) ) { |
---|
31 | extract( $_GET ); |
---|
32 | } |
---|
33 | |
---|
34 | //printf( "st%s\n", $st); |
---|
35 | $sourcetime = $st; |
---|
36 | //printf( "st%s\n", $sourcetime); |
---|
37 | |
---|
38 | //printf( "%s\n", $rrds ); |
---|
39 | //printf( "r%s\n", $range); |
---|
40 | //printf( "s %s\n", $start); |
---|
41 | //printf( "e %s\n", $end); |
---|
42 | |
---|
43 | # Graph specific variables |
---|
44 | $size = escapeshellcmd( rawurldecode( $HTTP_GET_VARS["z"] )); |
---|
45 | $graph = escapeshellcmd( rawurldecode( $HTTP_GET_VARS["g"] )); |
---|
46 | $grid = escapeshellcmd( rawurldecode( $HTTP_GET_VARS["G"] )); |
---|
47 | $self = escapeshellcmd( rawurldecode( $HTTP_GET_VARS["me"] )); |
---|
48 | $max = escapeshellcmd( rawurldecode( $HTTP_GET_VARS["x"] )); |
---|
49 | $min = escapeshellcmd( rawurldecode( $HTTP_GET_VARS["n"] )); |
---|
50 | $value = escapeshellcmd( rawurldecode( $HTTP_GET_VARS["v"] )); |
---|
51 | $load_color = escapeshellcmd( rawurldecode( $HTTP_GET_VARS["l"] )); |
---|
52 | $vlabel = escapeshellcmd( rawurldecode( $HTTP_GET_VARS["vl"] )); |
---|
53 | //$sourcetime = escapeshellcmd($HTTP_GET_VARS["st"]); |
---|
54 | |
---|
55 | $cluster = $c; |
---|
56 | $metricname = ($g) ? $g : $m; |
---|
57 | $hostname = $h; |
---|
58 | |
---|
59 | # Assumes we have a $start variable (set in get_context.php). |
---|
60 | if ($size == "small") { |
---|
61 | $height = 40; |
---|
62 | $width = 130; |
---|
63 | } else if ($size == "medium") { |
---|
64 | $height = 75; |
---|
65 | $width = 300; |
---|
66 | } else { |
---|
67 | $height = 100; |
---|
68 | $width = 400; |
---|
69 | } |
---|
70 | |
---|
71 | if($command) { |
---|
72 | $command = ''; |
---|
73 | } |
---|
74 | |
---|
75 | //printf( "cluster = %s hostname = %s metric = %s\n", $cluster, $hostname, $metricname ); |
---|
76 | |
---|
77 | $trd = new TarchRrdGraph( $cluster, $hostname ); |
---|
78 | //$rrd_files = $trd->getRrdFiles( $metricname, $start, $stop ); |
---|
79 | |
---|
80 | //print_r( $rrd_files ); |
---|
81 | |
---|
82 | $graph = $metricname; |
---|
83 | |
---|
84 | if (isset($graph)) { |
---|
85 | $series = ''; |
---|
86 | if( isset( $period_start ) && isset( $period_stop ) ) |
---|
87 | { |
---|
88 | $rrd_dirs = $trd->getRrdDirs( $period_start, $period_stop ); |
---|
89 | } |
---|
90 | |
---|
91 | if($graph == "cpu_report") { |
---|
92 | |
---|
93 | $style = "CPU"; |
---|
94 | //printf("ik doe die shit!\n"); |
---|
95 | |
---|
96 | $upper_limit = "--upper-limit 100 --rigid"; |
---|
97 | $lower_limit = "--lower-limit 0"; |
---|
98 | |
---|
99 | $vertical_label = "--vertical-label Percent "; |
---|
100 | |
---|
101 | $def_nr = 0; |
---|
102 | |
---|
103 | foreach( $rrd_dirs as $rrd_dir ) { |
---|
104 | |
---|
105 | if( $def_nr == 0 ) { |
---|
106 | |
---|
107 | $user_str = ":'User CPU'"; |
---|
108 | $nice_str = ":'Nice CPU'"; |
---|
109 | $system_str = ":'System CPU'"; |
---|
110 | $wio_str = ":'WAIT CPU'"; |
---|
111 | $idle_str = ":'Idle CPU'"; |
---|
112 | } else { |
---|
113 | |
---|
114 | $user_str = ""; |
---|
115 | $nice_str = ""; |
---|
116 | $system_str = ""; |
---|
117 | $wio_str = ""; |
---|
118 | $idle_str = ""; |
---|
119 | } |
---|
120 | |
---|
121 | $series .= "DEF:'cpu_user${def_nr}'='${rrd_dir}/cpu_user.rrd':'sum':AVERAGE " |
---|
122 | ."DEF:'cpu_nice${def_nr}'='${rrd_dir}/cpu_nice.rrd':'sum':AVERAGE " |
---|
123 | ."DEF:'cpu_system${def_nr}'='${rrd_dir}/cpu_system.rrd':'sum':AVERAGE " |
---|
124 | ."DEF:'cpu_idle${def_nr}'='${rrd_dir}/cpu_idle.rrd':'sum':AVERAGE " |
---|
125 | ."AREA:'cpu_user${def_nr}'#${cpu_user_color}${user_str} " |
---|
126 | ."STACK:'cpu_nice${def_nr}'#${cpu_nice_color}${nice_str} " |
---|
127 | ."STACK:'cpu_system${def_nr}'#${cpu_system_color}${system_str} "; |
---|
128 | |
---|
129 | if (file_exists("$rrd_dir/cpu_wio.rrd")) { |
---|
130 | $series .= "DEF:'cpu_wio${def_nr}'='${rrd_dir}/cpu_wio.rrd':'sum':AVERAGE " |
---|
131 | ."STACK:'cpu_wio${def_nr}'#${cpu_wio_color}${wio_str} "; |
---|
132 | } |
---|
133 | |
---|
134 | $series .= "STACK:'cpu_idle${def_nr}'#${cpu_idle_color}${idle_str} "; |
---|
135 | |
---|
136 | $def_nr++; |
---|
137 | } |
---|
138 | |
---|
139 | } else if ($graph == "job_report") { |
---|
140 | $style = "Jobs"; |
---|
141 | |
---|
142 | //$upper_limit = "--upper-limit 100 --rigid"; |
---|
143 | $lower_limit = "--lower-limit 0 --rigid"; |
---|
144 | $vertical_label = "--vertical-label Jobs"; |
---|
145 | |
---|
146 | $def_nr = 0; |
---|
147 | |
---|
148 | foreach( $metrics as $bhost => $bmetric ) |
---|
149 | { |
---|
150 | foreach( $bmetric as $mname => $mval ) |
---|
151 | { |
---|
152 | if( ( $mname == 'MONARCH-RJ' ) || ($mname == 'MONARCH-QJ') ) |
---|
153 | { |
---|
154 | $rjqj_host = $bhost; |
---|
155 | } |
---|
156 | } |
---|
157 | } |
---|
158 | |
---|
159 | $rrd_dir = "$rrds/$clustername/$rjqj_host/"; |
---|
160 | |
---|
161 | $rj_rrd = $rrd_dir . "MONARCH-RJ.rrd"; |
---|
162 | $qj_rrd = $rrd_dir . "MONARCH-QJ.rrd"; |
---|
163 | |
---|
164 | $sorted_hosts = array(); |
---|
165 | $sorted_hosts[] = $rjqj_host; |
---|
166 | |
---|
167 | //printf( "rjqjh %s\n", $rjqj_host); |
---|
168 | |
---|
169 | //printf( "rrdd %s\n", $rrd_dir ); |
---|
170 | |
---|
171 | $rj_str = ":'Running Jobs'"; |
---|
172 | $qj_str = ":'Queued Jobs'"; |
---|
173 | |
---|
174 | $series .= "DEF:'running_jobs'='${rj_rrd}':'sum':AVERAGE " |
---|
175 | ."DEF:'queued_jobs'='${qj_rrd}':'sum':AVERAGE " |
---|
176 | |
---|
177 | |
---|
178 | ."LINE3:'running_jobs'#ff0000${rj_str} " |
---|
179 | ."LINE3:'queued_jobs'#999999${qj_str} "; |
---|
180 | |
---|
181 | } else if ($graph == "mem_report") { |
---|
182 | $style = "Memory"; |
---|
183 | |
---|
184 | $lower_limit = "--lower-limit 0 --rigid"; |
---|
185 | $extras = "--base 1024"; |
---|
186 | $vertical_label = "--vertical-label Bytes"; |
---|
187 | |
---|
188 | $def_nr = 0; |
---|
189 | |
---|
190 | foreach( $rrd_dirs as $rrd_dir ) { |
---|
191 | |
---|
192 | if( $def_nr == 0 ) { |
---|
193 | |
---|
194 | $memuse_str = ":'Memory Used'"; |
---|
195 | $memshared_str = ":'Memory Shared'"; |
---|
196 | $memcached_str = ":'Memory Cached'"; |
---|
197 | $membuff_str = ":'Memory Buffered'"; |
---|
198 | $memswap_str = ":'Memory Swapped'"; |
---|
199 | $total_str = ":'Total In-Core Memory'"; |
---|
200 | } else { |
---|
201 | |
---|
202 | $memuse_str = ""; |
---|
203 | $memshared_str = ""; |
---|
204 | $memcached_str = ""; |
---|
205 | $membuff_str = ""; |
---|
206 | $memswap_str = ""; |
---|
207 | $total_str = ""; |
---|
208 | } |
---|
209 | |
---|
210 | $series .= "DEF:'mem_total${def_nr}'='${rrd_dir}/mem_total.rrd':'sum':AVERAGE " |
---|
211 | ."CDEF:'bmem_total${def_nr}'=mem_total${def_nr},1024,* " |
---|
212 | ."DEF:'mem_shared${def_nr}'='${rrd_dir}/mem_shared.rrd':'sum':AVERAGE " |
---|
213 | ."CDEF:'bmem_shared${def_nr}'=mem_shared${def_nr},1024,* " |
---|
214 | ."DEF:'mem_free${def_nr}'='${rrd_dir}/mem_free.rrd':'sum':AVERAGE " |
---|
215 | ."CDEF:'bmem_free${def_nr}'=mem_free${def_nr},1024,* " |
---|
216 | ."DEF:'mem_cached${def_nr}'='${rrd_dir}/mem_cached.rrd':'sum':AVERAGE " |
---|
217 | ."CDEF:'bmem_cached${def_nr}'=mem_cached${def_nr},1024,* " |
---|
218 | ."DEF:'mem_buffers${def_nr}'='${rrd_dir}/mem_buffers.rrd':'sum':AVERAGE " |
---|
219 | ."CDEF:'bmem_buffers${def_nr}'=mem_buffers${def_nr},1024,* " |
---|
220 | ."CDEF:'bmem_used${def_nr}'='bmem_total${def_nr}','bmem_shared${def_nr}',-,'bmem_free${def_nr}',-,'bmem_cached${def_nr}',-,'bmem_buffers${def_nr}',- " |
---|
221 | ."AREA:'bmem_used${def_nr}'#${mem_used_color}${memuse_str} " |
---|
222 | ."STACK:'bmem_shared${def_nr}'#${mem_shared_color}${memshared_str} " |
---|
223 | ."STACK:'bmem_cached${def_nr}'#${mem_cached_color}${memcached_str} " |
---|
224 | ."STACK:'bmem_buffers${def_nr}'#${mem_buffered_color}${membuff_str} "; |
---|
225 | |
---|
226 | if (file_exists("$rrd_dir/swap_total.rrd")) { |
---|
227 | $series .= "DEF:'swap_total${def_nr}'='${rrd_dir}/swap_total.rrd':'sum':AVERAGE " |
---|
228 | ."DEF:'swap_free${def_nr}'='${rrd_dir}/swap_free.rrd':'sum':AVERAGE " |
---|
229 | ."CDEF:'bmem_swapped${def_nr}'='swap_total${def_nr}','swap_free${def_nr}',-,1024,* " |
---|
230 | ."STACK:'bmem_swapped${def_nr}'#${mem_swapped_color}${memswap_str} "; |
---|
231 | } |
---|
232 | |
---|
233 | $series .= "LINE2:'bmem_total${def_nr}'#${cpu_num_color}${total_str} "; |
---|
234 | |
---|
235 | $def_nr++; |
---|
236 | } |
---|
237 | |
---|
238 | } else if ($graph == "load_report") { |
---|
239 | $style = "Load"; |
---|
240 | |
---|
241 | $lower_limit = "--lower-limit 0 --rigid"; |
---|
242 | $vertical_label = "--vertical-label 'Load/Procs'"; |
---|
243 | |
---|
244 | $def_nr = 0; |
---|
245 | |
---|
246 | foreach( $rrd_dirs as $rrd_dir ) { |
---|
247 | |
---|
248 | if( $def_nr == 0 ) { |
---|
249 | |
---|
250 | $load_str = ":'1-min Load'"; |
---|
251 | $cpu_str = ":'CPUs'"; |
---|
252 | $run_str = ":'Running Processes'"; |
---|
253 | } else { |
---|
254 | $load_str = ""; |
---|
255 | $cpu_str = ""; |
---|
256 | $run_str = ""; |
---|
257 | } |
---|
258 | |
---|
259 | $series .= "DEF:'load_one${def_nr}'='${rrd_dir}/load_one.rrd':'sum':AVERAGE " |
---|
260 | ."DEF:'proc_run${def_nr}'='${rrd_dir}/proc_run.rrd':'sum':AVERAGE " |
---|
261 | ."DEF:'cpu_num${def_nr}'='${rrd_dir}/cpu_num.rrd':'sum':AVERAGE "; |
---|
262 | $series .="AREA:'load_one${def_nr}'#${load_one_color}${load_str} "; |
---|
263 | $series .="LINE2:'cpu_num${def_nr}'#${cpu_num_color}${cpu_str} "; |
---|
264 | $series .="LINE2:'proc_run${def_nr}'#${proc_run_color}${run_str} "; |
---|
265 | |
---|
266 | $def_nr++; |
---|
267 | } |
---|
268 | |
---|
269 | } else if ($graph == "network_report") { |
---|
270 | $style = "Network"; |
---|
271 | |
---|
272 | $lower_limit = "--lower-limit 0 --rigid"; |
---|
273 | $extras = "--base 1024"; |
---|
274 | $vertical_label = "--vertical-label 'Bytes/sec'"; |
---|
275 | |
---|
276 | $def_nr = 0; |
---|
277 | |
---|
278 | foreach( $rrd_dirs as $rrd_dir ) { |
---|
279 | |
---|
280 | if( $def_nr == 0 ) { |
---|
281 | |
---|
282 | $in_str = ":'In'"; |
---|
283 | $out_str = ":'Out'"; |
---|
284 | } else { |
---|
285 | |
---|
286 | $in_str = ""; |
---|
287 | $out_str = ""; |
---|
288 | } |
---|
289 | |
---|
290 | $series .= "DEF:'bytes_in${def_nr}'='${rrd_dir}/bytes_in.rrd':'sum':AVERAGE " |
---|
291 | ."DEF:'bytes_out${def_nr}'='${rrd_dir}/bytes_out.rrd':'sum':AVERAGE " |
---|
292 | ."LINE2:'bytes_in${def_nr}'#${mem_cached_color}${in_str} " |
---|
293 | ."LINE2:'bytes_out${def_nr}'#${mem_used_color}${out_str} "; |
---|
294 | |
---|
295 | $def_nr++; |
---|
296 | } |
---|
297 | |
---|
298 | } else if ($graph == "packet_report") { |
---|
299 | $style = "Packets"; |
---|
300 | |
---|
301 | $lower_limit = "--lower-limit 0 --rigid"; |
---|
302 | $extras = "--base 1024"; |
---|
303 | $vertical_label = "--vertical-label 'Packets/sec'"; |
---|
304 | |
---|
305 | $def_nr = 0; |
---|
306 | |
---|
307 | foreach( $rrd_dirs as $rrd_dir ) { |
---|
308 | |
---|
309 | if( $def_nr == 0 ) { |
---|
310 | |
---|
311 | $in_str = ":'In'"; |
---|
312 | $out_str = ":'Out'"; |
---|
313 | } else { |
---|
314 | |
---|
315 | $in_str = ""; |
---|
316 | $out_str = ""; |
---|
317 | } |
---|
318 | |
---|
319 | $series .= "DEF:'bytes_in${def_nr}'='${rrd_dir}/pkts_in.rrd':'sum':AVERAGE " |
---|
320 | ."DEF:'bytes_out${def_nr}'='${rrd_dir}/pkts_out.rrd':'sum':AVERAGE " |
---|
321 | ."LINE2:'bytes_in${def_nr}'#${mem_cached_color}${in_str} " |
---|
322 | ."LINE2:'bytes_out${def_nr}'#${mem_used_color}${out_str} "; |
---|
323 | |
---|
324 | $def_nr++; |
---|
325 | } |
---|
326 | |
---|
327 | } else { |
---|
328 | /* Custom graph */ |
---|
329 | $style = ""; |
---|
330 | |
---|
331 | $subtitle = $metricname; |
---|
332 | if ($context == "host") { |
---|
333 | if ($size == "small") |
---|
334 | $prefix = $metricname; |
---|
335 | else |
---|
336 | $prefix = $hostname; |
---|
337 | |
---|
338 | $value = $value>1000 ? number_format($value) : number_format($value, 2); |
---|
339 | } |
---|
340 | |
---|
341 | //if ($range=="job") { |
---|
342 | // $hrs = intval( -$jobrange / 3600 ); |
---|
343 | // $subtitle = "$prefix last ${hrs}h (now $value)"; |
---|
344 | //} else |
---|
345 | // $subtitle = "$prefix last $range (now $value)"; |
---|
346 | |
---|
347 | if (is_numeric($max)) |
---|
348 | $upper_limit = "--upper-limit '$max' "; |
---|
349 | if (is_numeric($min)) |
---|
350 | $lower_limit ="--lower-limit '$min' "; |
---|
351 | |
---|
352 | if ($vlabel) |
---|
353 | $vertical_label = "--vertical-label '$vlabel'"; |
---|
354 | else { |
---|
355 | if ($upper_limit or $lower_limit) { |
---|
356 | $max = $max>1000 ? number_format($max) : number_format($max, 2); |
---|
357 | $min = $min>0 ? number_format($min,2) : $min; |
---|
358 | |
---|
359 | $vertical_label ="--vertical-label '$min - $max' "; |
---|
360 | } |
---|
361 | } |
---|
362 | |
---|
363 | $def_nr = 0; |
---|
364 | |
---|
365 | foreach( $rrd_dirs as $rrd_dir ) { |
---|
366 | |
---|
367 | if( $def_nr == 0 ) { |
---|
368 | $title_str = ":'${subtitle}'"; |
---|
369 | } else { |
---|
370 | $title_str = ""; |
---|
371 | } |
---|
372 | |
---|
373 | $rrd_file = "$rrd_dir/$metricname.rrd"; |
---|
374 | $series .= "DEF:'sum${def_nr}'='$rrd_file':'sum':AVERAGE " |
---|
375 | ."AREA:'sum${def_nr}'#${default_metric_color}${title_str} "; |
---|
376 | |
---|
377 | $def_nr++; |
---|
378 | } |
---|
379 | |
---|
380 | } |
---|
381 | if( $series != '' ) { |
---|
382 | if ($job_start) |
---|
383 | $series .= "VRULE:${job_start}#${jobstart_color} "; |
---|
384 | if ($job_stop) |
---|
385 | $series .= "VRULE:${job_stop}#${jobstart_color} "; |
---|
386 | } |
---|
387 | } |
---|
388 | |
---|
389 | //$title = "$hostname $style $metricname"; |
---|
390 | $title = "$hostname"; |
---|
391 | |
---|
392 | //# Set the graph title. |
---|
393 | //if($context == "meta") { |
---|
394 | // $title = "$self $meta_designator $style last $range"; |
---|
395 | //} else if ($context == "grid") { |
---|
396 | // $title = "$grid $meta_designator $style last $range"; |
---|
397 | //} else if ($context == "cluster") { |
---|
398 | // $title = "$clustername $style last $range"; |
---|
399 | //} else { |
---|
400 | // if ($size == "small") { |
---|
401 | // # Value for this graph define a background color. |
---|
402 | // if (!$load_color) $load_color = "ffffff"; |
---|
403 | // $background = "--color BACK#'$load_color'"; |
---|
404 | |
---|
405 | // $title = $hostname; |
---|
406 | // } else { |
---|
407 | // if ($style) |
---|
408 | // $title = "$hostname $style last $range"; |
---|
409 | // else |
---|
410 | // $title = $metricname; |
---|
411 | // } |
---|
412 | //} |
---|
413 | |
---|
414 | function determineXGrid( $p_start, $p_stop ) { |
---|
415 | |
---|
416 | $period = intval( $p_stop - $p_start ); |
---|
417 | |
---|
418 | // Syntax: <minor_grid_lines_time_declr>:<major_grid_lines_time_declr>:<labels_time_declr>:<offset>:<format> |
---|
419 | // |
---|
420 | // Where each <*time_declr*> = <time_type>:<time_interval> |
---|
421 | |
---|
422 | //$my_lines1 = intval( $period / 3.0 ); |
---|
423 | //$my_lines2 = intval( $period / 6.0 ); |
---|
424 | |
---|
425 | //$my_grid = "SECOND:$my_lines2:SECOND:$my_lines1:SECOND:$my_lines1:0:%R"; |
---|
426 | |
---|
427 | //return "--x-grid $my_grid"; |
---|
428 | |
---|
429 | // Less than 1 minute |
---|
430 | if( $period < 60 ) { |
---|
431 | |
---|
432 | $tm_formt = "%X"; |
---|
433 | $my_grid = "SECOND:15:SECOND:30:SECOND:30:0:$tm_formt"; |
---|
434 | |
---|
435 | // Less than 10 minutes |
---|
436 | } else if( $period < 600 ) { |
---|
437 | |
---|
438 | $tm_formt = "%R"; |
---|
439 | $my_grid = "MINUTE:1:MINUTE:3:MINUTE:3:0:$tm_formt"; |
---|
440 | |
---|
441 | // Less than 1 hour |
---|
442 | } else if( $period < 3600 ) { |
---|
443 | |
---|
444 | $tm_formt = "%R"; |
---|
445 | $my_grid = "MINUTE:5:MINUTE:15:MINUTE:15:0:$tm_formt"; |
---|
446 | |
---|
447 | // Less than 15 hour |
---|
448 | } else if( $period < 3600 ) { |
---|
449 | |
---|
450 | $tm_formt = "%R"; |
---|
451 | $my_grid = "HOUR:1:HOUR:2:HOUR:2:0:$tm_formt"; |
---|
452 | |
---|
453 | // Less than 1 day |
---|
454 | // |
---|
455 | } else if( $period < 86400 ) { |
---|
456 | |
---|
457 | $tm_formt = "%R"; |
---|
458 | $my_grid = "HOUR:2:HOUR:5:HOUR:5:0:$tm_formt"; |
---|
459 | |
---|
460 | // Less than 15 days |
---|
461 | // |
---|
462 | } else if( $period < 1296000 ) { |
---|
463 | |
---|
464 | $tm_formt = "%e-%m"; |
---|
465 | $my_grid = "HOUR:1:DAY:3:DAY:3:0:'$tm_formt'"; |
---|
466 | |
---|
467 | // Less than 30 days (a month) |
---|
468 | // |
---|
469 | } else if( $period < 2592000 ) { |
---|
470 | |
---|
471 | $tm_formt = "%e-%m"; |
---|
472 | $my_grid = "DAY:5:DAY:10:DAY:10:0:'$tm_formt'"; |
---|
473 | } |
---|
474 | |
---|
475 | if( isset( $my_grid ) ) { |
---|
476 | |
---|
477 | $ret_str = "--x-grid $my_grid"; |
---|
478 | return array($ret_str,$tm_formt); |
---|
479 | |
---|
480 | } else { |
---|
481 | return array( "", "" ); |
---|
482 | } |
---|
483 | } |
---|
484 | |
---|
485 | #list( $xgrid, $t_format ) = determineXGrid( $period_start, $period_stop ); |
---|
486 | |
---|
487 | #if( $t_format != "" ) { |
---|
488 | # $prnt_start = strftime( $t_format, $period_start ); |
---|
489 | # $prnt_stop = strftime( $t_format, $period_stop ); |
---|
490 | # $series .= " COMMENT:' Timescale $prnt_start - $prnt_stop' "; |
---|
491 | #} |
---|
492 | |
---|
493 | $lower_limit = "--lower-limit 0"; |
---|
494 | |
---|
495 | # Calculate time range. |
---|
496 | if( isset($sourcetime) ) |
---|
497 | { |
---|
498 | //printf("yay"); |
---|
499 | |
---|
500 | $end = $sourcetime; |
---|
501 | # Get_context makes start negative. |
---|
502 | $start = $sourcetime + $start; |
---|
503 | |
---|
504 | # Fix from Phil Radden, but step is not always 15 anymore. |
---|
505 | if ($range=="month") |
---|
506 | $end = floor($end / 672) * 672; |
---|
507 | |
---|
508 | $command = RRDTOOL . " graph - --start $start --end $end ". |
---|
509 | "--width $width --height $height $lower_limit ". |
---|
510 | "--title '$title' $extras $background ". |
---|
511 | $series; |
---|
512 | } |
---|
513 | |
---|
514 | # |
---|
515 | # Generate the rrdtool graph command. |
---|
516 | # |
---|
517 | #$command = RRDTOOL . " graph - --start $period_start --end $period_stop ". |
---|
518 | # "--width $width --height $height $upper_limit $lower_limit ". |
---|
519 | # "--title '$title' $vertical_label $extras $background $xgrid ". |
---|
520 | # $series; |
---|
521 | |
---|
522 | else { |
---|
523 | $command = RRDTOOL . " graph - --start $period_start --end $period_stop ". |
---|
524 | "--width $width --height $height $lower_limit ". |
---|
525 | "--title '$title' $extras $background ". |
---|
526 | $series; |
---|
527 | } |
---|
528 | |
---|
529 | $debug=0; |
---|
530 | |
---|
531 | # Did we generate a command? Run it. |
---|
532 | if($command) { |
---|
533 | /*Make sure the image is not cached*/ |
---|
534 | header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past |
---|
535 | header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified |
---|
536 | header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 |
---|
537 | header ("Pragma: no-cache"); // HTTP/1.0 |
---|
538 | if ($debug) { |
---|
539 | header ("Content-type: text/html"); |
---|
540 | print "$command\n\n\n\n\n"; |
---|
541 | } else { |
---|
542 | header ("Content-type: image/gif"); |
---|
543 | passthru($command); |
---|
544 | } |
---|
545 | } |
---|
546 | ?> |
---|