[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 799 2013-04-06 19:05:10Z 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 = ''; |
---|
| 100 | $space1 = ' '; |
---|
| 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 | |
---|
[717] | 151 | $style = "CPU"; |
---|
[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 | |
---|
[798] | 169 | if( $conf['graphreport_stats'] ) |
---|
[717] | 170 | { |
---|
[798] | 171 | $series .= "CDEF:cpu_user${def_nr}_nonans=cpu_user${def_nr},UN,0,cpu_user${def_nr},IF "; |
---|
| 172 | $series .= "CDEF:cpu_nice${def_nr}_nonans=cpu_nice${def_nr},UN,0,cpu_nice${def_nr},IF "; |
---|
| 173 | $series .= "CDEF:cpu_system${def_nr}_nonans=cpu_system${def_nr},UN,0,cpu_system${def_nr},IF "; |
---|
| 174 | $series .= "CDEF:cpu_wio${def_nr}_nonans=cpu_wio${def_nr},UN,0,cpu_wio${def_nr},IF "; |
---|
| 175 | $series .= "CDEF:cpu_idle${def_nr}_nonans=cpu_idle${def_nr},UN,0,cpu_idle${def_nr},IF "; |
---|
[717] | 176 | } |
---|
[143] | 177 | |
---|
[717] | 178 | $def_nr++; |
---|
| 179 | } |
---|
[143] | 180 | |
---|
[798] | 181 | |
---|
| 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 | $report_names = array( "user", "nice", "system", "wio", "idle" ); |
---|
| 212 | |
---|
| 213 | $r_count = 0; |
---|
| 214 | |
---|
| 215 | foreach( $report_names as $r ) |
---|
| 216 | { |
---|
| 217 | if( $r_count == 0 ) |
---|
| 218 | { |
---|
| 219 | $graph_str = "AREA"; |
---|
| 220 | $legend_str = ucfirst( $r ); |
---|
| 221 | } |
---|
| 222 | else |
---|
| 223 | { |
---|
| 224 | $graph_str = "STACK"; |
---|
| 225 | } |
---|
| 226 | foreach (range(0, ($s_last)) as $print_nr ) |
---|
| 227 | { |
---|
| 228 | $series .= "${graph_str}:'cpu_${r}${print_nr}'#".$conf['cpu_'.${r}.'_color'].":'${legend_str}\g' "; |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | $series .= "VDEF:'${r}_last'=cpu_${r},LAST "; |
---|
| 232 | $series .= "VDEF:'${r}_min'=cpu_${r},MINIMUM "; |
---|
| 233 | $series .= "VDEF:'${r}_avg'=cpu_${r},AVERAGE "; |
---|
| 234 | $series .= "VDEF:'${r}_max'=cpu_${r},MAXIMUM "; |
---|
| 235 | |
---|
| 236 | $spacefill = ''; |
---|
| 237 | |
---|
| 238 | $spacesize = 6-strlen($r); |
---|
| 239 | foreach ( range( 0, $spacesize ) as $whatever ) |
---|
| 240 | { |
---|
| 241 | $spacefill .= ' '; |
---|
| 242 | } |
---|
| 243 | |
---|
| 244 | $series .= "GPRINT:'${r}_last':'${spacefill}Now\:%6.1lf%s' " |
---|
| 245 | . "GPRINT:'${r}_min':'${space1}Min\:%6.1lf%s${eol1}' " |
---|
| 246 | . "GPRINT:'${r}_avg':'${space2}Avg\:%6.1lf%s' " |
---|
| 247 | . "GPRINT:'${r}_max':'${space1}Max\:%6.1lf%s\\l' "; |
---|
| 248 | } |
---|
| 249 | } |
---|
| 250 | else |
---|
| 251 | { |
---|
| 252 | $series .= "AREA:'cpu_user${def_nr}'#".$conf['cpu_user_color']."${user_str} " |
---|
| 253 | ."STACK:'cpu_nice${def_nr}'#".$conf['cpu_nice_color']."${nice_str} " |
---|
| 254 | ."STACK:'cpu_system${def_nr}'#".$conf['cpu_system_color']."${system_str} " |
---|
| 255 | ."STACK:'cpu_wio${def_nr}'#".$conf['cpu_wio_color']."${wio_str} " |
---|
| 256 | ."STACK:'cpu_idle${def_nr}'#".$conf['cpu_idle_color']."${idle_str} "; |
---|
| 257 | } |
---|
| 258 | |
---|
[717] | 259 | } |
---|
| 260 | else if ($graph == "job_report") |
---|
| 261 | { |
---|
| 262 | $style = "Jobs"; |
---|
[409] | 263 | |
---|
[717] | 264 | $lower_limit = "--lower-limit 0 --rigid"; |
---|
| 265 | $vertical_label = "--vertical-label Jobs"; |
---|
[409] | 266 | |
---|
[717] | 267 | $def_nr = 0; |
---|
[409] | 268 | |
---|
[761] | 269 | $rrd_dir = $conf['rrds'] . "/$clustername/$hostname/"; |
---|
[409] | 270 | |
---|
[726] | 271 | $rj_rrd = $rrd_dir . "zplugin_monarch_rj.rrd"; |
---|
| 272 | $qj_rrd = $rrd_dir . "zplugin_monarch_qj.rrd"; |
---|
[409] | 273 | |
---|
[717] | 274 | $sorted_hosts = array(); |
---|
[738] | 275 | $sorted_hosts[] = $rjqj_host; |
---|
[409] | 276 | |
---|
[717] | 277 | $rj_str = ":'Running Jobs'"; |
---|
| 278 | $qj_str = ":'Queued Jobs'"; |
---|
[409] | 279 | |
---|
[717] | 280 | $series .= "DEF:'running_jobs'='${rj_rrd}':'sum':AVERAGE " |
---|
[796] | 281 | ."DEF:'queued_jobs'='${qj_rrd}':'sum':AVERAGE "; |
---|
[409] | 282 | |
---|
[717] | 283 | |
---|
[796] | 284 | $series .= "LINE3:'running_jobs'#ff0000${rj_str} "; |
---|
[409] | 285 | |
---|
[796] | 286 | if ( $conf['graphreport_stats'] ) |
---|
| 287 | { |
---|
| 288 | $series .= "CDEF:running_pos=running_jobs,0,INF,LIMIT " |
---|
| 289 | . "VDEF:running_last=running_pos,LAST " |
---|
| 290 | . "VDEF:running_min=running_pos,MINIMUM " |
---|
| 291 | . "VDEF:running_avg=running_pos,AVERAGE " |
---|
| 292 | . "VDEF:running_max=running_pos,MAXIMUM " |
---|
| 293 | . "GPRINT:'running_last':' ${space1}Now\:%5.0lf' " |
---|
| 294 | . "GPRINT:'running_min':'${space1}Min\:%5.0lf${eol1}' " |
---|
| 295 | . "GPRINT:'running_avg':'${space2}Avg\:%5.0lf' " |
---|
| 296 | . "GPRINT:'running_max':'${space1}Max\:%5.0lf\\l' "; |
---|
| 297 | } |
---|
| 298 | |
---|
| 299 | $series .= "LINE3:'queued_jobs'#999999${qj_str} "; |
---|
| 300 | |
---|
| 301 | if ( $conf['graphreport_stats'] ) |
---|
| 302 | { |
---|
| 303 | $series .= "CDEF:queued_pos=queued_jobs,0,INF,LIMIT " |
---|
| 304 | . "VDEF:queued_last=queued_pos,LAST " |
---|
| 305 | . "VDEF:queued_min=queued_pos,MINIMUM " |
---|
| 306 | . "VDEF:queued_avg=queued_pos,AVERAGE " |
---|
| 307 | . "VDEF:queued_max=queued_pos,MAXIMUM " |
---|
| 308 | . "GPRINT:'queued_last':' ${space1}Now\:%5.0lf' " |
---|
| 309 | . "GPRINT:'queued_min':'${space1}Min\:%5.0lf${eol1}' " |
---|
| 310 | . "GPRINT:'queued_avg':'${space2}Avg\:%5.0lf' " |
---|
| 311 | . "GPRINT:'queued_max':'${space1}Max\:%5.0lf\\l' "; |
---|
| 312 | } |
---|
[717] | 313 | } |
---|
| 314 | else if ($graph == "mem_report") |
---|
| 315 | { |
---|
| 316 | $style = "Memory"; |
---|
[143] | 317 | |
---|
[717] | 318 | $lower_limit = "--lower-limit 0 --rigid"; |
---|
[796] | 319 | $extras .= "--base 1024"; |
---|
[717] | 320 | $vertical_label = "--vertical-label Bytes"; |
---|
[143] | 321 | |
---|
[717] | 322 | $def_nr = 0; |
---|
[143] | 323 | |
---|
[717] | 324 | foreach( $rrd_dirs as $rrd_dir ) |
---|
| 325 | { |
---|
| 326 | if( $def_nr == 0 ) |
---|
| 327 | { |
---|
[143] | 328 | |
---|
[717] | 329 | $memuse_str = ":'Memory Used'"; |
---|
| 330 | $memshared_str = ":'Memory Shared'"; |
---|
| 331 | $memcached_str = ":'Memory Cached'"; |
---|
| 332 | $membuff_str = ":'Memory Buffered'"; |
---|
| 333 | $memswap_str = ":'Memory Swapped'"; |
---|
| 334 | $total_str = ":'Total In-Core Memory'"; |
---|
| 335 | } |
---|
| 336 | else |
---|
| 337 | { |
---|
[143] | 338 | |
---|
[717] | 339 | $memuse_str = ""; |
---|
| 340 | $memshared_str = ""; |
---|
| 341 | $memcached_str = ""; |
---|
| 342 | $membuff_str = ""; |
---|
| 343 | $memswap_str = ""; |
---|
| 344 | $total_str = ""; |
---|
| 345 | } |
---|
[143] | 346 | |
---|
[717] | 347 | $series .= "DEF:'mem_total${def_nr}'='${rrd_dir}/mem_total.rrd':'sum':AVERAGE " |
---|
| 348 | ."CDEF:'bmem_total${def_nr}'=mem_total${def_nr},1024,* " |
---|
| 349 | ."DEF:'mem_shared${def_nr}'='${rrd_dir}/mem_shared.rrd':'sum':AVERAGE " |
---|
| 350 | ."CDEF:'bmem_shared${def_nr}'=mem_shared${def_nr},1024,* " |
---|
| 351 | ."DEF:'mem_free${def_nr}'='${rrd_dir}/mem_free.rrd':'sum':AVERAGE " |
---|
| 352 | ."CDEF:'bmem_free${def_nr}'=mem_free${def_nr},1024,* " |
---|
| 353 | ."DEF:'mem_cached${def_nr}'='${rrd_dir}/mem_cached.rrd':'sum':AVERAGE " |
---|
| 354 | ."CDEF:'bmem_cached${def_nr}'=mem_cached${def_nr},1024,* " |
---|
[799] | 355 | ."DEF:'mem_buffer${def_nr}'='${rrd_dir}/mem_buffers.rrd':'sum':AVERAGE " |
---|
| 356 | ."CDEF:'bmem_buffer${def_nr}'=mem_buffer${def_nr},1024,* " |
---|
| 357 | ."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}',- " |
---|
| 358 | ."DEF:'swap_total${def_nr}'='${rrd_dir}/swap_total.rrd':'sum':AVERAGE " |
---|
| 359 | ."DEF:'swap_free${def_nr}'='${rrd_dir}/swap_free.rrd':'sum':AVERAGE " |
---|
| 360 | ."CDEF:'bmem_swap${def_nr}'='swap_total${def_nr}','swap_free${def_nr}',-,1024,* "; |
---|
[145] | 361 | |
---|
[799] | 362 | $report_names = array( "used", "shared", "cached", "buffer", "swap", "total" ); |
---|
| 363 | |
---|
| 364 | if( $conf['graphreport_stats'] ) |
---|
[717] | 365 | { |
---|
[799] | 366 | foreach( $report_names as $r ) |
---|
| 367 | { |
---|
| 368 | $series .= "CDEF:bmem_${r}${def_nr}_nonans=bmem_${r}${def_nr},UN,0,bmem_${r}${def_nr},IF "; |
---|
| 369 | } |
---|
[717] | 370 | } |
---|
[145] | 371 | |
---|
[717] | 372 | $def_nr++; |
---|
| 373 | } |
---|
[145] | 374 | |
---|
[799] | 375 | if( $conf['graphreport_stats'] ) |
---|
| 376 | { |
---|
| 377 | $s_last = $def_nr - 1; |
---|
| 378 | |
---|
| 379 | foreach( $report_names as $r ) |
---|
| 380 | { |
---|
| 381 | $cdef_sum = "CDEF:bmem_${r}=bmem_${r}0_nonans"; |
---|
| 382 | |
---|
| 383 | if( $s_last > 1 ) |
---|
| 384 | { |
---|
| 385 | foreach (range(1, ($s_last)) as $print_nr ) |
---|
| 386 | { |
---|
| 387 | $user_sum .= ",bmem_${r}{$print_nr}_nonans,+"; |
---|
| 388 | } |
---|
| 389 | } |
---|
| 390 | $cdef_sum .= " "; |
---|
| 391 | |
---|
| 392 | $series .= $cdef_sum; |
---|
| 393 | } |
---|
| 394 | |
---|
| 395 | $r_count = 0; |
---|
| 396 | |
---|
| 397 | $conf['mem_buffer_color'] = $conf['mem_buffered_color']; |
---|
| 398 | $conf['mem_swap_color'] = $conf['mem_swapped_color']; |
---|
| 399 | $conf['mem_total_color'] = $conf['cpu_num_color']; |
---|
| 400 | |
---|
| 401 | foreach( $report_names as $r ) |
---|
| 402 | { |
---|
| 403 | $legend_str = ''; |
---|
| 404 | |
---|
| 405 | if( $r == "total" ) |
---|
| 406 | { |
---|
| 407 | $graph_str = "LINE2"; |
---|
| 408 | } |
---|
| 409 | else if( $r_count == 0 ) |
---|
| 410 | { |
---|
| 411 | $graph_str = "AREA"; |
---|
| 412 | } |
---|
| 413 | else |
---|
| 414 | { |
---|
| 415 | $graph_str = "STACK"; |
---|
| 416 | } |
---|
| 417 | foreach (range(0, ($s_last)) as $print_nr ) |
---|
| 418 | { |
---|
| 419 | if( $print_nr == 0 ) |
---|
| 420 | { |
---|
| 421 | $legend_str = ucfirst( $r ); |
---|
| 422 | } |
---|
| 423 | $series .= "${graph_str}:'bmem_${r}${print_nr}'#".$conf['mem_'.${r}.'_color'].":'${legend_str}\g' "; |
---|
| 424 | } |
---|
| 425 | |
---|
| 426 | $series .= "VDEF:'${r}_last'=bmem_${r},LAST "; |
---|
| 427 | $series .= "VDEF:'${r}_min'=bmem_${r},MINIMUM "; |
---|
| 428 | $series .= "VDEF:'${r}_avg'=bmem_${r},AVERAGE "; |
---|
| 429 | $series .= "VDEF:'${r}_max'=bmem_${r},MAXIMUM "; |
---|
| 430 | |
---|
| 431 | $spacefill = ''; |
---|
| 432 | |
---|
| 433 | $spacesize = 6-strlen($r); // max length 'swapped' = 7 |
---|
| 434 | foreach ( range( 0, $spacesize ) as $whatever ) |
---|
| 435 | { |
---|
| 436 | $spacefill .= ' '; |
---|
| 437 | } |
---|
| 438 | $series .= "GPRINT:'${r}_last':'${spacefill}Now\:%6.1lf%s' " |
---|
| 439 | . "GPRINT:'${r}_min':'${space1}Min\:%6.1lf%s${eol1}' " |
---|
| 440 | . "GPRINT:'${r}_avg':'${space2}Avg\:%6.1lf%s' " |
---|
| 441 | . "GPRINT:'${r}_max':'${space1}Max\:%6.1lf%s\\l' "; |
---|
| 442 | |
---|
| 443 | } |
---|
| 444 | } |
---|
| 445 | $r_count = $r_count + 1; |
---|
| 446 | |
---|
[717] | 447 | } |
---|
| 448 | else if ($graph == "load_report") |
---|
| 449 | { |
---|
| 450 | $style = "Load"; |
---|
[145] | 451 | |
---|
[717] | 452 | $lower_limit = "--lower-limit 0 --rigid"; |
---|
| 453 | $vertical_label = "--vertical-label 'Load/Procs'"; |
---|
[145] | 454 | |
---|
[717] | 455 | $def_nr = 0; |
---|
[145] | 456 | |
---|
[717] | 457 | foreach( $rrd_dirs as $rrd_dir ) |
---|
| 458 | { |
---|
[145] | 459 | |
---|
[717] | 460 | if( $def_nr == 0 ) |
---|
| 461 | { |
---|
[145] | 462 | |
---|
[717] | 463 | $load_str = ":'1-min Load'"; |
---|
| 464 | $cpu_str = ":'CPUs'"; |
---|
| 465 | $run_str = ":'Running Processes'"; |
---|
| 466 | } |
---|
| 467 | else |
---|
| 468 | { |
---|
| 469 | $load_str = ""; |
---|
| 470 | $cpu_str = ""; |
---|
| 471 | $run_str = ""; |
---|
| 472 | } |
---|
[145] | 473 | |
---|
[717] | 474 | $series .= "DEF:'load_one${def_nr}'='${rrd_dir}/load_one.rrd':'sum':AVERAGE " |
---|
| 475 | ."DEF:'proc_run${def_nr}'='${rrd_dir}/proc_run.rrd':'sum':AVERAGE " |
---|
| 476 | ."DEF:'cpu_num${def_nr}'='${rrd_dir}/cpu_num.rrd':'sum':AVERAGE "; |
---|
[731] | 477 | $series .="AREA:'load_one${def_nr}'#".$conf['load_one_color']."${load_str} "; |
---|
| 478 | $series .="LINE2:'cpu_num${def_nr}'#".$conf['cpu_num_color']."${cpu_str} "; |
---|
| 479 | $series .="LINE2:'proc_run${def_nr}'#".$conf['proc_run_color']."${run_str} "; |
---|
[145] | 480 | |
---|
[717] | 481 | $def_nr++; |
---|
| 482 | } |
---|
[145] | 483 | |
---|
[717] | 484 | } |
---|
| 485 | else if ($graph == "network_report") |
---|
| 486 | { |
---|
| 487 | $style = "Network"; |
---|
[145] | 488 | |
---|
[717] | 489 | $lower_limit = "--lower-limit 0 --rigid"; |
---|
[796] | 490 | $extras .= "--base 1024"; |
---|
[717] | 491 | $vertical_label = "--vertical-label 'Bytes/sec'"; |
---|
[145] | 492 | |
---|
[717] | 493 | $def_nr = 0; |
---|
[145] | 494 | |
---|
[717] | 495 | foreach( $rrd_dirs as $rrd_dir ) |
---|
| 496 | { |
---|
[145] | 497 | |
---|
[717] | 498 | if( $def_nr == 0 ) |
---|
| 499 | { |
---|
[145] | 500 | |
---|
[717] | 501 | $in_str = ":'In'"; |
---|
| 502 | $out_str = ":'Out'"; |
---|
| 503 | } |
---|
| 504 | else |
---|
| 505 | { |
---|
[145] | 506 | |
---|
[717] | 507 | $in_str = ""; |
---|
| 508 | $out_str = ""; |
---|
| 509 | } |
---|
[145] | 510 | |
---|
[717] | 511 | $series .= "DEF:'bytes_in${def_nr}'='${rrd_dir}/bytes_in.rrd':'sum':AVERAGE " |
---|
| 512 | ."DEF:'bytes_out${def_nr}'='${rrd_dir}/bytes_out.rrd':'sum':AVERAGE " |
---|
[731] | 513 | ."LINE2:'bytes_in${def_nr}'#".$conf['mem_cached_color']."${in_str} " |
---|
| 514 | ."LINE2:'bytes_out${def_nr}'#".$conf['mem_used_color']."${out_str} "; |
---|
[145] | 515 | |
---|
[717] | 516 | $def_nr++; |
---|
| 517 | } |
---|
[145] | 518 | |
---|
[717] | 519 | } |
---|
| 520 | else if ($graph == "packet_report") |
---|
| 521 | { |
---|
| 522 | $style = "Packets"; |
---|
[145] | 523 | |
---|
[717] | 524 | $lower_limit = "--lower-limit 0 --rigid"; |
---|
[796] | 525 | $extras .= "--base 1024"; |
---|
[717] | 526 | $vertical_label = "--vertical-label 'Packets/sec'"; |
---|
[145] | 527 | |
---|
[717] | 528 | $def_nr = 0; |
---|
[145] | 529 | |
---|
[717] | 530 | foreach( $rrd_dirs as $rrd_dir ) |
---|
| 531 | { |
---|
[145] | 532 | |
---|
[717] | 533 | if( $def_nr == 0 ) |
---|
| 534 | { |
---|
[145] | 535 | |
---|
[717] | 536 | $in_str = ":'In'"; |
---|
| 537 | $out_str = ":'Out'"; |
---|
| 538 | } |
---|
| 539 | else |
---|
| 540 | { |
---|
[145] | 541 | |
---|
[717] | 542 | $in_str = ""; |
---|
| 543 | $out_str = ""; |
---|
| 544 | } |
---|
[145] | 545 | |
---|
[717] | 546 | $series .= "DEF:'bytes_in${def_nr}'='${rrd_dir}/pkts_in.rrd':'sum':AVERAGE " |
---|
| 547 | ."DEF:'bytes_out${def_nr}'='${rrd_dir}/pkts_out.rrd':'sum':AVERAGE " |
---|
[731] | 548 | ."LINE2:'bytes_in${def_nr}'#".$conf['mem_cached_color']."${in_str} " |
---|
| 549 | ."LINE2:'bytes_out${def_nr}'#".$conf['mem_used_color']."${out_str} "; |
---|
[145] | 550 | |
---|
[717] | 551 | $def_nr++; |
---|
| 552 | } |
---|
[145] | 553 | |
---|
[717] | 554 | } |
---|
| 555 | else |
---|
| 556 | { |
---|
| 557 | /* Custom graph */ |
---|
| 558 | $style = ""; |
---|
[145] | 559 | |
---|
[717] | 560 | $subtitle = $metricname; |
---|
[736] | 561 | if($context == "host") |
---|
[717] | 562 | { |
---|
| 563 | if ($size == "small") |
---|
| 564 | $prefix = $metricname; |
---|
| 565 | else |
---|
| 566 | $prefix = $hostname; |
---|
[145] | 567 | |
---|
[717] | 568 | $value = $value>1000 ? number_format($value) : number_format($value, 2); |
---|
| 569 | } |
---|
[145] | 570 | |
---|
[717] | 571 | if (is_numeric($max)) |
---|
| 572 | $upper_limit = "--upper-limit '$max' "; |
---|
| 573 | if (is_numeric($min)) |
---|
| 574 | $lower_limit ="--lower-limit '$min' "; |
---|
[145] | 575 | |
---|
[717] | 576 | if ($vlabel) |
---|
| 577 | { |
---|
| 578 | $vertical_label = "--vertical-label '$vlabel'"; |
---|
| 579 | } |
---|
| 580 | else |
---|
| 581 | { |
---|
| 582 | if ($upper_limit or $lower_limit) |
---|
| 583 | { |
---|
| 584 | $max = $max>1000 ? number_format($max) : number_format($max, 2); |
---|
| 585 | $min = $min>0 ? number_format($min,2) : $min; |
---|
[145] | 586 | |
---|
[717] | 587 | $vertical_label ="--vertical-label '$min - $max' "; |
---|
| 588 | } |
---|
| 589 | } |
---|
[145] | 590 | |
---|
[717] | 591 | $def_nr = 0; |
---|
[145] | 592 | |
---|
[797] | 593 | |
---|
[717] | 594 | foreach( $rrd_dirs as $rrd_dir ) |
---|
| 595 | { |
---|
[145] | 596 | |
---|
[717] | 597 | if( $def_nr == 0 ) |
---|
| 598 | { |
---|
| 599 | $title_str = ":'${subtitle}'"; |
---|
| 600 | } |
---|
| 601 | else |
---|
| 602 | { |
---|
| 603 | $title_str = ""; |
---|
| 604 | } |
---|
[145] | 605 | |
---|
[717] | 606 | $rrd_file = "$rrd_dir/$metricname.rrd"; |
---|
| 607 | $series .= "DEF:'sum${def_nr}'='$rrd_file':'sum':AVERAGE " |
---|
[731] | 608 | ."AREA:'sum${def_nr}'#".$conf['default_metric_color']."${title_str} "; |
---|
[145] | 609 | |
---|
[797] | 610 | if( $conf['graphreport_stats'] ) |
---|
| 611 | { |
---|
| 612 | $series .= "CDEF:sum${def_nr}_nonans=sum${def_nr},UN,0,sum${def_nr},IF "; |
---|
| 613 | } |
---|
| 614 | |
---|
[717] | 615 | $def_nr++; |
---|
| 616 | } |
---|
[145] | 617 | |
---|
[797] | 618 | if( $conf['graphreport_stats'] ) |
---|
| 619 | { |
---|
| 620 | $s_last = $def_nr - 1; |
---|
| 621 | $series_sum = "CDEF:sum=sum0_nonans"; |
---|
| 622 | |
---|
| 623 | if( $def_nr > 1 ) |
---|
| 624 | { |
---|
| 625 | foreach (range(1, ($s_last)) as $print_nr ) |
---|
| 626 | { |
---|
| 627 | $series_sum .= ",sum{$print_nr}_nonans,+"; |
---|
| 628 | } |
---|
| 629 | } |
---|
| 630 | |
---|
| 631 | $series_sum .= " "; |
---|
| 632 | |
---|
| 633 | $series_last = "VDEF:'sum_last'=sum,LAST "; |
---|
| 634 | $series_minimum = "VDEF:'sum_min'=sum,MINIMUM "; |
---|
| 635 | $series_average = "VDEF:'sum_avg'=sum,AVERAGE "; |
---|
| 636 | $series_maximum = "VDEF:'sum_max'=sum,MAXIMUM "; |
---|
| 637 | |
---|
| 638 | $series .= $series_sum . $series_last . $series_minimum . $series_average . $series_maximum; |
---|
| 639 | |
---|
| 640 | $series .= "COMMENT:\"\\n\" "; |
---|
| 641 | $series .= "GPRINT:'sum_last':'${space1}Now\:%6.1lf%s' " |
---|
| 642 | . "GPRINT:'sum_min':'${space1}Min\:%6.1lf%s${eol1}' " |
---|
| 643 | . "GPRINT:'sum_avg':'${space2}Avg\:%6.1lf%s' " |
---|
| 644 | . "GPRINT:'sum_max':'${space1}Max\:%6.1lf%s\\l' "; |
---|
| 645 | } |
---|
[717] | 646 | } |
---|
[763] | 647 | } |
---|
| 648 | if( $series != '' ) |
---|
| 649 | { |
---|
| 650 | if ($job_start) |
---|
[717] | 651 | { |
---|
[795] | 652 | $series .= "VRULE:${job_start}#${jobstart_color}:'job start':dashes=4,2 "; |
---|
[717] | 653 | } |
---|
[763] | 654 | if ($job_stop) |
---|
| 655 | { |
---|
[795] | 656 | $series .= "VRULE:${job_stop}#${jobstop_color}:'job stop':dashes=4,2 "; |
---|
[763] | 657 | } |
---|
[145] | 658 | } |
---|
| 659 | |
---|
[759] | 660 | if($graph == "job_report") |
---|
[758] | 661 | { |
---|
[759] | 662 | if($range == 'job' ) |
---|
| 663 | { |
---|
| 664 | $title = "Last: $j_title"; |
---|
| 665 | } |
---|
| 666 | else |
---|
| 667 | { |
---|
| 668 | $title = "Last: $range"; |
---|
| 669 | } |
---|
[758] | 670 | } |
---|
| 671 | else |
---|
| 672 | { |
---|
| 673 | $title = "$hostname"; |
---|
| 674 | } |
---|
[145] | 675 | |
---|
[717] | 676 | function determineXGrid( $p_start, $p_stop ) |
---|
| 677 | { |
---|
[152] | 678 | |
---|
[717] | 679 | $period = intval( $p_stop - $p_start ); |
---|
[152] | 680 | |
---|
[717] | 681 | // Syntax: <minor_grid_lines_time_declr>:<major_grid_lines_time_declr>:<labels_time_declr>:<offset>:<format> |
---|
| 682 | // |
---|
| 683 | // Where each <*time_declr*> = <time_type>:<time_interval> |
---|
[152] | 684 | |
---|
[717] | 685 | //$my_lines1 = intval( $period / 3.0 ); |
---|
| 686 | //$my_lines2 = intval( $period / 6.0 ); |
---|
[159] | 687 | |
---|
[717] | 688 | //$my_grid = "SECOND:$my_lines2:SECOND:$my_lines1:SECOND:$my_lines1:0:%R"; |
---|
[159] | 689 | |
---|
[717] | 690 | //return "--x-grid $my_grid"; |
---|
[159] | 691 | |
---|
[717] | 692 | // Less than 1 minute |
---|
| 693 | if( $period < 60 ) |
---|
| 694 | { |
---|
[152] | 695 | |
---|
[717] | 696 | $tm_formt = "%X"; |
---|
| 697 | $my_grid = "SECOND:15:SECOND:30:SECOND:30:0:$tm_formt"; |
---|
[152] | 698 | |
---|
[717] | 699 | // Less than 10 minutes |
---|
| 700 | } |
---|
| 701 | else if( $period < 600 ) |
---|
| 702 | { |
---|
[152] | 703 | |
---|
[717] | 704 | $tm_formt = "%R"; |
---|
| 705 | $my_grid = "MINUTE:1:MINUTE:3:MINUTE:3:0:$tm_formt"; |
---|
[152] | 706 | |
---|
[717] | 707 | // Less than 1 hour |
---|
| 708 | } |
---|
| 709 | else if( $period < 3600 ) |
---|
| 710 | { |
---|
[152] | 711 | |
---|
[717] | 712 | $tm_formt = "%R"; |
---|
| 713 | $my_grid = "MINUTE:5:MINUTE:15:MINUTE:15:0:$tm_formt"; |
---|
[152] | 714 | |
---|
[717] | 715 | // Less than 15 hour |
---|
| 716 | } |
---|
| 717 | else if( $period < 3600 ) |
---|
| 718 | { |
---|
[159] | 719 | |
---|
[717] | 720 | $tm_formt = "%R"; |
---|
| 721 | $my_grid = "HOUR:1:HOUR:2:HOUR:2:0:$tm_formt"; |
---|
[159] | 722 | |
---|
[717] | 723 | // Less than 1 day |
---|
| 724 | // |
---|
| 725 | } |
---|
| 726 | else if( $period < 86400 ) |
---|
| 727 | { |
---|
[152] | 728 | |
---|
[717] | 729 | $tm_formt = "%R"; |
---|
| 730 | $my_grid = "HOUR:2:HOUR:5:HOUR:5:0:$tm_formt"; |
---|
[152] | 731 | |
---|
[717] | 732 | // Less than 15 days |
---|
| 733 | // |
---|
| 734 | } |
---|
| 735 | else if( $period < 1296000 ) |
---|
| 736 | { |
---|
[152] | 737 | |
---|
[717] | 738 | $tm_formt = "%e-%m"; |
---|
| 739 | $my_grid = "HOUR:1:DAY:3:DAY:3:0:'$tm_formt'"; |
---|
| 740 | |
---|
| 741 | // Less than 30 days (a month) |
---|
| 742 | // |
---|
| 743 | } |
---|
| 744 | else if( $period < 2592000 ) |
---|
| 745 | { |
---|
[152] | 746 | |
---|
[717] | 747 | $tm_formt = "%e-%m"; |
---|
| 748 | $my_grid = "DAY:5:DAY:10:DAY:10:0:'$tm_formt'"; |
---|
| 749 | } |
---|
[152] | 750 | |
---|
[717] | 751 | if( isset( $my_grid ) ) |
---|
| 752 | { |
---|
[152] | 753 | |
---|
[717] | 754 | $ret_str = "--x-grid $my_grid"; |
---|
| 755 | return array($ret_str,$tm_formt); |
---|
[152] | 756 | |
---|
[717] | 757 | } |
---|
| 758 | else |
---|
| 759 | { |
---|
| 760 | return array( "", "" ); |
---|
| 761 | } |
---|
[152] | 762 | } |
---|
| 763 | |
---|
[193] | 764 | $lower_limit = "--lower-limit 0"; |
---|
[159] | 765 | |
---|
[734] | 766 | if( !isset( $load_color ) or ( $load_color == '') ) |
---|
| 767 | { |
---|
| 768 | $load_color = 'FFFFFF'; |
---|
| 769 | } |
---|
| 770 | |
---|
[409] | 771 | # Calculate time range. |
---|
[733] | 772 | if ( isset($sourcetime) ) |
---|
[409] | 773 | { |
---|
[717] | 774 | $end = $sourcetime; |
---|
| 775 | # Get_context makes start negative. |
---|
| 776 | $start = $sourcetime + $start; |
---|
[409] | 777 | |
---|
[717] | 778 | # Fix from Phil Radden, but step is not always 15 anymore. |
---|
| 779 | if ($range=="month") |
---|
[733] | 780 | { |
---|
[717] | 781 | $end = floor($end / 672) * 672; |
---|
[733] | 782 | } |
---|
| 783 | $command = $conf['rrdtool']. " graph - --start $start --end $end ". |
---|
| 784 | "--width $width --height $height $lower_limit ". |
---|
| 785 | "--title '$title' $extras $background ". |
---|
| 786 | $series; |
---|
[409] | 787 | } |
---|
[733] | 788 | else |
---|
[717] | 789 | { |
---|
| 790 | $command = $conf['rrdtool'] . " graph - --start $period_start --end $period_stop ". |
---|
[733] | 791 | "--width $width --height $height $lower_limit --color BACK#$load_color ". |
---|
| 792 | "--title '$title' $extras $background ". |
---|
| 793 | $series; |
---|
[409] | 794 | } |
---|
| 795 | |
---|
[143] | 796 | $debug=0; |
---|
| 797 | |
---|
[733] | 798 | |
---|
[143] | 799 | # Did we generate a command? Run it. |
---|
[717] | 800 | if($command) |
---|
| 801 | { |
---|
| 802 | /*Make sure the image is not cached*/ |
---|
| 803 | header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past |
---|
| 804 | header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified |
---|
| 805 | header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 |
---|
| 806 | header ("Pragma: no-cache"); // HTTP/1.0 |
---|
| 807 | if ($debug) |
---|
| 808 | { |
---|
| 809 | header ("Content-type: text/html"); |
---|
| 810 | print "$command\n\n\n\n\n"; |
---|
| 811 | } |
---|
| 812 | else |
---|
| 813 | { |
---|
| 814 | header ("Content-type: image/gif"); |
---|
| 815 | passthru($command); |
---|
| 816 | } |
---|
[145] | 817 | } |
---|
[143] | 818 | ?> |
---|