[143] | 1 | <?php |
---|
[145] | 2 | include_once "./libtoga.php"; |
---|
[143] | 3 | |
---|
| 4 | if ( !empty( $_GET ) ) { |
---|
| 5 | extract( $_GET ); |
---|
| 6 | } |
---|
| 7 | |
---|
| 8 | # Graph specific variables |
---|
| 9 | $size = escapeshellcmd( rawurldecode( $HTTP_GET_VARS["z"] )); |
---|
| 10 | $graph = escapeshellcmd( rawurldecode( $HTTP_GET_VARS["g"] )); |
---|
| 11 | $grid = escapeshellcmd( rawurldecode( $HTTP_GET_VARS["G"] )); |
---|
| 12 | $self = escapeshellcmd( rawurldecode( $HTTP_GET_VARS["me"] )); |
---|
| 13 | $max = escapeshellcmd( rawurldecode( $HTTP_GET_VARS["x"] )); |
---|
| 14 | $min = escapeshellcmd( rawurldecode( $HTTP_GET_VARS["n"] )); |
---|
| 15 | $value = escapeshellcmd( rawurldecode( $HTTP_GET_VARS["v"] )); |
---|
| 16 | $load_color = escapeshellcmd( rawurldecode( $HTTP_GET_VARS["l"] )); |
---|
| 17 | $vlabel = escapeshellcmd( rawurldecode( $HTTP_GET_VARS["vl"] )); |
---|
| 18 | $sourcetime = escapeshellcmd($HTTP_GET_VARS["st"]); |
---|
| 19 | |
---|
[145] | 20 | $cluster = $c; |
---|
| 21 | $metricname = ($g) ? $g : $m; |
---|
| 22 | $hostname = $h; |
---|
| 23 | |
---|
[143] | 24 | # Assumes we have a $start variable (set in get_context.php). |
---|
[145] | 25 | if ($size == "small") { |
---|
| 26 | $height = 40; |
---|
| 27 | $width = 130; |
---|
| 28 | } else if ($size == "medium") { |
---|
| 29 | $height = 75; |
---|
| 30 | $width = 300; |
---|
| 31 | } else { |
---|
| 32 | $height = 100; |
---|
| 33 | $width = 400; |
---|
| 34 | } |
---|
[143] | 35 | |
---|
[145] | 36 | if($command) { |
---|
| 37 | $command = ''; |
---|
| 38 | } |
---|
[143] | 39 | |
---|
[145] | 40 | //printf( "cluster = %s hostname = %s metric = %s\n", $cluster, $hostname, $metricname ); |
---|
[143] | 41 | |
---|
[145] | 42 | $trd = new TarchRrdGraph( $cluster, $hostname ); |
---|
| 43 | //$rrd_files = $trd->getRrdFiles( $metricname, $start, $stop ); |
---|
[143] | 44 | |
---|
[145] | 45 | //print_r( $rrd_files ); |
---|
[143] | 46 | |
---|
[145] | 47 | $graph = $metricname; |
---|
[143] | 48 | |
---|
[145] | 49 | if (isset($graph)) { |
---|
| 50 | $rrd_dirs = $trd->getRrdDirs( $start, $stop ); |
---|
| 51 | $series = ''; |
---|
[143] | 52 | |
---|
[145] | 53 | if($graph == "cpu_report") { |
---|
| 54 | $style = "CPU"; |
---|
| 55 | //printf("ik doe die shit!\n"); |
---|
[143] | 56 | |
---|
[145] | 57 | $upper_limit = "--upper-limit 100 --rigid"; |
---|
| 58 | $lower_limit = "--lower-limit 0"; |
---|
[143] | 59 | |
---|
[145] | 60 | $vertical_label = "--vertical-label Percent "; |
---|
[143] | 61 | |
---|
[145] | 62 | $def_nr = 0; |
---|
[143] | 63 | |
---|
[145] | 64 | foreach( $rrd_dirs as $rrd_dir ) { |
---|
[143] | 65 | |
---|
[145] | 66 | if( $def_nr == 0 ) { |
---|
[143] | 67 | |
---|
[145] | 68 | $user_str = ":'User CPU'"; |
---|
| 69 | $nice_str = ":'Nice CPU'"; |
---|
| 70 | $system_str = ":'System CPU'"; |
---|
| 71 | $wio_str = ":'WAIT CPU'"; |
---|
| 72 | $idle_str = ":'Idle CPU'"; |
---|
| 73 | } else { |
---|
[143] | 74 | |
---|
[145] | 75 | $user_str = ""; |
---|
| 76 | $nice_str = ""; |
---|
| 77 | $system_str = ""; |
---|
| 78 | $wio_str = ""; |
---|
| 79 | $idle_str = ""; |
---|
| 80 | } |
---|
[143] | 81 | |
---|
[145] | 82 | $series .= "DEF:'cpu_user${def_nr}'='${rrd_dir}/cpu_user.rrd':'sum':AVERAGE " |
---|
| 83 | ."DEF:'cpu_nice${def_nr}'='${rrd_dir}/cpu_nice.rrd':'sum':AVERAGE " |
---|
| 84 | ."DEF:'cpu_system${def_nr}'='${rrd_dir}/cpu_system.rrd':'sum':AVERAGE " |
---|
| 85 | ."DEF:'cpu_idle${def_nr}'='${rrd_dir}/cpu_idle.rrd':'sum':AVERAGE " |
---|
| 86 | ."AREA:'cpu_user${def_nr}'#${cpu_user_color}${user_str} " |
---|
| 87 | ."STACK:'cpu_nice${def_nr}'#${cpu_nice_color}${nice_str} " |
---|
| 88 | ."STACK:'cpu_system${def_nr}'#${cpu_system_color}${system_str} "; |
---|
[143] | 89 | |
---|
[145] | 90 | if (file_exists("$rrd_dir/cpu_wio.rrd")) { |
---|
| 91 | $series .= "DEF:'cpu_wio${def_nr}'='${rrd_dir}/cpu_wio.rrd':'sum':AVERAGE " |
---|
| 92 | ."STACK:'cpu_wio${def_nr}'#${cpu_wio_color}${wio_str} "; |
---|
| 93 | } |
---|
[143] | 94 | |
---|
[145] | 95 | $series .= "STACK:'cpu_idle${def_nr}'#${cpu_idle_color}${idle_str} "; |
---|
[143] | 96 | |
---|
[145] | 97 | $def_nr++; |
---|
| 98 | } |
---|
[143] | 99 | |
---|
[145] | 100 | } else if ($graph == "mem_report") { |
---|
| 101 | $style = "Memory"; |
---|
[143] | 102 | |
---|
[145] | 103 | $lower_limit = "--lower-limit 0 --rigid"; |
---|
| 104 | $extras = "--base 1024"; |
---|
| 105 | $vertical_label = "--vertical-label Bytes"; |
---|
[143] | 106 | |
---|
[145] | 107 | $def_nr = 0; |
---|
[143] | 108 | |
---|
[145] | 109 | foreach( $rrd_dirs as $rrd_dir ) { |
---|
[143] | 110 | |
---|
[145] | 111 | if( $def_nr == 0 ) { |
---|
[143] | 112 | |
---|
[145] | 113 | $memuse_str = ":'Memory Used'"; |
---|
| 114 | $memshared_str = ":'Memory Shared'"; |
---|
| 115 | $memcached_str = ":'Memory Cached'"; |
---|
| 116 | $membuff_str = ":'Memory Buffered'"; |
---|
| 117 | $memswap_str = ":'Memory Swapped'"; |
---|
| 118 | $total_str = ":'Total In-Core Memory'"; |
---|
| 119 | } else { |
---|
[143] | 120 | |
---|
[145] | 121 | $memuse_str = ""; |
---|
| 122 | $memshared_str = ""; |
---|
| 123 | $memcached_str = ""; |
---|
| 124 | $membuff_str = ""; |
---|
| 125 | $memswap_str = ""; |
---|
| 126 | $total_str = ""; |
---|
| 127 | } |
---|
[143] | 128 | |
---|
[145] | 129 | $series .= "DEF:'mem_total${def_nr}'='${rrd_dir}/mem_total.rrd':'sum':AVERAGE " |
---|
| 130 | ."CDEF:'bmem_total${def_nr}'=mem_total${def_nr},1024,* " |
---|
| 131 | ."DEF:'mem_shared${def_nr}'='${rrd_dir}/mem_shared.rrd':'sum':AVERAGE " |
---|
| 132 | ."CDEF:'bmem_shared${def_nr}'=mem_shared${def_nr},1024,* " |
---|
| 133 | ."DEF:'mem_free${def_nr}'='${rrd_dir}/mem_free.rrd':'sum':AVERAGE " |
---|
| 134 | ."CDEF:'bmem_free${def_nr}'=mem_free${def_nr},1024,* " |
---|
| 135 | ."DEF:'mem_cached${def_nr}'='${rrd_dir}/mem_cached.rrd':'sum':AVERAGE " |
---|
| 136 | ."CDEF:'bmem_cached${def_nr}'=mem_cached${def_nr},1024,* " |
---|
| 137 | ."DEF:'mem_buffers${def_nr}'='${rrd_dir}/mem_buffers.rrd':'sum':AVERAGE " |
---|
| 138 | ."CDEF:'bmem_buffers${def_nr}'=mem_buffers${def_nr},1024,* " |
---|
| 139 | ."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}',- " |
---|
| 140 | ."AREA:'bmem_used${def_nr}'#${mem_used_color}${memuse_str} " |
---|
| 141 | ."STACK:'bmem_shared${def_nr}'#${mem_shared_color}${memshared_str} " |
---|
| 142 | ."STACK:'bmem_cached${def_nr}'#${mem_cached_color}${memcached_str} " |
---|
| 143 | ."STACK:'bmem_buffers${def_nr}'#${mem_buffered_color}${membuff_str} "; |
---|
| 144 | |
---|
| 145 | if (file_exists("$rrd_dir/swap_total.rrd")) { |
---|
| 146 | $series .= "DEF:'swap_total${def_nr}'='${rrd_dir}/swap_total.rrd':'sum':AVERAGE " |
---|
| 147 | ."DEF:'swap_free${def_nr}'='${rrd_dir}/swap_free.rrd':'sum':AVERAGE " |
---|
| 148 | ."CDEF:'bmem_swapped${def_nr}'='swap_total${def_nr}','swap_free${def_nr}',-,1024,* " |
---|
| 149 | ."STACK:'bmem_swapped${def_nr}'#${mem_swapped_color}${memswap_str} "; |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | $series .= "LINE2:'bmem_total${def_nr}'#${cpu_num_color}${total_str} "; |
---|
| 153 | |
---|
| 154 | $def_nr++; |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | } else if ($graph == "load_report") { |
---|
| 158 | $style = "Load"; |
---|
| 159 | |
---|
| 160 | $lower_limit = "--lower-limit 0 --rigid"; |
---|
| 161 | $vertical_label = "--vertical-label 'Load/Procs'"; |
---|
| 162 | |
---|
| 163 | $def_nr = 0; |
---|
| 164 | |
---|
| 165 | foreach( $rrd_dirs as $rrd_dir ) { |
---|
| 166 | |
---|
| 167 | if( $def_nr == 0 ) { |
---|
| 168 | |
---|
| 169 | $load_str = ":'1-min Load'"; |
---|
| 170 | $cpu_str = ":'CPUs'"; |
---|
| 171 | $run_str = ":'Running Processes'"; |
---|
| 172 | } else { |
---|
| 173 | |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | $series .= "DEF:'load_one${def_nr}'='${rrd_dir}/load_one.rrd':'sum':AVERAGE " |
---|
| 177 | ."DEF:'proc_run${def_nr}'='${rrd_dir}/proc_run.rrd':'sum':AVERAGE " |
---|
| 178 | ."DEF:'cpu_num${def_nr}'='${rrd_dir}/cpu_num.rrd':'sum':AVERAGE "; |
---|
| 179 | $series .="AREA:'load_one${def_nr}'#${load_one_color}${load_str} "; |
---|
| 180 | $series .="LINE2:'cpu_num${def_nr}'#${cpu_num_color}${cpu_str} "; |
---|
| 181 | $series .="LINE2:'proc_run${def_nr}'#${proc_run_color}${run_str} "; |
---|
| 182 | |
---|
| 183 | $def_nr++; |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | } else if ($graph == "network_report") { |
---|
| 187 | $style = "Network"; |
---|
| 188 | |
---|
| 189 | $lower_limit = "--lower-limit 0 --rigid"; |
---|
| 190 | $extras = "--base 1024"; |
---|
| 191 | $vertical_label = "--vertical-label 'Bytes/sec'"; |
---|
| 192 | |
---|
| 193 | $def_nr = 0; |
---|
| 194 | |
---|
| 195 | foreach( $rrd_dirs as $rrd_dir ) { |
---|
| 196 | |
---|
| 197 | if( $def_nr == 0 ) { |
---|
| 198 | |
---|
| 199 | $in_str = ":'In'"; |
---|
| 200 | $out_str = ":'Out'"; |
---|
| 201 | } else { |
---|
| 202 | |
---|
| 203 | $in_str = ""; |
---|
| 204 | $out_str = ""; |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | $series .= "DEF:'bytes_in${def_nr}'='${rrd_dir}/bytes_in.rrd':'sum':AVERAGE " |
---|
| 208 | ."DEF:'bytes_out${def_nr}'='${rrd_dir}/bytes_out.rrd':'sum':AVERAGE " |
---|
| 209 | ."LINE2:'bytes_in${def_nr}'#${mem_cached_color}${in_str} " |
---|
| 210 | ."LINE2:'bytes_out${def_nr}'#${mem_used_color}${out_str} "; |
---|
| 211 | |
---|
| 212 | $def_nr++; |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | } else if ($graph == "packet_report") { |
---|
| 216 | $style = "Packets"; |
---|
| 217 | |
---|
| 218 | $lower_limit = "--lower-limit 0 --rigid"; |
---|
| 219 | $extras = "--base 1024"; |
---|
| 220 | $vertical_label = "--vertical-label 'Packets/sec'"; |
---|
| 221 | |
---|
| 222 | $def_nr = 0; |
---|
| 223 | |
---|
| 224 | foreach( $rrd_dirs as $rrd_dir ) { |
---|
| 225 | |
---|
| 226 | if( $def_nr == 0 ) { |
---|
| 227 | |
---|
| 228 | $in_str = ":'In'"; |
---|
| 229 | $out_str = ":'Out'"; |
---|
| 230 | } else { |
---|
| 231 | |
---|
| 232 | $in_str = ""; |
---|
| 233 | $out_str = ""; |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | $series .= "DEF:'bytes_in${def_nr}'='${rrd_dir}/pkts_in.rrd':'sum':AVERAGE " |
---|
| 237 | ."DEF:'bytes_out${def_nr}'='${rrd_dir}/pkts_out.rrd':'sum':AVERAGE " |
---|
| 238 | ."LINE2:'bytes_in${def_nr}'#${mem_cached_color}${in_str} " |
---|
| 239 | ."LINE2:'bytes_out${def_nr}'#${mem_used_color}${out_str} "; |
---|
| 240 | |
---|
| 241 | $def_nr++; |
---|
| 242 | } |
---|
| 243 | |
---|
| 244 | } else { |
---|
| 245 | /* Custom graph */ |
---|
| 246 | $style = ""; |
---|
| 247 | |
---|
| 248 | $subtitle = $metricname; |
---|
| 249 | if ($context == "host") { |
---|
| 250 | if ($size == "small") |
---|
| 251 | $prefix = $metricname; |
---|
| 252 | else |
---|
| 253 | $prefix = $hostname; |
---|
| 254 | |
---|
| 255 | $value = $value>1000 ? number_format($value) : number_format($value, 2); |
---|
| 256 | } |
---|
| 257 | |
---|
| 258 | //if ($range=="job") { |
---|
| 259 | // $hrs = intval( -$jobrange / 3600 ); |
---|
| 260 | // $subtitle = "$prefix last ${hrs}h (now $value)"; |
---|
| 261 | //} else |
---|
| 262 | // $subtitle = "$prefix last $range (now $value)"; |
---|
| 263 | |
---|
| 264 | if (is_numeric($max)) |
---|
| 265 | $upper_limit = "--upper-limit '$max' "; |
---|
| 266 | if (is_numeric($min)) |
---|
| 267 | $lower_limit ="--lower-limit '$min' "; |
---|
| 268 | |
---|
| 269 | if ($vlabel) |
---|
| 270 | $vertical_label = "--vertical-label '$vlabel'"; |
---|
| 271 | else { |
---|
| 272 | if ($upper_limit or $lower_limit) { |
---|
| 273 | $max = $max>1000 ? number_format($max) : number_format($max, 2); |
---|
| 274 | $min = $min>0 ? number_format($min,2) : $min; |
---|
| 275 | |
---|
| 276 | $vertical_label ="--vertical-label '$min - $max' "; |
---|
| 277 | } |
---|
| 278 | } |
---|
| 279 | |
---|
| 280 | $def_nr = 0; |
---|
| 281 | |
---|
| 282 | foreach( $rrd_dirs as $rrd_dir ) { |
---|
| 283 | |
---|
| 284 | if( $def_nr == 0 ) { |
---|
| 285 | $title_str = ":'${subtitle}'"; |
---|
| 286 | } else { |
---|
| 287 | $title_str = ""; |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | $rrd_file = "$rrd_dir/$metricname.rrd"; |
---|
| 291 | $series .= "DEF:'sum${def_nr}'='$rrd_file':'sum':AVERAGE " |
---|
| 292 | ."AREA:'sum${def_nr}'#${default_metric_color}${title_str} "; |
---|
| 293 | |
---|
| 294 | $def_nr++; |
---|
| 295 | } |
---|
| 296 | |
---|
| 297 | } |
---|
| 298 | if( $series != '' ) { |
---|
| 299 | if ($job_start) |
---|
| 300 | $series .= "VRULE:${job_start}#${jobstart_color} "; |
---|
| 301 | if ($job_stop) |
---|
| 302 | $series .= "VRULE:${job_stop}#${jobstart_color} "; |
---|
| 303 | } |
---|
| 304 | } |
---|
| 305 | |
---|
| 306 | //$title = "$hostname $style $metricname"; |
---|
| 307 | $title = "$hostname"; |
---|
| 308 | |
---|
| 309 | //# Set the graph title. |
---|
| 310 | //if($context == "meta") { |
---|
| 311 | // $title = "$self $meta_designator $style last $range"; |
---|
| 312 | //} else if ($context == "grid") { |
---|
| 313 | // $title = "$grid $meta_designator $style last $range"; |
---|
| 314 | //} else if ($context == "cluster") { |
---|
| 315 | // $title = "$clustername $style last $range"; |
---|
| 316 | //} else { |
---|
| 317 | // if ($size == "small") { |
---|
| 318 | // # Value for this graph define a background color. |
---|
| 319 | // if (!$load_color) $load_color = "ffffff"; |
---|
| 320 | // $background = "--color BACK#'$load_color'"; |
---|
| 321 | |
---|
| 322 | // $title = $hostname; |
---|
| 323 | // } else { |
---|
| 324 | // if ($style) |
---|
| 325 | // $title = "$hostname $style last $range"; |
---|
| 326 | // else |
---|
| 327 | // $title = $metricname; |
---|
| 328 | // } |
---|
| 329 | //} |
---|
| 330 | |
---|
[143] | 331 | # |
---|
| 332 | # Generate the rrdtool graph command. |
---|
| 333 | # |
---|
[145] | 334 | $command = RRDTOOL . " graph - --start $start --end $stop ". |
---|
| 335 | "--width $width --height $height $upper_limit $lower_limit ". |
---|
| 336 | "--title '$title' $vertical_label $extras $background ". |
---|
| 337 | $series; |
---|
[143] | 338 | |
---|
| 339 | $debug=0; |
---|
| 340 | |
---|
| 341 | # Did we generate a command? Run it. |
---|
[145] | 342 | if($command) { |
---|
| 343 | /*Make sure the image is not cached*/ |
---|
| 344 | header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past |
---|
| 345 | header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified |
---|
| 346 | header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 |
---|
| 347 | header ("Pragma: no-cache"); // HTTP/1.0 |
---|
| 348 | if ($debug) { |
---|
| 349 | header ("Content-type: text/html"); |
---|
| 350 | print "$command\n\n\n\n\n"; |
---|
| 351 | } else { |
---|
| 352 | header ("Content-type: image/gif"); |
---|
| 353 | passthru($command); |
---|
| 354 | } |
---|
| 355 | } |
---|
[143] | 356 | ?> |
---|