- Timestamp:
- 06/17/05 17:14:55 (18 years ago)
- Location:
- trunk/web/addons/toga
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/web/addons/toga/graph.php
r143 r145 1 1 <?php 2 /* $Id: graph.php,v 1.8 2005/02/18 14:20:35 knobi1 Exp $ */ 3 include_once "./conf.php"; 4 include_once "./get_context.php"; 2 include_once "./libtoga.php"; 5 3 6 4 if ( !empty( $_GET ) ) { … … 20 18 $sourcetime = escapeshellcmd($HTTP_GET_VARS["st"]); 21 19 20 $cluster = $c; 21 $metricname = ($g) ? $g : $m; 22 $hostname = $h; 23 22 24 # Assumes we have a $start variable (set in get_context.php). 23 if ($size == "small") 24 { 25 $height = 40; 26 $width = 130; 27 } 28 else if ($size == "medium") 29 { 30 $height = 75; 31 $width = 300; 32 } 33 else 34 { 35 $height = 100; 36 $width = 400; 37 } 38 39 40 # This security fix was brought to my attention by Peter Vreugdenhil <petervre@sci.kun.nl> 41 # Dont want users specifying their own malicious command via GET variables e.g. 42 # http://ganglia.mrcluster.org/graph.php?graph=blob&command=whoami;cat%20/etc/passwd 43 # 44 if($command) 45 { 46 exit(); 47 } 48 49 switch ($context) 50 { 51 case "meta": 52 $rrd_dir = "$rrds/__SummaryInfo__"; 53 break; 54 case "grid": 55 $rrd_dir = "$rrds/$grid/__SummaryInfo__"; 56 break; 57 case "cluster": 58 $rrd_dir = "$rrds/$clustername/__SummaryInfo__"; 59 break; 60 case "host": 61 $rrd_dir = "$rrds/$clustername/$hostname"; 62 break; 63 default: 64 exit; 65 } 66 67 if ($graph) /* Canned graph request */ 68 { 69 if($graph == "cpu_report") 70 { 71 $style = "CPU"; 72 73 $upper_limit = "--upper-limit 100 --rigid"; 74 $lower_limit = "--lower-limit 0"; 75 76 $vertical_label = "--vertical-label Percent "; 77 78 if($context != "host" ) 79 { 80 /* If we are not in a host context, then we need to calculate the average */ 81 $series = 82 "DEF:'num_nodes'='${rrd_dir}/cpu_user.rrd':'num':AVERAGE " 83 ."DEF:'cpu_user'='${rrd_dir}/cpu_user.rrd':'sum':AVERAGE " 84 ."CDEF:'ccpu_user'=cpu_user,num_nodes,/ " 85 ."DEF:'cpu_nice'='${rrd_dir}/cpu_nice.rrd':'sum':AVERAGE " 86 ."CDEF:'ccpu_nice'=cpu_nice,num_nodes,/ " 87 ."DEF:'cpu_system'='${rrd_dir}/cpu_system.rrd':'sum':AVERAGE " 88 ."CDEF:'ccpu_system'=cpu_system,num_nodes,/ " 89 ."DEF:'cpu_idle'='${rrd_dir}/cpu_idle.rrd':'sum':AVERAGE " 90 ."CDEF:'ccpu_idle'=cpu_idle,num_nodes,/ " 91 ."AREA:'ccpu_user'#$cpu_user_color:'User CPU' " 92 ."STACK:'ccpu_nice'#$cpu_nice_color:'Nice CPU' " 93 ."STACK:'ccpu_system'#$cpu_system_color:'System CPU' "; 94 if (file_exists("$rrd_dir/cpu_wio.rrd")) { 95 $series .= "DEF:'cpu_wio'='${rrd_dir}/cpu_wio.rrd':'sum':AVERAGE " 96 ."CDEF:'ccpu_wio'=cpu_wio,num_nodes,/ " 97 ."STACK:'ccpu_wio'#$cpu_wio_color:'WAIT CPU' "; 98 } 99 $series .= "STACK:'ccpu_idle'#$cpu_idle_color:'Idle CPU' "; 100 } 101 else 102 { 103 $series ="DEF:'cpu_user'='${rrd_dir}/cpu_user.rrd':'sum':AVERAGE " 104 ."DEF:'cpu_nice'='${rrd_dir}/cpu_nice.rrd':'sum':AVERAGE " 105 ."DEF:'cpu_system'='${rrd_dir}/cpu_system.rrd':'sum':AVERAGE " 106 ."DEF:'cpu_idle'='${rrd_dir}/cpu_idle.rrd':'sum':AVERAGE " 107 ."AREA:'cpu_user'#$cpu_user_color:'User CPU' " 108 ."STACK:'cpu_nice'#$cpu_nice_color:'Nice CPU' " 109 ."STACK:'cpu_system'#$cpu_system_color:'System CPU' "; 110 if (file_exists("$rrd_dir/cpu_wio.rrd")) { 111 $series .= "DEF:'cpu_wio'='${rrd_dir}/cpu_wio.rrd':'sum':AVERAGE " 112 ."STACK:'cpu_wio'#$cpu_wio_color:'WAIT CPU' "; 113 } 114 $series .= "STACK:'cpu_idle'#$cpu_idle_color:'Idle CPU' "; 115 } 116 } 117 else if ($graph == "mem_report") 118 { 119 $style = "Memory"; 120 121 $lower_limit = "--lower-limit 0 --rigid"; 122 $extras = "--base 1024"; 123 $vertical_label = "--vertical-label Bytes"; 124 125 $series = "DEF:'mem_total'='${rrd_dir}/mem_total.rrd':'sum':AVERAGE " 126 ."CDEF:'bmem_total'=mem_total,1024,* " 127 ."DEF:'mem_shared'='${rrd_dir}/mem_shared.rrd':'sum':AVERAGE " 128 ."CDEF:'bmem_shared'=mem_shared,1024,* " 129 ."DEF:'mem_free'='${rrd_dir}/mem_free.rrd':'sum':AVERAGE " 130 ."CDEF:'bmem_free'=mem_free,1024,* " 131 ."DEF:'mem_cached'='${rrd_dir}/mem_cached.rrd':'sum':AVERAGE " 132 ."CDEF:'bmem_cached'=mem_cached,1024,* " 133 ."DEF:'mem_buffers'='${rrd_dir}/mem_buffers.rrd':'sum':AVERAGE " 134 ."CDEF:'bmem_buffers'=mem_buffers,1024,* " 135 ."CDEF:'bmem_used'='bmem_total','bmem_shared',-,'bmem_free',-,'bmem_cached',-,'bmem_buffers',- " 136 ."AREA:'bmem_used'#$mem_used_color:'Memory Used' " 137 ."STACK:'bmem_shared'#$mem_shared_color:'Memory Shared' " 138 ."STACK:'bmem_cached'#$mem_cached_color:'Memory Cached' " 139 ."STACK:'bmem_buffers'#$mem_buffered_color:'Memory Buffered' "; 140 if (file_exists("$rrd_dir/swap_total.rrd")) { 141 $series .= "DEF:'swap_total'='${rrd_dir}/swap_total.rrd':'sum':AVERAGE " 142 ."DEF:'swap_free'='${rrd_dir}/swap_free.rrd':'sum':AVERAGE " 143 ."CDEF:'bmem_swapped'='swap_total','swap_free',-,1024,* " 144 ."STACK:'bmem_swapped'#$mem_swapped_color:'Memory Swapped' "; 145 } 146 $series .= "LINE2:'bmem_total'#$cpu_num_color:'Total In-Core Memory' "; 147 } 148 else if ($graph == "load_report") 149 { 150 $style = "Load"; 151 152 $lower_limit = "--lower-limit 0 --rigid"; 153 $vertical_label = "--vertical-label 'Load/Procs'"; 154 155 $series = "DEF:'load_one'='${rrd_dir}/load_one.rrd':'sum':AVERAGE " 156 ."DEF:'proc_run'='${rrd_dir}/proc_run.rrd':'sum':AVERAGE " 157 ."DEF:'cpu_num'='${rrd_dir}/cpu_num.rrd':'sum':AVERAGE "; 158 if( $context != "host" ) 159 { 160 $series .="DEF:'num_nodes'='${rrd_dir}/cpu_num.rrd':'num':AVERAGE "; 161 } 162 $series .="AREA:'load_one'#$load_one_color:'1-min Load' "; 163 if( $context != "host" ) 164 { 165 $series .= "LINE2:'num_nodes'#$num_nodes_color:'Nodes' "; 166 } 167 $series .="LINE2:'cpu_num'#$cpu_num_color:'CPUs' "; 168 $series .="LINE2:'proc_run'#$proc_run_color:'Running Processes' "; 169 } 170 else if ($graph == "network_report") 171 { 172 $style = "Network"; 173 174 $lower_limit = "--lower-limit 0 --rigid"; 175 $extras = "--base 1024"; 176 $vertical_label = "--vertical-label 'Bytes/sec'"; 177 178 $series = "DEF:'bytes_in'='${rrd_dir}/bytes_in.rrd':'sum':AVERAGE " 179 ."DEF:'bytes_out'='${rrd_dir}/bytes_out.rrd':'sum':AVERAGE " 180 ."LINE2:'bytes_in'#$mem_cached_color:'In' " 181 ."LINE2:'bytes_out'#$mem_used_color:'Out' "; 182 } 183 else if ($graph == "packet_report") 184 { 185 $style = "Packets"; 186 187 $lower_limit = "--lower-limit 0 --rigid"; 188 $extras = "--base 1024"; 189 $vertical_label = "--vertical-label 'Packets/sec'"; 190 191 $series = "DEF:'bytes_in'='${rrd_dir}/pkts_in.rrd':'sum':AVERAGE " 192 ."DEF:'bytes_out'='${rrd_dir}/pkts_out.rrd':'sum':AVERAGE " 193 ."LINE2:'bytes_in'#$mem_cached_color:'In' " 194 ."LINE2:'bytes_out'#$mem_used_color:'Out' "; 195 } 196 else 197 { 198 /* Custom graph */ 199 $style = ""; 200 201 $subtitle = $metricname; 202 if ($context == "host") 203 { 204 if ($size == "small") 205 $prefix = $metricname; 206 else 207 $prefix = $hostname; 208 209 $value = $value>1000 ? number_format($value) : number_format($value, 2); 210 211 if ($range=="job") { 212 $hrs = intval( -$jobrange / 3600 ); 213 $subtitle = "$prefix last ${hrs}h (now $value)"; 214 } 215 else 216 $subtitle = "$prefix last $range (now $value)"; 217 } 218 219 if (is_numeric($max)) 220 $upper_limit = "--upper-limit '$max' "; 221 if (is_numeric($min)) 222 $lower_limit ="--lower-limit '$min' "; 223 224 if ($vlabel) 225 $vertical_label = "--vertical-label '$vlabel'"; 226 else if ($upper_limit or $lower_limit) 227 { 228 $max = $max>1000 ? number_format($max) : number_format($max, 2); 229 $min = $min>0 ? number_format($min,2) : $min; 230 231 $vertical_label ="--vertical-label '$min - $max' "; 232 } 233 234 $rrd_file = "$rrd_dir/$metricname.rrd"; 235 $series = "DEF:'sum'='$rrd_file':'sum':AVERAGE " 236 ."AREA:'sum'#$default_metric_color:'$subtitle' "; 237 if ($jobstart) 238 $series .= "VRULE:$jobstart#$jobstart_color "; 239 } 240 241 # Set the graph title. 242 if($context == "meta") 243 { 244 $title = "$self $meta_designator $style last $range"; 245 } 246 else if ($context == "grid") 247 { 248 $title = "$grid $meta_designator $style last $range"; 249 } 250 else if ($context == "cluster") 251 { 252 $title = "$clustername $style last $range"; 253 } 254 else 255 { 256 if ($size == "small") 257 { 258 # Value for this graph define a background color. 259 if (!$load_color) $load_color = "ffffff"; 260 $background = "--color BACK#'$load_color'"; 261 262 $title = $hostname; 263 } 264 else if ($style) 265 $title = "$hostname $style last $range"; 266 else 267 $title = $metricname; 268 } 269 270 # Fix from Phil Radden, but step is not always 15 anymore. 271 if ($range=="month") 272 $end = floor($end / 672) * 672; 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 } 35 36 if($command) { 37 $command = ''; 38 } 39 40 //printf( "cluster = %s hostname = %s metric = %s\n", $cluster, $hostname, $metricname ); 41 42 $trd = new TarchRrdGraph( $cluster, $hostname ); 43 //$rrd_files = $trd->getRrdFiles( $metricname, $start, $stop ); 44 45 //print_r( $rrd_files ); 46 47 $graph = $metricname; 48 49 if (isset($graph)) { 50 $rrd_dirs = $trd->getRrdDirs( $start, $stop ); 51 $series = ''; 52 53 if($graph == "cpu_report") { 54 $style = "CPU"; 55 //printf("ik doe die shit!\n"); 56 57 $upper_limit = "--upper-limit 100 --rigid"; 58 $lower_limit = "--lower-limit 0"; 59 60 $vertical_label = "--vertical-label Percent "; 61 62 $def_nr = 0; 63 64 foreach( $rrd_dirs as $rrd_dir ) { 65 66 if( $def_nr == 0 ) { 67 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 { 74 75 $user_str = ""; 76 $nice_str = ""; 77 $system_str = ""; 78 $wio_str = ""; 79 $idle_str = ""; 80 } 81 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} "; 89 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 } 94 95 $series .= "STACK:'cpu_idle${def_nr}'#${cpu_idle_color}${idle_str} "; 96 97 $def_nr++; 98 } 99 100 } else if ($graph == "mem_report") { 101 $style = "Memory"; 102 103 $lower_limit = "--lower-limit 0 --rigid"; 104 $extras = "--base 1024"; 105 $vertical_label = "--vertical-label Bytes"; 106 107 $def_nr = 0; 108 109 foreach( $rrd_dirs as $rrd_dir ) { 110 111 if( $def_nr == 0 ) { 112 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 { 120 121 $memuse_str = ""; 122 $memshared_str = ""; 123 $memcached_str = ""; 124 $membuff_str = ""; 125 $memswap_str = ""; 126 $total_str = ""; 127 } 128 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 //} 273 330 274 331 # 275 332 # Generate the rrdtool graph command. 276 333 # 277 $command = RRDTOOL . " graph - --start $start --end $ end".278 279 280 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; 281 338 282 339 $debug=0; 283 340 284 341 # Did we generate a command? Run it. 285 if($command) 286 { 287 /*Make sure the image is not cached*/ 288 header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past 289 header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified 290 header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 291 header ("Pragma: no-cache"); // HTTP/1.0 292 if ($debug) { 293 header ("Content-type: text/html"); 294 print "$command\n\n\n\n\n"; 295 } 296 else { 297 header ("Content-type: image/gif"); 298 passthru($command); 299 } 300 } 301 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 } 302 356 ?> 303 -
trunk/web/addons/toga/index.php
r144 r145 39 39 global $default_refresh, $filterorder, $view; 40 40 global $TARCHD; 41 41 42 42 if( isset($default_metric) and !isset($m) ) 43 43 $metricname = $default_metric; … … 146 146 foreach ($metrics[$firsthost] as $m => $foo) 147 147 $context_metrics[] = $m; 148 148 149 foreach ($reports as $r => $foo) 149 150 $context_metrics[] = $r; … … 319 320 320 321 makeFooter(); 321 322 322 $tpl->printToScreen(); 323 323 ?> -
trunk/web/addons/toga/libtoga.php
r143 r145 2 2 // If php is compiled without globals 3 3 // 4 if ( !empty( $_GET ) ) {5 extract( $_GET );6 }4 //if ( !empty( $_GET ) ) { 5 // extract( $_GET ); 6 //} 7 7 8 8 class HTTPVariables { … … 60 60 chdir( $GANGLIA_PATH ); 61 61 62 $context = 'cluster';63 64 62 include_once "./conf.php"; 65 63 include_once "./functions.php"; 66 64 include_once "./ganglia.php"; 67 //include_once "./get_context.php"; 65 include_once "./get_context.php"; 66 unset( $start ); 67 $context = 'cluster'; 68 68 include_once "./get_ganglia.php"; 69 69 … … 229 229 var $rrdbin, $rrdvalues, $clustername, $hostname, $tempdir, $tarchdir, $metrics; 230 230 231 function TarchRrd( $clustername, $rrdbin = '/usr/bin/rrdtool', $tarchdir = '/data/toga/rrds' ) { 231 function TarchRrdGraph( $clustername, $hostname, $rrdbin = '/usr/bin/rrdtool', $tarchdir = '/data/toga/rrds' ) { 232 232 233 $this->rrdbin = $rrdbin; 233 234 $this->rrdvalues = array(); 234 235 $this->tarchdir = $tarchdir; 236 $this->clustername = $clustername; 237 $this->hostname = $hostname; 235 238 } 236 239 … … 274 277 function getTimePeriods( $start, $end ) { 275 278 279 //printf("start = %s end = %s\n", $start, $end ); 276 280 $times = array(); 277 281 $dirlist = $this->dirList( $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname ); 282 283 //print_r( $dirlist ); 284 278 285 $first = 0; 279 286 $last = 9999999999999; … … 287 294 } 288 295 296 //printf( "first = %s last = %s\n", $first, $last ); 297 289 298 foreach( $dirlist as $dir ) { 290 299 291 if( $dir >= $first and $dir <= $last and !array_key_exists( $dir, $times ) ) 300 //printf( "dir %s ", $dir ); 301 302 if( $dir >= $first and $dir <= $last and !array_key_exists( $dir, $times ) ) { 303 292 304 $times[] = $dir; 293 } 305 //printf("newtime %s ", $dir ); 306 307 } 308 } 309 310 //print_r( $times ); 294 311 295 312 sort( $times ); 296 313 314 //print_r( $times ); 315 297 316 return $times; 317 } 318 319 function getRrdDirs( $start, $stop ) { 320 321 //printf( "tarchdir = %s\n", $this->tarchdir ); 322 $timess = $this->getTimePeriods( $start, $stop ); 323 //print_r( $timess ); 324 325 $rrd_files = array(); 326 327 foreach( $timess as $time ) { 328 329 $rrd_files[] = $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname. '/'.$time; 330 } 331 332 return $rrd_files; 333 } 334 335 function getRrdFiles( $metric, $start, $stop ) { 336 337 $times = $this->getTimePeriods( $start, $stop ); 338 339 $rrd_files = array(); 340 341 foreach( $times as $time ) { 342 343 $rrd_files[] = $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname . '/' .$time. '/' . $metric. '.rrd'; 344 } 345 346 return $rrd_files; 298 347 } 299 348 … … 309 358 310 359 //return $graph; 360 return 0; 311 361 } 312 362 } -
trunk/web/addons/toga/search.php
r143 r145 128 128 } 129 129 130 function epochToDatetime( $epoch ) { 131 132 return strftime( "%d-%m-%Y %H:%M:%S", $epoch ); 133 } 134 130 135 function timeToEpoch( $time ) { 131 136 … … 159 164 global $clustername, $tpl, $id, $user, $name, $start_from_time, $start_to_time, $queue; 160 165 global $end_from_time, $end_to_time, $filter, $default_showhosts, $m, $hosts_up; 166 global $start, $stop; 161 167 162 168 $metricname = $m; 169 //printf("job_start = %s job_stop = %s\n", $job_start, $job_stop ); 170 //printf("start = %s stop = %s\n", $start, $stop ); 163 171 164 172 $tpl->assign( "cluster", $clustername ); … … 197 205 198 206 $nodes_nr = count( $nodes ); 199 $domain = $job[domain]; 207 208 // need to replace later with domain stored from dbase 209 // 210 //$job_domain = $job[domain]; 211 212 $myhost = $_SERVER[HTTP_HOST]; 213 $myhf = explode( '.', $myhost ); 214 $myhf = array_reverse( $myhf ); 215 array_pop( $myhf ); 216 $myhf = array_reverse( $myhf ); 217 $job_domain = implode( '.', $myhf ); 218 219 //print_r( $job ); 220 //printf( "job domain = %s\n", $job_domain); 200 221 $ppn = (int) $job[ppn] ? $job[ppn] : 1; 201 222 $cpus = $nodes_nr * $ppn; … … 204 225 $tpl->assign( "cpus", $cpus ); 205 226 206 $runningtime = intval( $job[stop_timestamp] - $job[start_timestamp] ); 207 $tpl->assign( "started", makeDate( $job[start_timestamp] ) ); 208 $tpl->assign( "finished", makeDate( $job[stop_timestamp] ) ); 227 $job_start = $job[start_timestamp]; 228 $job_stop = $job[stop_timestamp]; 229 $runningtime = intval( $job_stop - $job_start ); 230 $tpl->assign( "started", makeDate( $job_start ) ); 231 $tpl->assign( "finished", makeDate( $job_stop ) ); 209 232 $tpl->assign( "runningtime", makeTime( $runningtime ) ); 210 233 … … 223 246 224 247 # Present a width list 225 $cols_menu = "<SELECT NAME=\"hc\" OnChange=\" toga_form.submit();\">\n";248 $cols_menu = "<SELECT NAME=\"hc\" OnChange=\"archive_search_form.submit();\">\n"; 226 249 227 250 $hostcols = ($hc) ? $hc : 4; … … 243 266 //bla 244 267 245 if( !isset($start) ) $start="jobstart"; 246 if( !isset($stop) ) $stop="now"; 247 //$tpl->assign("start", $start); 248 //$tpl->assign("stop", $stop); 268 //printf("job_start = %s job_stop = %s\n", $job_start, $job_stop ); 269 //printf("start = %s stop = %s\n", $start, $stop ); 270 271 if( !$start ) // Add an additional 5 minutes before 272 $start = intval( $job_start - 600 ); 273 else 274 $start = datetimeToEpoch( $start ); 275 276 if( !$stop ) // Add an additional 5 minutes after 277 $stop = intval( $job_stop + 600 ); 278 else 279 $stop = datetimeToEpoch( $stop ); 280 281 //printf("start = %s stop = %s\n", $start, $stop ); 282 283 $tpl->assign("j_start", epochToDatetime( $start ) ); 284 $tpl->assign("j_stop", epochToDatetime( $stop ) ); 285 286 $hosts_up = array(); 287 288 foreach( $nodes as $mynode ) 289 $hosts_up[] = $mynode[hostname]; 290 291 //print_r( $hosts_up ); 249 292 250 293 $sorted_hosts = array(); 251 $hosts_up = $jobs[$filter[id]][nodes]; 252 253 $r = intval($job_runningtime * 1.25); 254 255 $jobrange = ($job_runningtime < 3600) ? -3600 : -$r ; 256 $jobstart = $report_time - $job_runningtime; 257 258 if ($reports[$metricname]) 259 $metricval = "g"; 260 else 261 $metricval = "m"; 294 //$hosts_up = $jobs[$filter[id]][nodes]; 262 295 263 296 foreach ($hosts_up as $host ) { 264 $host = $host. '.'.$ domain;297 $host = $host. '.'.$job_domain; 265 298 $cpus = $metrics[$host]["cpu_num"][VAL]; 266 299 if (!$cpus) $cpus=1; … … 307 340 $val = $metrics[$host][$metricname]; 308 341 $class = "metric"; 309 $host_link="\"?c=$cluster_url&h=$host_url& r=job&jr=$jobrange&js=$jobstart\"";342 $host_link="\"?c=$cluster_url&h=$host_url&job_start=$job_start&job_stop=$job_stop&start=$start&stop=$stop\""; 310 343 311 344 if ($val[TYPE]=="timestamp" or $always_timestamp[$metricname]) { … … 314 347 $textval = "$val[VAL] $val[UNITS]"; 315 348 } else { 316 $load_color = load_color($host_load[$host]); 317 $graphargs = ($reports[$metricname]) ? "g=$metricname&" : "m=$metricname&"; 318 $graphargs .= "z=small&c=$cluster_url&h=$host_url&l=$load_color" ."&v=$val[VAL]&x=$max&n=$min&r=job&jr=$jobrange&js=$jobstart"; 349 $graphargs = "z=small&c=$cluster_url&m=$metricname&h=$host_url&v=$val[VAL]&x=$max&n=$min&job_start=$job_start&job_stop=$job_stop&start=$start&stop=$stop"; 319 350 } 320 351 if ($textval) { 321 352 $cell="<td class=$class>". "<b><a href=$host_link>$host</a></b><br>". "<i>$metricname:</i> <b>$textval</b></td>"; 322 353 } else { 323 $cell="<td><a href=$host_link>". "<img src=\". ./../graph.php?$graphargs\" ". "alt=\"$host\" height=112 width=225border=0></a></td>";354 $cell="<td><a href=$host_link>". "<img src=\"./graph.php?$graphargs\" ". "alt=\"$host\" border=0></a></td>"; 324 355 } 325 356 -
trunk/web/addons/toga/templates/search.tpl
r144 r145 60 60 <FORM NAME="archive_search_form" ACTION="./"> 61 61 62 <INPUT TYPE="hidden" NAME="c" VALUE="{cluster}">63 62 <INPUT TYPE="hidden" NAME="view" VALUE="search"> 64 63 … … 260 259 </FONT><BR> 261 260 <FONT SIZE="-1"> 262 <INPUT TYPE="HIDDEN" NAME="start" VALUE="{ start}">263 <INPUT TYPE="HIDDEN" NAME="stop" VALUE="{ stop}">264 Set graph timeperiod from265 <INPUT TYPE="text" NAME="period_start_pick" VALUE="{ start}" ALT="Start time" DISABLED="TRUE">261 <INPUT TYPE="HIDDEN" NAME="start" VALUE="{j_start}"> 262 <INPUT TYPE="HIDDEN" NAME="stop" VALUE="{j_stop}"> 263 Graph timeperiod from 264 <INPUT TYPE="text" NAME="period_start_pick" VALUE="{j_start}" ALT="Start time" DISABLED="TRUE"> 266 265 <a href="javascript:show_calendar('document.archive_search_form.period_start_pick', document.archive_search_form.period_start_pick.value);" alt="Click to select a date/time" title="Click to select a date/time"> 267 266 <img src="cal.gif" width="16" height="16" border="0"></a> 268 267 <a href="#" onClick="javascript: document.archive_search_form.period_start_pick.value=''" alt="Click here to clear field" title="Click here to clear field"> 269 268 <IMG SRC="redcross.jpg" BORDER=0></A> 270 to <INPUT TYPE="text" NAME="period_stop_pick" VALUE="{ stop}" ALT="Stop time" DISABLED="TRUE">269 to <INPUT TYPE="text" NAME="period_stop_pick" VALUE="{j_stop}" ALT="Stop time" DISABLED="TRUE"> 271 270 <a href="javascript:show_calendar('document.archive_search_form.period_stop_pick', document.archive_search_form.period_stop_pick.value);" alt="Click to select a date/time" title="Click to select a date/time"> 272 271 <img src="cal.gif" width="16" height="16" border="0"></a> 273 <a href="#" onClick="javascript: document.archive_search_form.period_ to_pick.value=''" alt="Click here to clear field" title="Click here to clear field">272 <a href="#" onClick="javascript: document.archive_search_form.period_stop_pick.value=''" alt="Click here to clear field" title="Click here to clear field"> 274 273 <IMG SRC="redcross.jpg" BORDER=0></A> 275 274 <INPUT TYPE="submit" onClick="setPeriodTimestamps();" VALUE="Refresh graphs"> … … 289 288 </TABLE> 290 289 291 <p>292 (Nodes colored by 1-minute load) | <A HREF="../../node_legend.html" ALT="Node Image egend">Legend</A>293 294 290 </CENTER> 295 291
Note: See TracChangeset
for help on using the changeset viewer.