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