[143] | 1 | <?php |
---|
[225] | 2 | /* |
---|
| 3 | * |
---|
| 4 | * This file is part of Jobmonarch |
---|
| 5 | * |
---|
[830] | 6 | * Copyright (C) 2006-2013 Ramon Bastiaans |
---|
[225] | 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 830 2013-04-12 13:52:25Z ramonb $ |
---|
[225] | 23 | */ |
---|
| 24 | |
---|
[761] | 25 | global $rrds, $start, $r, $conf, $m; |
---|
[143] | 26 | |
---|
[409] | 27 | include "./libtoga.php"; |
---|
| 28 | |
---|
[761] | 29 | # Graph specific variables |
---|
| 30 | $size = escapeshellcmd( rawurldecode( $_GET["z"] )); |
---|
| 31 | $graph = escapeshellcmd( rawurldecode( $_GET["g"] )); |
---|
| 32 | $grid = escapeshellcmd( rawurldecode( $_GET["G"] )); |
---|
| 33 | $self = escapeshellcmd( rawurldecode( $_GET["me"] )); |
---|
| 34 | $max = escapeshellcmd( rawurldecode( $_GET["x"] )); |
---|
| 35 | $min = escapeshellcmd( rawurldecode( $_GET["n"] )); |
---|
| 36 | $value = escapeshellcmd( rawurldecode( $_GET["v"] )); |
---|
| 37 | $load_color = escapeshellcmd( rawurldecode( $_GET["l"] )); |
---|
| 38 | $vlabel = escapeshellcmd( rawurldecode( $_GET["vl"] )); |
---|
| 39 | $j_title = escapeshellcmd( rawurldecode( $_GET["t"] )); |
---|
| 40 | $hostname = escapeshellcmd( rawurldecode( $_GET["h"] )); |
---|
| 41 | $range = escapeshellcmd( rawurldecode( $_GET["r"] )); |
---|
[751] | 42 | |
---|
[761] | 43 | if( strpos( $size, 'overview' ) ) |
---|
| 44 | { |
---|
| 45 | $my_dir = getcwd(); |
---|
[751] | 46 | |
---|
[761] | 47 | global $context; |
---|
[751] | 48 | |
---|
[761] | 49 | $context = 'host'; |
---|
[751] | 50 | |
---|
[761] | 51 | chdir( $GANGLIA_PATH ); |
---|
[751] | 52 | |
---|
[761] | 53 | include "./ganglia.php"; |
---|
| 54 | include "./get_ganglia.php"; |
---|
[751] | 55 | |
---|
[761] | 56 | chdir( $my_dir ); |
---|
| 57 | } |
---|
| 58 | |
---|
[717] | 59 | if ( !empty( $_GET ) ) |
---|
| 60 | { |
---|
[143] | 61 | extract( $_GET ); |
---|
| 62 | } |
---|
| 63 | |
---|
[409] | 64 | $sourcetime = $st; |
---|
| 65 | |
---|
[143] | 66 | |
---|
[145] | 67 | $cluster = $c; |
---|
| 68 | $metricname = ($g) ? $g : $m; |
---|
| 69 | |
---|
[143] | 70 | # Assumes we have a $start variable (set in get_context.php). |
---|
[717] | 71 | if ($size == "small") |
---|
| 72 | { |
---|
| 73 | $height = 40; |
---|
| 74 | $width = 130; |
---|
| 75 | } |
---|
| 76 | else if ($size == "medium") |
---|
| 77 | { |
---|
| 78 | $height = 75; |
---|
| 79 | $width = 300; |
---|
| 80 | } |
---|
[731] | 81 | else if ($size == "overview-medium") |
---|
| 82 | { |
---|
| 83 | $height = 75; |
---|
| 84 | $width = 300; |
---|
| 85 | } |
---|
[717] | 86 | else |
---|
| 87 | { |
---|
| 88 | $height = 100; |
---|
| 89 | $width = 400; |
---|
[145] | 90 | } |
---|
[143] | 91 | |
---|
[796] | 92 | // RB: Perform some formatting/spacing magic.. tinkered to fit |
---|
| 93 | // |
---|
| 94 | if ($size == 'small') { |
---|
| 95 | $eol1 = '\\l'; |
---|
| 96 | $space1 = ' '; |
---|
| 97 | $space2 = ' '; |
---|
| 98 | } else if ($size == 'medium') { |
---|
| 99 | $eol1 = ''; |
---|
[800] | 100 | $space1 = ''; |
---|
[796] | 101 | $space2 = ''; |
---|
[797] | 102 | $extras = ' --font LEGEND:7 '; |
---|
[796] | 103 | } else if ($size == 'overview-medium') { |
---|
| 104 | $eol1 = ''; |
---|
| 105 | $space1 = ''; |
---|
| 106 | $space2 = ''; |
---|
[797] | 107 | $extras = ' --font LEGEND:7 '; |
---|
[796] | 108 | } else if ($size == 'large') { |
---|
| 109 | $eol1 = ''; |
---|
| 110 | $space1 = ' '; |
---|
| 111 | $space2 = ' '; |
---|
| 112 | } else if ($size == 'xlarge') { |
---|
| 113 | $eol1 = ''; |
---|
| 114 | $space1 = ' '; |
---|
| 115 | $space2 = ' '; |
---|
| 116 | } else if ($size == 'mobile') { |
---|
| 117 | $eol1 = ''; |
---|
| 118 | $space1 = ' '; |
---|
| 119 | $space2 = ''; |
---|
| 120 | } |
---|
| 121 | |
---|
[795] | 122 | $jobstart_color = "3AE302"; |
---|
| 123 | $jobstop_color = "F5164A"; |
---|
[731] | 124 | |
---|
[717] | 125 | if($command) |
---|
| 126 | { |
---|
[145] | 127 | $command = ''; |
---|
| 128 | } |
---|
[143] | 129 | |
---|
[145] | 130 | $graph = $metricname; |
---|
[143] | 131 | |
---|
[731] | 132 | $rrd_dirs = Array(); |
---|
| 133 | |
---|
[717] | 134 | if (isset($graph)) |
---|
| 135 | { |
---|
| 136 | $series = ''; |
---|
[739] | 137 | if( $size == 'overview-medium' ) |
---|
[717] | 138 | { |
---|
[739] | 139 | $rrd_dirs[] = $conf['rrds'] . '/' . $cluster .'/'. $hostname; |
---|
[717] | 140 | } |
---|
[739] | 141 | else |
---|
| 142 | { |
---|
| 143 | $trd = new TarchRrdGraph( $cluster, $hostname ); |
---|
| 144 | $rrd_dirs = $trd->getRrdDirs( $period_start, $period_stop ); |
---|
[779] | 145 | |
---|
[739] | 146 | } |
---|
[143] | 147 | |
---|
[717] | 148 | if($graph == "cpu_report") |
---|
| 149 | { |
---|
[433] | 150 | |
---|
[819] | 151 | $title = "CPU: $hostname"; |
---|
[143] | 152 | |
---|
[717] | 153 | $upper_limit = "--upper-limit 100 --rigid"; |
---|
| 154 | $lower_limit = "--lower-limit 0"; |
---|
[143] | 155 | |
---|
[717] | 156 | $vertical_label = "--vertical-label Percent "; |
---|
[143] | 157 | |
---|
[717] | 158 | $def_nr = 0; |
---|
[143] | 159 | |
---|
[717] | 160 | foreach( $rrd_dirs as $rrd_dir ) |
---|
| 161 | { |
---|
[143] | 162 | |
---|
[717] | 163 | $series .= "DEF:'cpu_user${def_nr}'='${rrd_dir}/cpu_user.rrd':'sum':AVERAGE " |
---|
| 164 | ."DEF:'cpu_nice${def_nr}'='${rrd_dir}/cpu_nice.rrd':'sum':AVERAGE " |
---|
| 165 | ."DEF:'cpu_system${def_nr}'='${rrd_dir}/cpu_system.rrd':'sum':AVERAGE " |
---|
| 166 | ."DEF:'cpu_idle${def_nr}'='${rrd_dir}/cpu_idle.rrd':'sum':AVERAGE " |
---|
[798] | 167 | ."DEF:'cpu_wio${def_nr}'='${rrd_dir}/cpu_wio.rrd':'sum':AVERAGE "; |
---|
[143] | 168 | |
---|
[804] | 169 | $report_names = array( "user", "nice", "system", "wio", "idle" ); |
---|
| 170 | |
---|
[798] | 171 | if( $conf['graphreport_stats'] ) |
---|
[717] | 172 | { |
---|
[804] | 173 | foreach( $report_names as $r ) |
---|
| 174 | { |
---|
| 175 | $series .= "CDEF:cpu_${r}${def_nr}_nonans=cpu_${r}${def_nr},UN,0,cpu_${r}${def_nr},IF "; |
---|
| 176 | } |
---|
[717] | 177 | } |
---|
[143] | 178 | |
---|
[717] | 179 | $def_nr++; |
---|
| 180 | } |
---|
[143] | 181 | |
---|
[798] | 182 | if( $conf['graphreport_stats'] ) |
---|
| 183 | { |
---|
| 184 | $s_last = $def_nr - 1; |
---|
| 185 | $user_sum = "CDEF:cpu_user=cpu_user0_nonans"; |
---|
| 186 | $nice_sum = "CDEF:cpu_nice=cpu_nice0_nonans"; |
---|
| 187 | $system_sum = "CDEF:cpu_system=cpu_system0_nonans"; |
---|
| 188 | $wio_sum = "CDEF:cpu_wio=cpu_wio0_nonans"; |
---|
| 189 | $idle_sum = "CDEF:cpu_idle=cpu_idle0_nonans"; |
---|
| 190 | |
---|
| 191 | if( $s_last > 1 ) |
---|
| 192 | { |
---|
| 193 | foreach (range(1, ($s_last)) as $print_nr ) |
---|
| 194 | { |
---|
| 195 | $user_sum .= ",cpu_user{$print_nr}_nonans,+"; |
---|
| 196 | $nice_sum .= ",cpu_nice{$print_nr}_nonans,+"; |
---|
| 197 | $system_sum .= ",cpu_system{$print_nr}_nonans,+"; |
---|
| 198 | $wio_sum .= ",cpu_wio{$print_nr}_nonans,+"; |
---|
| 199 | $idle_sum .= ",cpu_idle{$print_nr}_nonans,+"; |
---|
| 200 | } |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | $user_sum .= " "; |
---|
| 204 | $nice_sum .= " "; |
---|
| 205 | $system_sum .= " "; |
---|
| 206 | $wio_sum .= " "; |
---|
| 207 | $idle_sum .= " "; |
---|
| 208 | |
---|
| 209 | $series .= $user_sum . $nice_sum . $system_sum . $wio_sum . $idle_sum; |
---|
| 210 | |
---|
| 211 | |
---|
| 212 | $r_count = 0; |
---|
| 213 | |
---|
| 214 | foreach( $report_names as $r ) |
---|
| 215 | { |
---|
[800] | 216 | $legend_str = ucfirst( $r ); |
---|
| 217 | |
---|
[798] | 218 | if( $r_count == 0 ) |
---|
| 219 | { |
---|
| 220 | $graph_str = "AREA"; |
---|
| 221 | } |
---|
| 222 | else |
---|
| 223 | { |
---|
| 224 | $graph_str = "STACK"; |
---|
| 225 | } |
---|
| 226 | foreach (range(0, ($s_last)) as $print_nr ) |
---|
| 227 | { |
---|
[800] | 228 | |
---|
[798] | 229 | $series .= "${graph_str}:'cpu_${r}${print_nr}'#".$conf['cpu_'.${r}.'_color'].":'${legend_str}\g' "; |
---|
[800] | 230 | $legend_str = ''; |
---|
[798] | 231 | } |
---|
| 232 | |
---|
| 233 | $series .= "VDEF:'${r}_last'=cpu_${r},LAST "; |
---|
| 234 | $series .= "VDEF:'${r}_min'=cpu_${r},MINIMUM "; |
---|
| 235 | $series .= "VDEF:'${r}_avg'=cpu_${r},AVERAGE "; |
---|
| 236 | $series .= "VDEF:'${r}_max'=cpu_${r},MAXIMUM "; |
---|
| 237 | |
---|
| 238 | $spacefill = ''; |
---|
| 239 | |
---|
| 240 | $spacesize = 6-strlen($r); |
---|
| 241 | foreach ( range( 0, $spacesize ) as $whatever ) |
---|
| 242 | { |
---|
| 243 | $spacefill .= ' '; |
---|
| 244 | } |
---|
| 245 | |
---|
[808] | 246 | $series .= "GPRINT:'${r}_last':'${spacefill}Last\:%6.1lf%%' " |
---|
[801] | 247 | . "GPRINT:'${r}_min':'${space1}Min\:%6.1lf%%${eol1}' " |
---|
| 248 | . "GPRINT:'${r}_avg':'${space2}Avg\:%6.1lf%%' " |
---|
| 249 | . "GPRINT:'${r}_max':'${space1}Max\:%6.1lf%%\\l' "; |
---|
[800] | 250 | |
---|
| 251 | $r_count = $r_count + 1; |
---|
[798] | 252 | } |
---|
| 253 | } |
---|
| 254 | else |
---|
| 255 | { |
---|
| 256 | $series .= "AREA:'cpu_user${def_nr}'#".$conf['cpu_user_color']."${user_str} " |
---|
| 257 | ."STACK:'cpu_nice${def_nr}'#".$conf['cpu_nice_color']."${nice_str} " |
---|
| 258 | ."STACK:'cpu_system${def_nr}'#".$conf['cpu_system_color']."${system_str} " |
---|
| 259 | ."STACK:'cpu_wio${def_nr}'#".$conf['cpu_wio_color']."${wio_str} " |
---|
| 260 | ."STACK:'cpu_idle${def_nr}'#".$conf['cpu_idle_color']."${idle_str} "; |
---|
| 261 | } |
---|
| 262 | |
---|
[717] | 263 | } |
---|
| 264 | else if ($graph == "job_report") |
---|
| 265 | { |
---|
[819] | 266 | $title = "Jobs"; |
---|
[409] | 267 | |
---|
[717] | 268 | $lower_limit = "--lower-limit 0 --rigid"; |
---|
| 269 | $vertical_label = "--vertical-label Jobs"; |
---|
[409] | 270 | |
---|
[717] | 271 | $def_nr = 0; |
---|
[409] | 272 | |
---|
[761] | 273 | $rrd_dir = $conf['rrds'] . "/$clustername/$hostname/"; |
---|
[409] | 274 | |
---|
[726] | 275 | $rj_rrd = $rrd_dir . "zplugin_monarch_rj.rrd"; |
---|
| 276 | $qj_rrd = $rrd_dir . "zplugin_monarch_qj.rrd"; |
---|
[409] | 277 | |
---|
[717] | 278 | $sorted_hosts = array(); |
---|
[738] | 279 | $sorted_hosts[] = $rjqj_host; |
---|
[409] | 280 | |
---|
[717] | 281 | $rj_str = ":'Running Jobs'"; |
---|
| 282 | $qj_str = ":'Queued Jobs'"; |
---|
[409] | 283 | |
---|
[717] | 284 | $series .= "DEF:'running_jobs'='${rj_rrd}':'sum':AVERAGE " |
---|
[796] | 285 | ."DEF:'queued_jobs'='${qj_rrd}':'sum':AVERAGE "; |
---|
[409] | 286 | |
---|
[717] | 287 | |
---|
[796] | 288 | $series .= "LINE3:'running_jobs'#ff0000${rj_str} "; |
---|
[409] | 289 | |
---|
[796] | 290 | if ( $conf['graphreport_stats'] ) |
---|
| 291 | { |
---|
| 292 | $series .= "CDEF:running_pos=running_jobs,0,INF,LIMIT " |
---|
| 293 | . "VDEF:running_last=running_pos,LAST " |
---|
| 294 | . "VDEF:running_min=running_pos,MINIMUM " |
---|
| 295 | . "VDEF:running_avg=running_pos,AVERAGE " |
---|
| 296 | . "VDEF:running_max=running_pos,MAXIMUM " |
---|
[808] | 297 | . "GPRINT:'running_last':' ${space1}Last\:%5.0lf' " |
---|
[796] | 298 | . "GPRINT:'running_min':'${space1}Min\:%5.0lf${eol1}' " |
---|
| 299 | . "GPRINT:'running_avg':'${space2}Avg\:%5.0lf' " |
---|
| 300 | . "GPRINT:'running_max':'${space1}Max\:%5.0lf\\l' "; |
---|
| 301 | } |
---|
| 302 | |
---|
| 303 | $series .= "LINE3:'queued_jobs'#999999${qj_str} "; |
---|
| 304 | |
---|
| 305 | if ( $conf['graphreport_stats'] ) |
---|
| 306 | { |
---|
| 307 | $series .= "CDEF:queued_pos=queued_jobs,0,INF,LIMIT " |
---|
| 308 | . "VDEF:queued_last=queued_pos,LAST " |
---|
| 309 | . "VDEF:queued_min=queued_pos,MINIMUM " |
---|
| 310 | . "VDEF:queued_avg=queued_pos,AVERAGE " |
---|
| 311 | . "VDEF:queued_max=queued_pos,MAXIMUM " |
---|
[808] | 312 | . "GPRINT:'queued_last':' ${space1}Last\:%5.0lf' " |
---|
[796] | 313 | . "GPRINT:'queued_min':'${space1}Min\:%5.0lf${eol1}' " |
---|
| 314 | . "GPRINT:'queued_avg':'${space2}Avg\:%5.0lf' " |
---|
| 315 | . "GPRINT:'queued_max':'${space1}Max\:%5.0lf\\l' "; |
---|
| 316 | } |
---|
[717] | 317 | } |
---|
| 318 | else if ($graph == "mem_report") |
---|
| 319 | { |
---|
[819] | 320 | $title = "Memory: $hostname"; |
---|
[143] | 321 | |
---|
[717] | 322 | $lower_limit = "--lower-limit 0 --rigid"; |
---|
[796] | 323 | $extras .= "--base 1024"; |
---|
[717] | 324 | $vertical_label = "--vertical-label Bytes"; |
---|
[143] | 325 | |
---|
[717] | 326 | $def_nr = 0; |
---|
[143] | 327 | |
---|
[717] | 328 | foreach( $rrd_dirs as $rrd_dir ) |
---|
| 329 | { |
---|
| 330 | $series .= "DEF:'mem_total${def_nr}'='${rrd_dir}/mem_total.rrd':'sum':AVERAGE " |
---|
| 331 | ."CDEF:'bmem_total${def_nr}'=mem_total${def_nr},1024,* " |
---|
| 332 | ."DEF:'mem_shared${def_nr}'='${rrd_dir}/mem_shared.rrd':'sum':AVERAGE " |
---|
| 333 | ."CDEF:'bmem_shared${def_nr}'=mem_shared${def_nr},1024,* " |
---|
| 334 | ."DEF:'mem_free${def_nr}'='${rrd_dir}/mem_free.rrd':'sum':AVERAGE " |
---|
| 335 | ."CDEF:'bmem_free${def_nr}'=mem_free${def_nr},1024,* " |
---|
| 336 | ."DEF:'mem_cached${def_nr}'='${rrd_dir}/mem_cached.rrd':'sum':AVERAGE " |
---|
| 337 | ."CDEF:'bmem_cached${def_nr}'=mem_cached${def_nr},1024,* " |
---|
[799] | 338 | ."DEF:'mem_buffer${def_nr}'='${rrd_dir}/mem_buffers.rrd':'sum':AVERAGE " |
---|
| 339 | ."CDEF:'bmem_buffer${def_nr}'=mem_buffer${def_nr},1024,* " |
---|
| 340 | ."CDEF:'bmem_used${def_nr}'='bmem_total${def_nr}','bmem_shared${def_nr}',-,'bmem_free${def_nr}',-,'bmem_cached${def_nr}',-,'bmem_buffer${def_nr}',- " |
---|
| 341 | ."DEF:'swap_total${def_nr}'='${rrd_dir}/swap_total.rrd':'sum':AVERAGE " |
---|
| 342 | ."DEF:'swap_free${def_nr}'='${rrd_dir}/swap_free.rrd':'sum':AVERAGE " |
---|
| 343 | ."CDEF:'bmem_swap${def_nr}'='swap_total${def_nr}','swap_free${def_nr}',-,1024,* "; |
---|
[145] | 344 | |
---|
[799] | 345 | $report_names = array( "used", "shared", "cached", "buffer", "swap", "total" ); |
---|
| 346 | |
---|
| 347 | if( $conf['graphreport_stats'] ) |
---|
[717] | 348 | { |
---|
[799] | 349 | foreach( $report_names as $r ) |
---|
| 350 | { |
---|
| 351 | $series .= "CDEF:bmem_${r}${def_nr}_nonans=bmem_${r}${def_nr},UN,0,bmem_${r}${def_nr},IF "; |
---|
| 352 | } |
---|
[717] | 353 | } |
---|
[145] | 354 | |
---|
[717] | 355 | $def_nr++; |
---|
| 356 | } |
---|
[145] | 357 | |
---|
[799] | 358 | if( $conf['graphreport_stats'] ) |
---|
| 359 | { |
---|
| 360 | $s_last = $def_nr - 1; |
---|
| 361 | |
---|
| 362 | foreach( $report_names as $r ) |
---|
| 363 | { |
---|
| 364 | $cdef_sum = "CDEF:bmem_${r}=bmem_${r}0_nonans"; |
---|
| 365 | |
---|
| 366 | if( $s_last > 1 ) |
---|
| 367 | { |
---|
| 368 | foreach (range(1, ($s_last)) as $print_nr ) |
---|
| 369 | { |
---|
| 370 | $user_sum .= ",bmem_${r}{$print_nr}_nonans,+"; |
---|
| 371 | } |
---|
| 372 | } |
---|
| 373 | $cdef_sum .= " "; |
---|
| 374 | |
---|
| 375 | $series .= $cdef_sum; |
---|
| 376 | } |
---|
| 377 | |
---|
| 378 | $r_count = 0; |
---|
| 379 | |
---|
| 380 | $conf['mem_buffer_color'] = $conf['mem_buffered_color']; |
---|
[800] | 381 | $conf['mem_swap_color'] = $conf['mem_swapped_color']; |
---|
| 382 | $conf['mem_total_color'] = $conf['cpu_num_color']; |
---|
[799] | 383 | |
---|
| 384 | foreach( $report_names as $r ) |
---|
| 385 | { |
---|
[800] | 386 | $legend_str = ucfirst( $r ); |
---|
[799] | 387 | |
---|
| 388 | if( $r == "total" ) |
---|
| 389 | { |
---|
| 390 | $graph_str = "LINE2"; |
---|
| 391 | } |
---|
| 392 | else if( $r_count == 0 ) |
---|
| 393 | { |
---|
| 394 | $graph_str = "AREA"; |
---|
| 395 | } |
---|
| 396 | else |
---|
| 397 | { |
---|
| 398 | $graph_str = "STACK"; |
---|
| 399 | } |
---|
| 400 | foreach (range(0, ($s_last)) as $print_nr ) |
---|
| 401 | { |
---|
| 402 | $series .= "${graph_str}:'bmem_${r}${print_nr}'#".$conf['mem_'.${r}.'_color'].":'${legend_str}\g' "; |
---|
[800] | 403 | $legend_str = ''; |
---|
[799] | 404 | } |
---|
| 405 | |
---|
| 406 | $series .= "VDEF:'${r}_last'=bmem_${r},LAST "; |
---|
| 407 | $series .= "VDEF:'${r}_min'=bmem_${r},MINIMUM "; |
---|
| 408 | $series .= "VDEF:'${r}_avg'=bmem_${r},AVERAGE "; |
---|
| 409 | $series .= "VDEF:'${r}_max'=bmem_${r},MAXIMUM "; |
---|
| 410 | |
---|
| 411 | $spacefill = ''; |
---|
| 412 | |
---|
| 413 | $spacesize = 6-strlen($r); // max length 'swapped' = 7 |
---|
| 414 | foreach ( range( 0, $spacesize ) as $whatever ) |
---|
| 415 | { |
---|
| 416 | $spacefill .= ' '; |
---|
| 417 | } |
---|
[808] | 418 | $series .= "GPRINT:'${r}_last':'${spacefill}Last\:%6.1lf%s' " |
---|
[799] | 419 | . "GPRINT:'${r}_min':'${space1}Min\:%6.1lf%s${eol1}' " |
---|
| 420 | . "GPRINT:'${r}_avg':'${space2}Avg\:%6.1lf%s' " |
---|
| 421 | . "GPRINT:'${r}_max':'${space1}Max\:%6.1lf%s\\l' "; |
---|
[804] | 422 | $r_count = $r_count + 1; |
---|
[799] | 423 | } |
---|
| 424 | } |
---|
[804] | 425 | else |
---|
| 426 | { |
---|
| 427 | $series .= "AREA:'bmem_used${def_nr}'#".$conf['mem_used_color']."${memuse_str} " |
---|
| 428 | ."STACK:'bmem_shared${def_nr}'#".$conf['mem_shared_color']."${memshared_str} " |
---|
| 429 | ."STACK:'bmem_cached${def_nr}'#".$conf['mem_cached_color']."${memcached_str} " |
---|
| 430 | ."STACK:'bmem_buffer${def_nr}'#".$conf['mem_buffered_color']."${membuff_str} " |
---|
| 431 | ."STACK:'bmem_swap${def_nr}'#".$conf['mem_swapped_color']."${memswap_str} "; |
---|
| 432 | } |
---|
[799] | 433 | |
---|
[717] | 434 | } |
---|
| 435 | else if ($graph == "load_report") |
---|
| 436 | { |
---|
[819] | 437 | $title = "Load: $hostname"; |
---|
[145] | 438 | |
---|
[717] | 439 | $lower_limit = "--lower-limit 0 --rigid"; |
---|
| 440 | $vertical_label = "--vertical-label 'Load/Procs'"; |
---|
[145] | 441 | |
---|
[717] | 442 | $def_nr = 0; |
---|
[145] | 443 | |
---|
[717] | 444 | foreach( $rrd_dirs as $rrd_dir ) |
---|
| 445 | { |
---|
[145] | 446 | |
---|
[717] | 447 | if( $def_nr == 0 ) |
---|
| 448 | { |
---|
[145] | 449 | |
---|
[717] | 450 | $load_str = ":'1-min Load'"; |
---|
| 451 | $cpu_str = ":'CPUs'"; |
---|
| 452 | $run_str = ":'Running Processes'"; |
---|
| 453 | } |
---|
| 454 | else |
---|
| 455 | { |
---|
| 456 | $load_str = ""; |
---|
| 457 | $cpu_str = ""; |
---|
| 458 | $run_str = ""; |
---|
| 459 | } |
---|
[145] | 460 | |
---|
[803] | 461 | $series .= "DEF:'load_load${def_nr}'='${rrd_dir}/load_one.rrd':'sum':AVERAGE " |
---|
| 462 | ."DEF:'load_procs${def_nr}'='${rrd_dir}/proc_run.rrd':'sum':AVERAGE " |
---|
| 463 | ."DEF:'load_cpus${def_nr}'='${rrd_dir}/cpu_num.rrd':'sum':AVERAGE "; |
---|
| 464 | |
---|
| 465 | $report_names = array( "load", "procs", "cpus" ); |
---|
| 466 | |
---|
| 467 | if( $conf['graphreport_stats'] ) |
---|
| 468 | { |
---|
| 469 | foreach( $report_names as $r ) |
---|
| 470 | { |
---|
| 471 | $series .= "CDEF:load_${r}${def_nr}_nonans=load_${r}${def_nr},UN,0,load_${r}${def_nr},IF "; |
---|
| 472 | } |
---|
| 473 | } |
---|
| 474 | |
---|
| 475 | $def_nr++; |
---|
| 476 | } |
---|
| 477 | |
---|
| 478 | if( $conf['graphreport_stats'] ) |
---|
| 479 | { |
---|
| 480 | $s_last = $def_nr - 1; |
---|
| 481 | |
---|
| 482 | foreach( $report_names as $r ) |
---|
| 483 | { |
---|
| 484 | $cdef_sum = "CDEF:load_${r}=load_${r}0_nonans"; |
---|
| 485 | |
---|
| 486 | if( $s_last > 1 ) |
---|
| 487 | { |
---|
| 488 | foreach (range(1, ($s_last)) as $print_nr ) |
---|
| 489 | { |
---|
| 490 | $user_sum .= ",load_${r}{$print_nr}_nonans,+"; |
---|
| 491 | } |
---|
| 492 | } |
---|
| 493 | $cdef_sum .= " "; |
---|
| 494 | |
---|
| 495 | $series .= $cdef_sum; |
---|
| 496 | } |
---|
| 497 | |
---|
| 498 | $conf['load_load_color'] = $conf['load_one_color']; |
---|
| 499 | $conf['load_procs_color'] = $conf['proc_run_color']; |
---|
| 500 | $conf['load_cpus_color'] = $conf['cpu_num_color']; |
---|
| 501 | |
---|
| 502 | foreach( $report_names as $r ) |
---|
| 503 | { |
---|
| 504 | $legend_str = ucfirst( $r ); |
---|
| 505 | |
---|
| 506 | if( $r == 'load' ) |
---|
| 507 | { |
---|
| 508 | $graph_str = "AREA"; |
---|
| 509 | } |
---|
| 510 | else |
---|
| 511 | { |
---|
| 512 | $graph_str = "LINE2"; |
---|
| 513 | } |
---|
| 514 | foreach (range(0, ($s_last)) as $print_nr ) |
---|
| 515 | { |
---|
| 516 | $series .= "${graph_str}:'load_${r}${print_nr}'#".$conf['load_'.${r}.'_color'].":'${legend_str}\g' "; |
---|
| 517 | $legend_str = ''; |
---|
| 518 | } |
---|
| 519 | |
---|
| 520 | $series .= "VDEF:'${r}_last'=load_${r},LAST "; |
---|
| 521 | $series .= "VDEF:'${r}_min'=load_${r},MINIMUM "; |
---|
| 522 | $series .= "VDEF:'${r}_avg'=load_${r},AVERAGE "; |
---|
| 523 | $series .= "VDEF:'${r}_max'=load_${r},MAXIMUM "; |
---|
| 524 | |
---|
| 525 | $spacefill = ''; |
---|
| 526 | |
---|
| 527 | $spacesize = 6-strlen($r); // max length 'swapped' = 7 |
---|
| 528 | foreach ( range( 0, $spacesize ) as $whatever ) |
---|
| 529 | { |
---|
| 530 | $spacefill .= ' '; |
---|
| 531 | } |
---|
[808] | 532 | $series .= "GPRINT:'${r}_last':'${spacefill}Last\:%6.1lf%s' " |
---|
[803] | 533 | . "GPRINT:'${r}_min':'${space1}Min\:%6.1lf%s${eol1}' " |
---|
| 534 | . "GPRINT:'${r}_avg':'${space2}Avg\:%6.1lf%s' " |
---|
| 535 | . "GPRINT:'${r}_max':'${space1}Max\:%6.1lf%s\\l' "; |
---|
| 536 | } |
---|
| 537 | } |
---|
| 538 | else |
---|
| 539 | { |
---|
[731] | 540 | $series .="AREA:'load_one${def_nr}'#".$conf['load_one_color']."${load_str} "; |
---|
| 541 | $series .="LINE2:'cpu_num${def_nr}'#".$conf['cpu_num_color']."${cpu_str} "; |
---|
| 542 | $series .="LINE2:'proc_run${def_nr}'#".$conf['proc_run_color']."${run_str} "; |
---|
[717] | 543 | } |
---|
| 544 | } |
---|
| 545 | else if ($graph == "network_report") |
---|
| 546 | { |
---|
[819] | 547 | $title = "Network: $hostname"; |
---|
[145] | 548 | |
---|
[717] | 549 | $lower_limit = "--lower-limit 0 --rigid"; |
---|
[796] | 550 | $extras .= "--base 1024"; |
---|
[717] | 551 | $vertical_label = "--vertical-label 'Bytes/sec'"; |
---|
[145] | 552 | |
---|
[717] | 553 | $def_nr = 0; |
---|
[145] | 554 | |
---|
[717] | 555 | foreach( $rrd_dirs as $rrd_dir ) |
---|
| 556 | { |
---|
[801] | 557 | $series .= "DEF:'bytes_in${def_nr}'='${rrd_dir}/bytes_in.rrd':'sum':AVERAGE " |
---|
| 558 | ."DEF:'bytes_out${def_nr}'='${rrd_dir}/bytes_out.rrd':'sum':AVERAGE "; |
---|
[145] | 559 | |
---|
[801] | 560 | $report_names = array( "in", "out" ); |
---|
| 561 | |
---|
| 562 | if( $conf['graphreport_stats'] ) |
---|
[717] | 563 | { |
---|
[801] | 564 | foreach( $report_names as $r ) |
---|
| 565 | { |
---|
| 566 | $series .= "CDEF:bytes_${r}${def_nr}_nonans=bytes_${r}${def_nr},UN,0,bytes_${r}${def_nr},IF "; |
---|
| 567 | } |
---|
| 568 | } |
---|
[145] | 569 | |
---|
[801] | 570 | $def_nr++; |
---|
| 571 | } |
---|
| 572 | |
---|
| 573 | if( $conf['graphreport_stats'] ) |
---|
| 574 | { |
---|
| 575 | $s_last = $def_nr - 1; |
---|
| 576 | |
---|
| 577 | foreach( $report_names as $r ) |
---|
[717] | 578 | { |
---|
[801] | 579 | $cdef_sum = "CDEF:bytes_${r}=bytes_${r}0_nonans"; |
---|
[145] | 580 | |
---|
[801] | 581 | if( $s_last > 1 ) |
---|
| 582 | { |
---|
| 583 | foreach (range(1, ($s_last)) as $print_nr ) |
---|
| 584 | { |
---|
| 585 | $user_sum .= ",bytes_${r}{$print_nr}_nonans,+"; |
---|
| 586 | } |
---|
| 587 | } |
---|
| 588 | $cdef_sum .= " "; |
---|
| 589 | |
---|
| 590 | $series .= $cdef_sum; |
---|
[717] | 591 | } |
---|
[145] | 592 | |
---|
[801] | 593 | $r_count = 0; |
---|
[145] | 594 | |
---|
[801] | 595 | $conf['bytes_out_color'] = $conf['mem_used_color']; |
---|
| 596 | $conf['bytes_in_color'] = $conf['mem_cached_color']; |
---|
| 597 | |
---|
| 598 | foreach( $report_names as $r ) |
---|
| 599 | { |
---|
| 600 | $legend_str = ucfirst( $r ); |
---|
| 601 | |
---|
| 602 | $graph_str = "LINE2"; |
---|
| 603 | |
---|
| 604 | foreach (range(0, ($s_last)) as $print_nr ) |
---|
| 605 | { |
---|
| 606 | $series .= "${graph_str}:'bytes_${r}${print_nr}'#".$conf['bytes_'.${r}.'_color'].":'${legend_str}\g' "; |
---|
| 607 | $legend_str = ''; |
---|
| 608 | } |
---|
| 609 | |
---|
| 610 | $series .= "VDEF:'${r}_last'=bytes_${r},LAST "; |
---|
| 611 | $series .= "VDEF:'${r}_min'=bytes_${r},MINIMUM "; |
---|
| 612 | $series .= "VDEF:'${r}_avg'=bytes_${r},AVERAGE "; |
---|
| 613 | $series .= "VDEF:'${r}_max'=bytes_${r},MAXIMUM "; |
---|
| 614 | |
---|
| 615 | $spacefill = ''; |
---|
| 616 | |
---|
| 617 | $spacesize = 6-strlen($r); // max length 'swapped' = 7 |
---|
| 618 | foreach ( range( 0, $spacesize ) as $whatever ) |
---|
| 619 | { |
---|
| 620 | $spacefill .= ' '; |
---|
| 621 | } |
---|
[808] | 622 | $series .= "GPRINT:'${r}_last':'${spacefill}Last\:%6.1lf%s' " |
---|
[801] | 623 | . "GPRINT:'${r}_min':'${space1}Min\:%6.1lf%s${eol1}' " |
---|
| 624 | . "GPRINT:'${r}_avg':'${space2}Avg\:%6.1lf%s' " |
---|
| 625 | . "GPRINT:'${r}_max':'${space1}Max\:%6.1lf%s\\l' "; |
---|
| 626 | |
---|
| 627 | } |
---|
[717] | 628 | } |
---|
[801] | 629 | else |
---|
| 630 | { |
---|
| 631 | $series .= "LINE2:'bytes_in${def_nr}'#".$conf['mem_cached_color']."'Bytes In' " |
---|
| 632 | ."LINE2:'bytes_out${def_nr}'#".$conf['mem_used_color']."'Bytes Out' "; |
---|
| 633 | } |
---|
[145] | 634 | |
---|
[717] | 635 | } |
---|
| 636 | else if ($graph == "packet_report") |
---|
| 637 | { |
---|
[819] | 638 | $title = "Packets: $hostname"; |
---|
[145] | 639 | |
---|
[717] | 640 | $lower_limit = "--lower-limit 0 --rigid"; |
---|
[796] | 641 | $extras .= "--base 1024"; |
---|
[717] | 642 | $vertical_label = "--vertical-label 'Packets/sec'"; |
---|
[145] | 643 | |
---|
[717] | 644 | $def_nr = 0; |
---|
[145] | 645 | |
---|
[717] | 646 | foreach( $rrd_dirs as $rrd_dir ) |
---|
| 647 | { |
---|
[145] | 648 | |
---|
[802] | 649 | $series .= "DEF:'pkts_in${def_nr}'='${rrd_dir}/pkts_in.rrd':'sum':AVERAGE " |
---|
| 650 | ."DEF:'pkts_out${def_nr}'='${rrd_dir}/pkts_out.rrd':'sum':AVERAGE "; |
---|
| 651 | |
---|
| 652 | $report_names = array( "in", "out" ); |
---|
| 653 | |
---|
| 654 | if( $conf['graphreport_stats'] ) |
---|
[717] | 655 | { |
---|
[802] | 656 | foreach( $report_names as $r ) |
---|
| 657 | { |
---|
| 658 | $series .= "CDEF:pkts_${r}${def_nr}_nonans=pkts_${r}${def_nr},UN,0,pkts_${r}${def_nr},IF "; |
---|
| 659 | } |
---|
| 660 | } |
---|
[145] | 661 | |
---|
[802] | 662 | $def_nr++; |
---|
| 663 | } |
---|
| 664 | |
---|
| 665 | if( $conf['graphreport_stats'] ) |
---|
| 666 | { |
---|
| 667 | $s_last = $def_nr - 1; |
---|
| 668 | |
---|
| 669 | foreach( $report_names as $r ) |
---|
[717] | 670 | { |
---|
[802] | 671 | $cdef_sum = "CDEF:pkts_${r}=pkts_${r}0_nonans"; |
---|
[145] | 672 | |
---|
[802] | 673 | if( $s_last > 1 ) |
---|
| 674 | { |
---|
| 675 | foreach (range(1, ($s_last)) as $print_nr ) |
---|
| 676 | { |
---|
| 677 | $user_sum .= ",pkts_${r}{$print_nr}_nonans,+"; |
---|
| 678 | } |
---|
| 679 | } |
---|
| 680 | $cdef_sum .= " "; |
---|
| 681 | |
---|
| 682 | $series .= $cdef_sum; |
---|
[717] | 683 | } |
---|
[145] | 684 | |
---|
[802] | 685 | $r_count = 0; |
---|
[145] | 686 | |
---|
[802] | 687 | $conf['pkts_out_color'] = $conf['mem_used_color']; |
---|
| 688 | $conf['pkts_in_color'] = $conf['mem_cached_color']; |
---|
| 689 | |
---|
| 690 | foreach( $report_names as $r ) |
---|
| 691 | { |
---|
| 692 | $legend_str = ucfirst( $r ); |
---|
| 693 | |
---|
| 694 | $graph_str = "LINE2"; |
---|
| 695 | |
---|
| 696 | foreach (range(0, ($s_last)) as $print_nr ) |
---|
| 697 | { |
---|
| 698 | $series .= "${graph_str}:'pkts_${r}${print_nr}'#".$conf['pkts_'.${r}.'_color'].":'${legend_str}\g' "; |
---|
| 699 | $legend_str = ''; |
---|
| 700 | } |
---|
| 701 | |
---|
| 702 | $series .= "VDEF:'${r}_last'=pkts_${r},LAST "; |
---|
| 703 | $series .= "VDEF:'${r}_min'=pkts_${r},MINIMUM "; |
---|
| 704 | $series .= "VDEF:'${r}_avg'=pkts_${r},AVERAGE "; |
---|
| 705 | $series .= "VDEF:'${r}_max'=pkts_${r},MAXIMUM "; |
---|
| 706 | |
---|
| 707 | $spacefill = ''; |
---|
| 708 | |
---|
| 709 | $spacesize = 6-strlen($r); // max length 'swapped' = 7 |
---|
| 710 | foreach ( range( 0, $spacesize ) as $whatever ) |
---|
| 711 | { |
---|
| 712 | $spacefill .= ' '; |
---|
| 713 | } |
---|
[808] | 714 | $series .= "GPRINT:'${r}_last':'${spacefill}Last\:%6.1lf%s' " |
---|
[802] | 715 | . "GPRINT:'${r}_min':'${space1}Min\:%6.1lf%s${eol1}' " |
---|
| 716 | . "GPRINT:'${r}_avg':'${space2}Avg\:%6.1lf%s' " |
---|
| 717 | . "GPRINT:'${r}_max':'${space1}Max\:%6.1lf%s\\l' "; |
---|
| 718 | |
---|
| 719 | } |
---|
[717] | 720 | } |
---|
[802] | 721 | else |
---|
| 722 | { |
---|
| 723 | $series .= "LINE2:'pkts_in${def_nr}'#".$conf['mem_cached_color']."'Packets In' " |
---|
| 724 | ."LINE2:'pkts_out${def_nr}'#".$conf['mem_used_color']."'Packets Out' "; |
---|
| 725 | } |
---|
[145] | 726 | |
---|
[717] | 727 | } |
---|
| 728 | else |
---|
| 729 | { |
---|
| 730 | /* Custom graph */ |
---|
| 731 | $style = ""; |
---|
[145] | 732 | |
---|
[717] | 733 | $subtitle = $metricname; |
---|
[736] | 734 | if($context == "host") |
---|
[717] | 735 | { |
---|
| 736 | if ($size == "small") |
---|
| 737 | $prefix = $metricname; |
---|
| 738 | else |
---|
| 739 | $prefix = $hostname; |
---|
[145] | 740 | |
---|
[717] | 741 | $value = $value>1000 ? number_format($value) : number_format($value, 2); |
---|
| 742 | } |
---|
[145] | 743 | |
---|
[717] | 744 | if (is_numeric($max)) |
---|
| 745 | $upper_limit = "--upper-limit '$max' "; |
---|
| 746 | if (is_numeric($min)) |
---|
| 747 | $lower_limit ="--lower-limit '$min' "; |
---|
[145] | 748 | |
---|
[717] | 749 | if ($vlabel) |
---|
| 750 | { |
---|
| 751 | $vertical_label = "--vertical-label '$vlabel'"; |
---|
| 752 | } |
---|
| 753 | else |
---|
| 754 | { |
---|
| 755 | if ($upper_limit or $lower_limit) |
---|
| 756 | { |
---|
| 757 | $max = $max>1000 ? number_format($max) : number_format($max, 2); |
---|
| 758 | $min = $min>0 ? number_format($min,2) : $min; |
---|
[145] | 759 | |
---|
[717] | 760 | $vertical_label ="--vertical-label '$min - $max' "; |
---|
| 761 | } |
---|
| 762 | } |
---|
[145] | 763 | |
---|
[717] | 764 | $def_nr = 0; |
---|
[145] | 765 | |
---|
[797] | 766 | |
---|
[717] | 767 | foreach( $rrd_dirs as $rrd_dir ) |
---|
| 768 | { |
---|
[145] | 769 | |
---|
[717] | 770 | if( $def_nr == 0 ) |
---|
| 771 | { |
---|
| 772 | $title_str = ":'${subtitle}'"; |
---|
| 773 | } |
---|
| 774 | else |
---|
| 775 | { |
---|
| 776 | $title_str = ""; |
---|
| 777 | } |
---|
[145] | 778 | |
---|
[717] | 779 | $rrd_file = "$rrd_dir/$metricname.rrd"; |
---|
| 780 | $series .= "DEF:'sum${def_nr}'='$rrd_file':'sum':AVERAGE " |
---|
[731] | 781 | ."AREA:'sum${def_nr}'#".$conf['default_metric_color']."${title_str} "; |
---|
[145] | 782 | |
---|
[797] | 783 | if( $conf['graphreport_stats'] ) |
---|
| 784 | { |
---|
| 785 | $series .= "CDEF:sum${def_nr}_nonans=sum${def_nr},UN,0,sum${def_nr},IF "; |
---|
| 786 | } |
---|
| 787 | |
---|
[717] | 788 | $def_nr++; |
---|
| 789 | } |
---|
[145] | 790 | |
---|
[797] | 791 | if( $conf['graphreport_stats'] ) |
---|
| 792 | { |
---|
| 793 | $s_last = $def_nr - 1; |
---|
| 794 | $series_sum = "CDEF:sum=sum0_nonans"; |
---|
| 795 | |
---|
| 796 | if( $def_nr > 1 ) |
---|
| 797 | { |
---|
| 798 | foreach (range(1, ($s_last)) as $print_nr ) |
---|
| 799 | { |
---|
| 800 | $series_sum .= ",sum{$print_nr}_nonans,+"; |
---|
| 801 | } |
---|
| 802 | } |
---|
| 803 | |
---|
| 804 | $series_sum .= " "; |
---|
| 805 | |
---|
| 806 | $series_last = "VDEF:'sum_last'=sum,LAST "; |
---|
| 807 | $series_minimum = "VDEF:'sum_min'=sum,MINIMUM "; |
---|
| 808 | $series_average = "VDEF:'sum_avg'=sum,AVERAGE "; |
---|
| 809 | $series_maximum = "VDEF:'sum_max'=sum,MAXIMUM "; |
---|
| 810 | |
---|
| 811 | $series .= $series_sum . $series_last . $series_minimum . $series_average . $series_maximum; |
---|
| 812 | |
---|
| 813 | $series .= "COMMENT:\"\\n\" "; |
---|
[808] | 814 | $series .= "GPRINT:'sum_last':'${space1}Last\:%6.1lf%s' " |
---|
[797] | 815 | . "GPRINT:'sum_min':'${space1}Min\:%6.1lf%s${eol1}' " |
---|
| 816 | . "GPRINT:'sum_avg':'${space2}Avg\:%6.1lf%s' " |
---|
| 817 | . "GPRINT:'sum_max':'${space1}Max\:%6.1lf%s\\l' "; |
---|
| 818 | } |
---|
[717] | 819 | } |
---|
[763] | 820 | } |
---|
| 821 | if( $series != '' ) |
---|
| 822 | { |
---|
| 823 | if ($job_start) |
---|
[717] | 824 | { |
---|
[795] | 825 | $series .= "VRULE:${job_start}#${jobstart_color}:'job start':dashes=4,2 "; |
---|
[717] | 826 | } |
---|
[763] | 827 | if ($job_stop) |
---|
| 828 | { |
---|
[795] | 829 | $series .= "VRULE:${job_stop}#${jobstop_color}:'job stop':dashes=4,2 "; |
---|
[763] | 830 | } |
---|
[145] | 831 | } |
---|
| 832 | |
---|
[759] | 833 | if($graph == "job_report") |
---|
[758] | 834 | { |
---|
[759] | 835 | if($range == 'job' ) |
---|
| 836 | { |
---|
| 837 | $title = "Last: $j_title"; |
---|
| 838 | } |
---|
| 839 | else |
---|
| 840 | { |
---|
| 841 | $title = "Last: $range"; |
---|
| 842 | } |
---|
[758] | 843 | } |
---|
[819] | 844 | else if( !isset( $title ) ) |
---|
[758] | 845 | { |
---|
| 846 | $title = "$hostname"; |
---|
| 847 | } |
---|
[145] | 848 | |
---|
[717] | 849 | function determineXGrid( $p_start, $p_stop ) |
---|
| 850 | { |
---|
[152] | 851 | |
---|
[717] | 852 | $period = intval( $p_stop - $p_start ); |
---|
[152] | 853 | |
---|
[717] | 854 | // Syntax: <minor_grid_lines_time_declr>:<major_grid_lines_time_declr>:<labels_time_declr>:<offset>:<format> |
---|
| 855 | // |
---|
| 856 | // Where each <*time_declr*> = <time_type>:<time_interval> |
---|
[152] | 857 | |
---|
[717] | 858 | //$my_lines1 = intval( $period / 3.0 ); |
---|
| 859 | //$my_lines2 = intval( $period / 6.0 ); |
---|
[159] | 860 | |
---|
[717] | 861 | //$my_grid = "SECOND:$my_lines2:SECOND:$my_lines1:SECOND:$my_lines1:0:%R"; |
---|
[159] | 862 | |
---|
[717] | 863 | //return "--x-grid $my_grid"; |
---|
[159] | 864 | |
---|
[717] | 865 | // Less than 1 minute |
---|
| 866 | if( $period < 60 ) |
---|
| 867 | { |
---|
[152] | 868 | |
---|
[717] | 869 | $tm_formt = "%X"; |
---|
| 870 | $my_grid = "SECOND:15:SECOND:30:SECOND:30:0:$tm_formt"; |
---|
[152] | 871 | |
---|
[717] | 872 | // Less than 10 minutes |
---|
| 873 | } |
---|
| 874 | else if( $period < 600 ) |
---|
| 875 | { |
---|
[152] | 876 | |
---|
[717] | 877 | $tm_formt = "%R"; |
---|
| 878 | $my_grid = "MINUTE:1:MINUTE:3:MINUTE:3:0:$tm_formt"; |
---|
[152] | 879 | |
---|
[717] | 880 | // Less than 1 hour |
---|
| 881 | } |
---|
| 882 | else if( $period < 3600 ) |
---|
| 883 | { |
---|
[152] | 884 | |
---|
[717] | 885 | $tm_formt = "%R"; |
---|
| 886 | $my_grid = "MINUTE:5:MINUTE:15:MINUTE:15:0:$tm_formt"; |
---|
[152] | 887 | |
---|
[717] | 888 | // Less than 15 hour |
---|
| 889 | } |
---|
| 890 | else if( $period < 3600 ) |
---|
| 891 | { |
---|
[159] | 892 | |
---|
[717] | 893 | $tm_formt = "%R"; |
---|
| 894 | $my_grid = "HOUR:1:HOUR:2:HOUR:2:0:$tm_formt"; |
---|
[159] | 895 | |
---|
[717] | 896 | // Less than 1 day |
---|
| 897 | // |
---|
| 898 | } |
---|
| 899 | else if( $period < 86400 ) |
---|
| 900 | { |
---|
[152] | 901 | |
---|
[717] | 902 | $tm_formt = "%R"; |
---|
| 903 | $my_grid = "HOUR:2:HOUR:5:HOUR:5:0:$tm_formt"; |
---|
[152] | 904 | |
---|
[717] | 905 | // Less than 15 days |
---|
| 906 | // |
---|
| 907 | } |
---|
| 908 | else if( $period < 1296000 ) |
---|
| 909 | { |
---|
[152] | 910 | |
---|
[717] | 911 | $tm_formt = "%e-%m"; |
---|
| 912 | $my_grid = "HOUR:1:DAY:3:DAY:3:0:'$tm_formt'"; |
---|
| 913 | |
---|
| 914 | // Less than 30 days (a month) |
---|
| 915 | // |
---|
| 916 | } |
---|
| 917 | else if( $period < 2592000 ) |
---|
| 918 | { |
---|
[152] | 919 | |
---|
[717] | 920 | $tm_formt = "%e-%m"; |
---|
| 921 | $my_grid = "DAY:5:DAY:10:DAY:10:0:'$tm_formt'"; |
---|
| 922 | } |
---|
[152] | 923 | |
---|
[717] | 924 | if( isset( $my_grid ) ) |
---|
| 925 | { |
---|
[152] | 926 | |
---|
[717] | 927 | $ret_str = "--x-grid $my_grid"; |
---|
| 928 | return array($ret_str,$tm_formt); |
---|
[152] | 929 | |
---|
[717] | 930 | } |
---|
| 931 | else |
---|
| 932 | { |
---|
| 933 | return array( "", "" ); |
---|
| 934 | } |
---|
[152] | 935 | } |
---|
| 936 | |
---|
[193] | 937 | $lower_limit = "--lower-limit 0"; |
---|
[159] | 938 | |
---|
[734] | 939 | if( !isset( $load_color ) or ( $load_color == '') ) |
---|
| 940 | { |
---|
| 941 | $load_color = 'FFFFFF'; |
---|
| 942 | } |
---|
| 943 | |
---|
[409] | 944 | # Calculate time range. |
---|
[733] | 945 | if ( isset($sourcetime) ) |
---|
[409] | 946 | { |
---|
[717] | 947 | $end = $sourcetime; |
---|
| 948 | # Get_context makes start negative. |
---|
| 949 | $start = $sourcetime + $start; |
---|
[409] | 950 | |
---|
[717] | 951 | # Fix from Phil Radden, but step is not always 15 anymore. |
---|
| 952 | if ($range=="month") |
---|
[733] | 953 | { |
---|
[717] | 954 | $end = floor($end / 672) * 672; |
---|
[733] | 955 | } |
---|
| 956 | $command = $conf['rrdtool']. " graph - --start $start --end $end ". |
---|
[823] | 957 | "$upper_limit $lower_limit ". |
---|
[801] | 958 | "--width $width --height $height $lower_limit $vertical_label ". |
---|
[733] | 959 | "--title '$title' $extras $background ". |
---|
| 960 | $series; |
---|
[409] | 961 | } |
---|
[733] | 962 | else |
---|
[717] | 963 | { |
---|
| 964 | $command = $conf['rrdtool'] . " graph - --start $period_start --end $period_stop ". |
---|
[823] | 965 | "$upper_limit $lower_limit ". |
---|
[801] | 966 | "--width $width --height $height $lower_limit --color BACK#$load_color $vertical_label ". |
---|
[733] | 967 | "--title '$title' $extras $background ". |
---|
| 968 | $series; |
---|
[409] | 969 | } |
---|
| 970 | |
---|
[143] | 971 | $debug=0; |
---|
| 972 | |
---|
[733] | 973 | |
---|
[143] | 974 | # Did we generate a command? Run it. |
---|
[717] | 975 | if($command) |
---|
| 976 | { |
---|
| 977 | /*Make sure the image is not cached*/ |
---|
| 978 | header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past |
---|
| 979 | header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified |
---|
| 980 | header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 |
---|
| 981 | header ("Pragma: no-cache"); // HTTP/1.0 |
---|
| 982 | if ($debug) |
---|
| 983 | { |
---|
| 984 | header ("Content-type: text/html"); |
---|
| 985 | print "$command\n\n\n\n\n"; |
---|
| 986 | } |
---|
| 987 | else |
---|
| 988 | { |
---|
| 989 | header ("Content-type: image/gif"); |
---|
| 990 | passthru($command); |
---|
| 991 | } |
---|
[145] | 992 | } |
---|
[143] | 993 | ?> |
---|