Index: /trunk/web/addons/toga/graph.php =================================================================== --- /trunk/web/addons/toga/graph.php (revision 143) +++ /trunk/web/addons/toga/graph.php (revision 143) @@ -0,0 +1,303 @@ + +# 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/$clustername/__SummaryInfo__"; + break; + case "host": + $rrd_dir = "$rrds/$clustername/$hostname"; + break; + default: + exit; +} + +if ($graph) /* Canned graph request */ + { + if($graph == "cpu_report") + { + $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' "; + if (file_exists("$rrd_dir/cpu_wio.rrd")) { + $series .= "DEF:'cpu_wio'='${rrd_dir}/cpu_wio.rrd':'sum':AVERAGE " + ."CDEF:'ccpu_wio'=cpu_wio,num_nodes,/ " + ."STACK:'ccpu_wio'#$cpu_wio_color:'WAIT CPU' "; + } + $series .= "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' "; + if (file_exists("$rrd_dir/cpu_wio.rrd")) { + $series .= "DEF:'cpu_wio'='${rrd_dir}/cpu_wio.rrd':'sum':AVERAGE " + ."STACK:'cpu_wio'#$cpu_wio_color:'WAIT CPU' "; + } + $series .= "STACK:'cpu_idle'#$cpu_idle_color:'Idle CPU' "; + } + } + else if ($graph == "mem_report") + { + $style = "Memory"; + + $lower_limit = "--lower-limit 0 --rigid"; + $extras = "--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_report") + { + $style = "Load"; + + $lower_limit = "--lower-limit 0 --rigid"; + $vertical_label = "--vertical-label 'Load/Procs'"; + + $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-min Load' "; + if( $context != "host" ) + { + $series .= "LINE2:'num_nodes'#$num_nodes_color:'Nodes' "; + } + $series .="LINE2:'cpu_num'#$cpu_num_color:'CPUs' "; + $series .="LINE2:'proc_run'#$proc_run_color:'Running Processes' "; + } + else if ($graph == "network_report") + { + $style = "Network"; + + $lower_limit = "--lower-limit 0 --rigid"; + $extras = "--base 1024"; + $vertical_label = "--vertical-label 'Bytes/sec'"; + + $series = "DEF:'bytes_in'='${rrd_dir}/bytes_in.rrd':'sum':AVERAGE " + ."DEF:'bytes_out'='${rrd_dir}/bytes_out.rrd':'sum':AVERAGE " + ."LINE2:'bytes_in'#$mem_cached_color:'In' " + ."LINE2:'bytes_out'#$mem_used_color:'Out' "; + } + else if ($graph == "packet_report") + { + $style = "Packets"; + + $lower_limit = "--lower-limit 0 --rigid"; + $extras = "--base 1024"; + $vertical_label = "--vertical-label 'Packets/sec'"; + + $series = "DEF:'bytes_in'='${rrd_dir}/pkts_in.rrd':'sum':AVERAGE " + ."DEF:'bytes_out'='${rrd_dir}/pkts_out.rrd':'sum':AVERAGE " + ."LINE2:'bytes_in'#$mem_cached_color:'In' " + ."LINE2:'bytes_out'#$mem_used_color:'Out' "; + } + else + { + /* Custom graph */ + $style = ""; + + $subtitle = $metricname; + if ($context == "host") + { + if ($size == "small") + $prefix = $metricname; + else + $prefix = $hostname; + + $value = $value>1000 ? number_format($value) : number_format($value, 2); + + if ($range=="job") { + $hrs = intval( -$jobrange / 3600 ); + $subtitle = "$prefix last ${hrs}h (now $value)"; + } + else + $subtitle = "$prefix last $range (now $value)"; + } + + 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 ($upper_limit or $lower_limit) + { + $max = $max>1000 ? number_format($max) : number_format($max, 2); + $min = $min>0 ? number_format($min,2) : $min; + + $vertical_label ="--vertical-label '$min - $max' "; + } + + $rrd_file = "$rrd_dir/$metricname.rrd"; + $series = "DEF:'sum'='$rrd_file':'sum':AVERAGE " + ."AREA:'sum'#$default_metric_color:'$subtitle' "; + if ($jobstart) + $series .= "VRULE:$jobstart#$jobstart_color "; + } + +# Set the graph title. +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 = "$clustername $style last $range"; + } +else + { + if ($size == "small") + { + # Value for this graph define a background color. + if (!$load_color) $load_color = "ffffff"; + $background = "--color BACK#'$load_color'"; + + $title = $hostname; + } + else if ($style) + $title = "$hostname $style last $range"; + else + $title = $metricname; + } + +# Fix from Phil Radden, but step is not always 15 anymore. +if ($range=="month") + $end = floor($end / 672) * 672; + +# +# Generate the rrdtool graph command. +# +$command = RRDTOOL . " graph - --start $start --end $end ". + "--width $width --height $height $upper_limit $lower_limit ". + "--title '$title' $vertical_label $extras $background ". + $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); + } + } + +?> + Index: /trunk/web/addons/toga/index.php =================================================================== --- /trunk/web/addons/toga/index.php (revision 142) +++ /trunk/web/addons/toga/index.php (revision 143) @@ -187,4 +187,14 @@ } + if( $view == "search" ) { + $node_menu .= ">\n"; + $node_menu .= "Jobarchive "; + $tpl->assign("view", "search" ); + $tpl->assign("form_name", "archive_search_form" ); + } else { + $tpl->assign("form_name", "toga_form" ); + $tpl->assign("view", "overview" ); + } + $tpl->assign("node_menu", $node_menu); Index: /trunk/web/addons/toga/libtoga.php =================================================================== --- /trunk/web/addons/toga/libtoga.php (revision 142) +++ /trunk/web/addons/toga/libtoga.php (revision 143) @@ -216,5 +216,5 @@ $this->connect(); - printf( "query = [%s]\n", $query ); + //printf( "query = [%s]\n", $query ); $result = pg_query( $this->conn, $query ); Index: /trunk/web/addons/toga/search.php =================================================================== --- /trunk/web/addons/toga/search.php (revision 142) +++ /trunk/web/addons/toga/search.php (revision 143) @@ -118,7 +118,4 @@ $time_fields = explode( ':', $time ); - reset( $time_fields ); - - print_r( $time_fields ); $hours = $time_fields[0]; @@ -161,5 +158,7 @@ function makeSearchPage() { global $clustername, $tpl, $id, $user, $name, $start_from_time, $start_to_time, $queue; - global $end_from_time, $end_to_time, $filter; + global $end_from_time, $end_to_time, $filter, $default_showhosts, $m, $hosts_up; + + $metricname = $m; $tpl->assign( "cluster", $clustername ); @@ -210,17 +209,128 @@ $tpl->assign( "runningtime", makeTime( $runningtime ) ); - print_r( $job ); - print_r( $nodes ); - //output jobzooi - + //print_r( $job ); + //print_r( $nodes ); } + if( count( $search_ids ) == 1 ) { $tpl->newBlock( "showhosts" ); + + $showhosts = isset($sh) ? $sh : $default_showhosts; + //if( !$showhosts) $showhosts = $default_showhosts; + $tpl->assign("checked$showhosts", "checked"); + + # Present a width list + $cols_menu = "\n"; + + $hostcols = ($hc) ? $hc : 4; + + foreach(range(1,25) as $cols) { + $cols_menu .= "assign("metric","$metricname $units"); + $tpl->assign("id", $id); + # Host columns menu defined in header.php + $tpl->assign("cols_menu", $cols_menu); + + if( $showhosts ) { + //bla + + if( !isset($start) ) $start="jobstart"; + if( !isset($stop) ) $stop="now"; + //$tpl->assign("start", $start); + //$tpl->assign("stop", $stop); + + $sorted_hosts = array(); + $hosts_up = $jobs[$filter[id]][nodes]; + + $r = intval($job_runningtime * 1.25); + + $jobrange = ($job_runningtime < 3600) ? -3600 : -$r ; + $jobstart = $report_time - $job_runningtime; + + if ($reports[$metricname]) + $metricval = "g"; + else + $metricval = "m"; + + foreach ($hosts_up as $host ) { + $host = $host. '.'.$domain; + $cpus = $metrics[$host]["cpu_num"][VAL]; + if (!$cpus) $cpus=1; + $load_one = $metrics[$host]["load_one"][VAL]; + $load = ((float) $load_one)/$cpus; + $host_load[$host] = $load; + $percent_hosts[load_color($load)] += 1; + if ($metricname=="load_one") + $sorted_hosts[$host] = $load; + else + $sorted_hosts[$host] = $metrics[$host][$metricname][VAL]; + } + switch ($sort) { + case "descending": + arsort($sorted_hosts); + break; + case "by hostname": + ksort($sorted_hosts); + break; + default: + case "ascending": + asort($sorted_hosts); + break; + } + + //$sorted_hosts = array_merge($down_hosts, $sorted_hosts); + + # First pass to find the max value in all graphs for this + # metric. The $start,$end variables comes from get_context.php, + # included in index.php. + list($min, $max) = find_limits($sorted_hosts, $metricname); + + # Second pass to output the graphs or metrics. + $i = 1; + foreach ( $sorted_hosts as $host=>$value ) { + $tpl->newBlock ("sorted_list"); + //$host = $host. '.'.$domain; + $host_url = rawurlencode($host); + $cluster_url = rawurlencode($clustername); + + $textval = ""; + //printf("host = %s, value = %s", $host, $value); + //echo "$host: $value, "; + $val = $metrics[$host][$metricname]; + $class = "metric"; + $host_link="\"?c=$cluster_url&h=$host_url&r=job&jr=$jobrange&js=$jobstart\""; + + if ($val[TYPE]=="timestamp" or $always_timestamp[$metricname]) { + $textval = date("r", $val[VAL]); + } elseif ($val[TYPE]=="string" or $val[SLOPE]=="zero" or $always_constant[$metricname] or ($max_graphs > 0 and $i > $max_graphs )) { + $textval = "$val[VAL] $val[UNITS]"; + } else { + $load_color = load_color($host_load[$host]); + $graphargs = ($reports[$metricname]) ? "g=$metricname&" : "m=$metricname&"; + $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"; + } + if ($textval) { + $cell="". "$host". "$metricname: $textval"; + } else { + $cell="". ""; + } + + $tpl->assign("metric_image", $cell); + if (! ($i++ % $hostcols) ) + $tpl->assign ("br", ""); + } + + //einde bla + } } - // show search results - } } Index: /trunk/web/addons/toga/templates/header.tpl =================================================================== --- /trunk/web/addons/toga/templates/header.tpl (revision 142) +++ /trunk/web/addons/toga/templates/header.tpl (revision 143) @@ -9,5 +9,5 @@ - + Index: /trunk/web/addons/toga/templates/search.tpl =================================================================== --- /trunk/web/addons/toga/templates/search.tpl (revision 142) +++ /trunk/web/addons/toga/templates/search.tpl (revision 143) @@ -3,5 +3,42 @@ - +