Index: /trunk/web/addons/toga/index.php
===================================================================
--- /trunk/web/addons/toga/index.php	(revision 125)
+++ /trunk/web/addons/toga/index.php	(revision 126)
@@ -36,5 +36,16 @@
 	global $parentgrid, $physical, $hostname;
 	global $self, $filter, $cluster_url, $get_metric_string;
-
+	global $metrics, $reports, $m, $default_metric;
+
+	if( isset($default_metric) and !isset($m) )
+		$metricname = $default_metric;
+	else
+		if( isset( $m ) )
+			$metricname = $m;
+		else
+			$metricname = "load_one";
+
+	//$metricname = ($m) ? $m : $default_metric;
+	//printf( "m = %s, metricname = %s, default_metric = %s\n", $m, $metricname, $default_metric );
 	if ( $context == "control" && $controlroom < 0 )
 		$header = "header-nobanner";
@@ -134,4 +145,14 @@
 	}
 
+	if (!count($metrics)) {
+		echo "<h4>Cannot find any metrics for selected cluster \"$clustername\", exiting.</h4>\n";       echo "Check ganglia XML tree (telnet $ganglia_ip $ganglia_port)\n";
+		exit;
+	}
+	$firsthost = key($metrics);
+	foreach ($metrics[$firsthost] as $m => $foo)
+		$context_metrics[] = $m;
+	foreach ($reports as $r => $foo)
+		$context_metrics[] = $r;
+
 	$node_menu .= "<B><A HREF=\"./?c=".rawurlencode($clustername)."\">Joblist</A></B> ";
 
@@ -141,9 +162,52 @@
 
 			$node_menu .= "<B>&gt;</B>\n";
-			$node_menu .= "<B>'$filtername': $filterval</B> ";
+			$node_menu .= "<B>$filtername- $filterval</B> ";
 		}
 	}
 
 	$tpl->assign("node_menu", $node_menu);
+
+	if( array_key_exists( "id", $filter ) ) {
+		//$context_ranges[]="hour";
+		//$context_ranges[]="day";
+		//$context_ranges[]="week";
+		//$context_ranges[]="month";
+		//$context_ranges[]="year";
+		//if ($jobrange)
+		//	$context_ranges[]="job";
+
+		//$range_menu = "<B>Last</B>&nbsp;&nbsp;"
+		//	."<SELECT NAME=\"r\" OnChange=\"toga_form.submit();\">\n";
+		//foreach ($context_ranges as $v) {
+		//	$url=rawurlencode($v);
+	//		$range_menu .= "<OPTION VALUE=\"$url\" ";
+	//		if ($v == $range)
+	//			 $range_menu .= "SELECTED";
+	//		$range_menu .= ">$v\n";
+	//	}
+	//	$range_menu .= "</SELECT>\n";
+
+	//	$tpl->assign("range_menu", $range_menu);
+
+		//$metricname = $m;
+
+		if (is_array($context_metrics) ) {
+			$metric_menu = "<B>Metric</B>&nbsp;&nbsp;"
+				."<SELECT NAME=\"m\" OnChange=\"toga_form.submit();\">\n";
+
+			sort($context_metrics);
+			foreach( $context_metrics as $k ) {
+				$url = rawurlencode($k);
+				$metric_menu .= "<OPTION VALUE=\"$url\" ";
+				if ($k == $metricname )
+					$metric_menu .= "SELECTED";
+				$metric_menu .= ">$k\n";
+			}
+			$metric_menu .= "</SELECT>\n";
+
+			$tpl->assign("metric_menu", $metric_menu );
+		}
+	}
+	$m = $metricname;
 
 	# Make sure that no data is cached..
@@ -200,8 +264,8 @@
 		break;
 
-	case "jobview":
-
-		includeJobview();
-		break;
+	//case "jobview":
+
+	//	includeJobview();
+	//	break;
 
 	default:
@@ -225,8 +289,8 @@
 		break;
 
-	case "jobview":
-
-		makeJobview();
-		break;
+	//case "jobview":
+
+	//	makeJobview();
+	//	break;
 
 	default:
Index: /trunk/web/addons/toga/libtoga.php
===================================================================
--- /trunk/web/addons/toga/libtoga.php	(revision 125)
+++ /trunk/web/addons/toga/libtoga.php	(revision 126)
@@ -75,11 +75,14 @@
 // provide us with the correct metrics array
 //
-global $context, $clustername;
+global $context, $clustername, $reports;
 //$clustername = $httpvars->getClusterName();
 //$context = 'cluster';
 
+
+global $default_metric;
+
 // Ganglia's array of host metrics
 //
-global $metrics;
+global $metrics, $hosts_up;
 
 
Index: /trunk/web/addons/toga/overview.php
===================================================================
--- /trunk/web/addons/toga/overview.php	(revision 125)
+++ /trunk/web/addons/toga/overview.php	(revision 126)
@@ -1,4 +1,5 @@
 <?php
-global $GANGLIA_PATH, $clustername, $tpl, $filter, $cluster, $get_metric_string, $cluster_url;
+global $GANGLIA_PATH, $clustername, $tpl, $filter, $cluster, $get_metric_string, $cluster_url, $sh;
+global $hosts_up, $m, $start, $end;
 
 $data_gatherer = new DataGatherer();
@@ -11,5 +12,5 @@
 $heartbeat = $data_gatherer->getHeartbeat();
 $jobs = $data_gatherer->getJobs();
-$nodes = $data_gatherer->getNodes();
+$gnodes = $data_gatherer->getNodes();
 $cpus = $data_gatherer->getCpus();
 
@@ -23,6 +24,13 @@
 $tpl->assign( "clusterimage", "./image.php?c=".rawurlencode($clustername)."&view=big-clusterimage".$filter_image_url );
 
-
-$pie = drawClusterPie();
+if( array_key_exists( "id", $filter ) )
+	$pie = drawJobPie();
+else if( array_key_exists( "user", $filter ) )
+	$pie = drawUserPie();
+else if( array_key_exists( "queue", $filter ) )
+	$pie = drawQueuePie();
+else
+	$pie = drawClusterPie();
+
 $tpl->assign("pie", $pie );
 
@@ -170,10 +178,22 @@
 }
 
+function drawJobPie() {
+}
+
+function drawUserPie() {
+
+}
+
+function drawQueuePie() {
+
+}
 
 
 function drawClusterPie() {
 
-	global $jobs, $nodes;
-
+	global $jobs, $gnodes;
+
+	$nodes = $gnodes;
+	
 	$pie_args = "title=" . rawurlencode("Cluster queue usage");
 	$pie_args .= "&size=250x150";
@@ -326,5 +346,9 @@
 
 	global $jobs, $nodes, $heartbeat, $clustername, $tpl;
-	global $sortorder, $sortby, $filter;
+	global $sortorder, $sortby, $filter, $sh, $hc, $m;
+	global $cluster_url, $get_metric_string, $host_url, $metrics;
+	global $start, $end, $reports;
+
+	$metricname = $m;
 
 	$tpl->assign("sortorder", $sortorder );
@@ -336,5 +360,5 @@
 
 	$overview_jobs = count( $sorted_jobs );
-	$overview_nodes = count( $nodes );
+	$overview_nodes = count( $gnodes );
 	$overview_cpus = 0;
 
@@ -378,4 +402,5 @@
 				$tpl->assign("queue", $jobs[$jobid][queue] );
 				$tpl->assign("name", $jobs[$jobid][name] );
+				$domain = $jobs[$jobid][domain];
 				$tpl->assign("req_cpu", makeTime( timeToEpoch( $jobs[$jobid][requested_time] ) ) );
 				$tpl->assign("req_memory", $jobs[$jobid][requested_memory] );
@@ -386,4 +411,5 @@
 				$tpl->assign("cpus", $cpus );
 				$start_time = (int) $jobs[$jobid][start_timestamp];
+				$job_start = $start_time;
 
 				$f_cpus = $f_cpus + $cpus;
@@ -403,4 +429,5 @@
 
 					$runningtime = makeTime( $report_time - $start_time );
+					$job_runningtime = $report_time - $start_time;
 					$tpl->assign("started", makeDate( $start_time ) );
 					$tpl->assign("runningtime", $runningtime );
@@ -417,4 +444,122 @@
 	$tpl->assignGlobal("f_cpus_nr", $f_cpus );
 	$tpl->assignGlobal("f_jobs_nr", $f_jobs );
+
+	if( array_key_exists( "id", $filter ) ) {
+		$tpl->newBlock( "showhosts" );
+
+		# Present a width list
+		$cols_menu = "<SELECT NAME=\"hc\" OnChange=\"toga_form.submit();\">\n";
+
+		$hostcols = ($hc) ? $hc : 4;
+
+		foreach(range(1,25) as $cols) {
+			$cols_menu .= "<OPTION VALUE=$cols ";
+			if ($cols == $hostcols)
+				$cols_menu .= "SELECTED";
+			$cols_menu .= ">$cols\n";
+		}
+		$cols_menu .= "</SELECT>\n";
+
+		//$tpl->assign("cluster", $clustername);
+		$tpl->assign("metric","$metricname $units");
+		$tpl->assign("id", $id);
+		# Host columns menu defined in header.php
+		$tpl->assign("cols_menu", $cols_menu);
+
+		if( $sh) $showhosts = $sh;
+		if( !$showhosts) $showhosts = 0;
+		$tpl->assign("checked$showhosts", "checked");
+
+		if( $showhosts ) {
+			//-----
+
+			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="<td class=$class>".  "<b><a href=$host_link>$host</a></b><br>".  "<i>$metricname:</i> <b>$textval</b></td>";
+				} else {
+					$cell="<td><a href=$host_link>".  "<img src=\"../../graph.php?$graphargs\" ".  "alt=\"$host\" height=112 width=225 border=0></a></td>";
+				}
+
+				$tpl->assign("metric_image", $cell);
+				if (! ($i++ % $hostcols) )
+					 $tpl->assign ("br", "</tr><tr>");
+			}
+		}
+//---
+	}
 }
 ?>
Index: /trunk/web/addons/toga/templates/header.tpl
===================================================================
--- /trunk/web/addons/toga/templates/header.tpl	(revision 125)
+++ /trunk/web/addons/toga/templates/header.tpl	(revision 126)
@@ -9,5 +9,5 @@
 <BODY BGCOLOR="#FFFFFF">
 
-<FORM ACTION="{page}" METHOD="GET" NAME="ganglia_form">
+<FORM ACTION="./" METHOD="GET" NAME="toga_form">
 <TABLE WIDTH="100%">
 <TR>
@@ -45,5 +45,4 @@
 </TR>
 </TABLE> 
-</FORM>
 
 <FONT SIZE="+1">
Index: /trunk/web/addons/toga/templates/overview.tpl
===================================================================
--- /trunk/web/addons/toga/templates/overview.tpl	(revision 125)
+++ /trunk/web/addons/toga/templates/overview.tpl	(revision 126)
@@ -17,4 +17,5 @@
 <BR><BR>
 
+<SCRIPT TYPE="text/javascript" SRC="ts_picker.js"></SCRIPT>
 <SCRIPT TYPE="text/javascript">
 	function setSort( sortbyval ) {
@@ -51,6 +52,4 @@
 </SCRIPT>
 
-<FORM NAME="toga_form" ACTION="./" METHOD="GET">
-
 <INPUT TYPE="HIDDEN" NAME="sortby" VALUE="{sortby}">
 <INPUT TYPE="HIDDEN" NAME="sortorder" VALUE="{sortorder}">
@@ -60,6 +59,4 @@
 <INPUT TYPE="HIDDEN" NAME="user" VALUE="{f_user}">
 <INPUT TYPE="HIDDEN" NAME="id" VALUE="{f_id}">
-
-</FORM>
 
 <TABLE WIDTH="90%" CELLPADDING="8" CELLSPACING="3" BORDER=0>
@@ -93,2 +90,41 @@
 </TABLE>
 </CENTER>
+
+<!-- START BLOCK : showhosts -->
+<TABLE BORDER="0" WIDTH="100%">
+<TR>
+  <TD CLASS=title COLSPAN="2">
+  <FONT SIZE="-1">
+  Show Hosts:
+  yes<INPUT type=radio name="sh" value="1" OnClick="toga_form.submit();" {checked1}>
+  no<INPUT type=radio name="sh" value="0" OnClick="toga_form.submit();" {checked0}>
+  </FONT>
+  |
+  job <strong>{id}</strong> metric <strong>{metric}</strong>
+  |
+   <FONT SIZE="-1">
+   Columns&nbsp;&nbsp;{cols_menu}
+   </FONT><!-- <BR>
+   <FONT SIZE="-1">
+    Set graph timeperiod from <INPUT TYPE="text" NAME="start" VALUE="{start}" SIZE=12 ALT="Start time"><a href="javascript:show_calendar('document.toga_form.start', document.toga_form.start.value);"><img src="cal.gif" width="16" height="16" border="0"></a> to <INPUT TYPE="text" NAME="stop" VALUE="{stop}" SIZE=12 ALT="Stop time"><a href="javascript:show_calendar('document.toga_form.stop', document.toga_form.stop.value);"><img src="cal.gif" width="16" height="16" border="0"></a><INPUT TYPE="submit" VALUE="Refresh graphs">
+   </FONT> -->
+  </TD>
+</TR>
+   
+</TABLE>
+
+<CENTER>
+<TABLE>
+<TR>
+<!-- START BLOCK : sorted_list -->
+{metric_image}{br}
+<!-- END BLOCK : sorted_list -->
+</TR>
+</TABLE>
+
+<p>
+(Nodes colored by 1-minute load) | <A HREF="../../node_legend.html" ALT="Node Image egend">Legend</A>
+
+</CENTER>
+
+<!-- END BLOCK : showhosts -->
