# Dont want users specifying their own malicious command via GET variables e.g. # http://ganglia.mrcluster.org/graph.php?graph=blob&command=whoami;cat%20/etc/passwd # if($command) { exit(); } switch ($context) { case "meta": $rrd_dir = "$rrds/__SummaryInfo__"; break; case "grid": $rrd_dir = "$rrds/$grid/__SummaryInfo__"; break; case "cluster": $rrd_dir = "$rrds/$cluster/__SummaryInfo__"; break; case "host": $rrd_dir = "$rrds/$cluster/$host"; break; default: exit; } if ($graph) /* Canned graph request */ { if($graph == "cpu") { $style = "CPU"; $upper_limit = "--upper-limit 100 --rigid"; $lower_limit = "--lower-limit 0"; $vertical_label = "--vertical-label Percent "; if($context != "host" ) { /* If we are not in a host context, then we need to calculate the average */ $series = "DEF:'num_nodes'='${rrd_dir}/cpu_user.rrd':'num':AVERAGE " ."DEF:'cpu_user'='${rrd_dir}/cpu_user.rrd':'sum':AVERAGE " ."CDEF:'ccpu_user'=cpu_user,num_nodes,/ " ."DEF:'cpu_nice'='${rrd_dir}/cpu_nice.rrd':'sum':AVERAGE " ."CDEF:'ccpu_nice'=cpu_nice,num_nodes,/ " ."DEF:'cpu_system'='${rrd_dir}/cpu_system.rrd':'sum':AVERAGE " ."CDEF:'ccpu_system'=cpu_system,num_nodes,/ " ."DEF:'cpu_idle'='${rrd_dir}/cpu_idle.rrd':'sum':AVERAGE " ."CDEF:'ccpu_idle'=cpu_idle,num_nodes,/ " ."AREA:'ccpu_user'$cpu_user_color:'User CPU' " ."STACK:'ccpu_nice'$cpu_nice_color:'Nice CPU' " ."STACK:'ccpu_system'$cpu_system_color:'System CPU' " ."STACK:'ccpu_idle'$cpu_idle_color:'Idle CPU' "; } else { $series ="DEF:'cpu_user'='${rrd_dir}/cpu_user.rrd':'sum':AVERAGE " ."DEF:'cpu_nice'='${rrd_dir}/cpu_nice.rrd':'sum':AVERAGE " ."DEF:'cpu_system'='${rrd_dir}/cpu_system.rrd':'sum':AVERAGE " ."DEF:'cpu_idle'='${rrd_dir}/cpu_idle.rrd':'sum':AVERAGE " ."AREA:'cpu_user'$cpu_user_color:'User CPU' " ."STACK:'cpu_nice'$cpu_nice_color:'Nice CPU' " ."STACK:'cpu_system'$cpu_system_color:'System CPU' " ."STACK:'cpu_idle'$cpu_idle_color:'Idle CPU' "; } } else if ($graph == "mem") { $style = "MEM"; $lower_limit = "--lower-limit 0 --rigid"; $base = "--base 1024"; $vertical_label = "--vertical-label Bytes"; $series = "DEF:'mem_total'='${rrd_dir}/mem_total.rrd':'sum':AVERAGE " ."CDEF:'bmem_total'=mem_total,1024,* " ."DEF:'mem_shared'='${rrd_dir}/mem_shared.rrd':'sum':AVERAGE " ."CDEF:'bmem_shared'=mem_shared,1024,* " ."DEF:'mem_free'='${rrd_dir}/mem_free.rrd':'sum':AVERAGE " ."CDEF:'bmem_free'=mem_free,1024,* " ."DEF:'mem_cached'='${rrd_dir}/mem_cached.rrd':'sum':AVERAGE " ."CDEF:'bmem_cached'=mem_cached,1024,* " ."DEF:'mem_buffers'='${rrd_dir}/mem_buffers.rrd':'sum':AVERAGE " ."CDEF:'bmem_buffers'=mem_buffers,1024,* " ."CDEF:'bmem_used'='bmem_total','bmem_shared',-,'bmem_free',-,'bmem_cached',-,'bmem_buffers',- " ."AREA:'bmem_used'$mem_used_color:'Memory Used' " ."STACK:'bmem_shared'$mem_shared_color:'Memory Shared' " ."STACK:'bmem_cached'$mem_cached_color:'Memory Cached' " ."STACK:'bmem_buffers'$mem_buffered_color:'Memory Buffered' "; if (file_exists("$rrd_dir/swap_total.rrd")) { $series .= "DEF:'swap_total'='${rrd_dir}/swap_total.rrd':'sum':AVERAGE " ."DEF:'swap_free'='${rrd_dir}/swap_free.rrd':'sum':AVERAGE " ."CDEF:'bmem_swapped'='swap_total','swap_free',-,1024,* " ."STACK:'bmem_swapped'$mem_swapped_color:'Memory Swapped' "; } $series .= "LINE2:'bmem_total'$cpu_num_color:'Total In-Core Memory' "; } else if ($graph == "load") { $style = "LOAD"; $lower_limit = "--lower-limit 0 --rigid"; $vertical_label = "--vertical-label 'Processes'"; $series = "DEF:'load_one'='${rrd_dir}/load_one.rrd':'sum':AVERAGE " ."DEF:'proc_run'='${rrd_dir}/proc_run.rrd':'sum':AVERAGE " ."DEF:'cpu_num'='${rrd_dir}/cpu_num.rrd':'sum':AVERAGE "; if( $context != "host" ) { $series .="DEF:'num_nodes'='${rrd_dir}/cpu_num.rrd':'num':AVERAGE "; } $series .="AREA:'load_one'$load_one_color:'1-Minute Load' "; if( $context != "host" ) { $series .= "LINE2:'num_nodes'$num_nodes_color:'Nodes' "; } $series .="LINE2:'cpu_num'$cpu_num_color:'Total CPUs' "; $series .="LINE2:'proc_run'$proc_run_color:'Running Processes' "; } else { /* Got a strange value for $graph */ exit(); } } else { /* Custom graph */ $style = ""; $subtitle = $metric; if ($context == "host") { if ($size == "small") $prefix = $metric; else $prefix = $host; if ($range=="job") { $hrs = intval( -$jobrange / 3600 ); $subtitle = "$prefix last ${hrs}h (now $value)"; } else $subtitle = "$prefix last $range (now $value)"; } # # We need to be very careful here to protect against malicious # user input. All input needs to be escaped with '' quotes. # if(is_numeric($max)) { $upper_limit = "--upper-limit '$max' "; } if(is_numeric($min)) { $lower_limit ="--lower-limit '$min' "; } if ($vlabel) { $vertical_label = "--vertical-label '$vlabel'"; } else if ($max || $min) { $vertical_label ="--vertical-label '$min - $max' "; } $rrd_file = "$rrd_dir/$metric.rrd"; $series = "DEF:'sum'='$rrd_file':'sum':AVERAGE " ."AREA:'sum'$default_metric_color:'$subtitle' "; if ($jobstart) $series .= "VRULE:$jobstart#FF3300 "; } # # Generate the rrdtool graph command. # if($context == "meta") { $title = "$self $meta_designator $style last $range"; } else if ($context == "grid") { $title = "$grid $meta_designator $style last $range"; } else if ($context == "cluster") { $title = "$cluster $style last $range"; } else { if ($size == "small") $title = $host; else if ($style) $title = "$host $style last $range"; else $title = "$metric"; } $command = RRDTOOL . " graph - --start $start --end N ". "--width $width --height $height $upper_limit $lower_limit ". # --imgformat GIF|PNG # ."--imgformat PNG " "--title '$title' $vertical_label $base ". $series; $debug=0; # Did we generate a command? Run it. if($command) { /*Make sure the image is not cached*/ header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header ("Pragma: no-cache"); // HTTP/1.0 if ($debug) { header ("Content-type: text/html"); print "$command\n\n\n\n\n"; } else { header ("Content-type: image/gif"); passthru($command); } } ?>