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