Index: trunk/web/addons/toga/libtoga.php
===================================================================
--- trunk/web/addons/toga/libtoga.php	(revision 130)
+++ trunk/web/addons/toga/libtoga.php	(revision 135)
@@ -134,5 +134,5 @@
 
 		$output = explode( "\n", $output );
-		print_r( $output );
+		//print_r( $output );
 		return $output;
 	}
@@ -207,5 +207,5 @@
 	}
 
-	function makeJobRrds( $clustername, $hostname, $descr, $start, $end) {
+	function makeJobRrd( $clustername, $hostname, $metric, $descr, $start, $end) {
 		$this->clustername = $clustername;
 		$this->hostname = $hostname;
@@ -219,64 +219,84 @@
 			$time_size = count( $times );
 			$curtime = 1;
-			$this->metrics = $this->dirList( $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname .'/'. $times[0] );
 			//print_r( $this->metrics );
 
-			$intv = $this->getIntervalStep( '"'.$this->tarchdir . '/' . $this->clustername . '/' . $this->hostname .'/'. $times[0]. '/'.$this->metrics[0].'"' );
-			foreach( $this->metrics as $metric ) {	
-				$newfile = $this->tempdir .'/toga.temp-'. $descr .'-'.$metric;
-
-				foreach( $times as $timep ) {
-
-					$r_start = null;
-					$r_end = null;
-
-					if( $curtime == 1 )
-						$r_start = $start;
-
-					if( $curtime == $time_size )
-						$r_end = $end;
-
-					$file = $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname .'/'. $timep .'/'. $metric;
-
-					$r_values = $this->getValues( $file, $r_start, $r_end );
-					//print_r($r_values);
-
-					$myvalues = $myvalues + $r_values;
+			$firstold = $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname .'/'. $times[0]. '/'.$metric;
+
+			if( !file_exists( $firstold ) )
+				return 0;
+
+			$hostdir = $this->tempdir .'/'. $hostname;		
+			$newdir = $hostdir .'/'.$descr;
+			$newfile = $newdir .'/'.$metric;
+
+			//if( file_exists( $newfile ) )
+			//	return 0;
+
+			if( !file_exists( $hostdir ) )
+				mkdir( $hostdir );
+
+			if( !file_exists( $newdir ) )
+				mkdir( $newdir );
+
+			//$this->metrics = $this->dirList( $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname .'/'. $times[0] );
+			$intv = $this->getIntervalStep( '"'.$firstold.'"' );
+
+			foreach( $times as $timep ) {
+
+				$r_start = null;
+				$r_end = null;
+
+				if( $curtime == 1 )
+					$r_start = $start;
+
+				if( $curtime == $time_size )
+					$r_end = $end;
+
+				$file = $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname .'/'. $timep .'/'. $metric;
+
+				$r_values = $this->getValues( $file, $r_start, $r_end );
+				//print_r($r_values);
+
+				$myvalues = $myvalues + $r_values;
 				
-					$curtime++;	
-				}
-				//printf( "----myvalues----\n" );
-				//print_r($myvalues);
-				//printf( "----myvalues----\n" );
-
-				$heartbeat = intval( 8 * $intv );
-				$ret = $this->doCmd( $this->rrdbin .' create "'.$newfile.'" --step '. $intv .' --start '. $start .' DS:sum:GAUGE:'.$heartbeat.':U:U RRA:AVERAGE:0.5:1:'. count( $myvalues ) );
-
-				$update_args = array();
-				$arglist_nr = 0;
-
-				ksort( $myvalues );
-
-				foreach( $myvalues as $mytime=>$myvalue ) {
-					$myupdateval = ' '.trim($mytime).':'.trim($myvalue);
-
-					if( !isset($update_args[$arglist_nr]) )
-						$update_args[$arglist_nr] = '';
-
-					if( intval( strlen($update_args[$arglist_nr]) + strlen($myupdateval) ) > 50000 )
-						$arglist_nr++;
-
-					$update_args[$arglist_nr] .= $myupdateval;
-				}
-
-				//printf( "grootte args = %s\n", strlen( $update_args ) );
-
-				$ret = $this->doCmd( $this->rrdbin .' update "'. $newfile . '" blaaa' );
-				foreach( $update_args as $update_arg )
-					$ret = $this->doCmd( $this->rrdbin .' update "'. $newfile . '"'.$update_arg );
-
-				return;
-			}
-		}
+				$curtime++;	
+			}
+			//printf( "----myvalues----\n" );
+			//print_r($myvalues);
+			//printf( "----myvalues----\n" );
+
+			$heartbeat = intval( 8 * $intv );
+			$ret = $this->doCmd( $this->rrdbin .' create "'.$newfile.'" --step '. $intv .' --start '. $start .' DS:sum:GAUGE:'.$heartbeat.':U:U RRA:AVERAGE:0.5:1:'. count( $myvalues ) );
+
+			$update_args = array();
+			$arglist_nr = 0;
+
+			ksort( $myvalues );
+			reset( $myvalues );
+			$myvalues = array_unique( $myvalues );
+			reset( $myvalues );
+
+			foreach( $myvalues as $mytime=>$myvalue ) {
+				$myupdateval = ' '.trim($mytime).':'.trim($myvalue);
+
+				if( !isset($update_args[$arglist_nr]) )
+					$update_args[$arglist_nr] = '';
+
+				// Max_Args for Linux kernel is normally about 130k
+				//
+				if( intval( strlen($update_args[$arglist_nr]) + strlen($myupdateval) ) > 100000 )
+					$arglist_nr++;
+
+				$update_args[$arglist_nr] .= $myupdateval;
+			}
+
+			//printf( "grootte args = %s\n", strlen( $update_args ) );
+
+			foreach( $update_args as $update_arg )
+				$ret = $this->doCmd( $this->rrdbin .' update "'. $newfile . '"'.$update_arg );
+
+			printf( "generated %s\n", $newfile );
+		} else
+			return 0;
 	}
 
@@ -311,7 +331,7 @@
 					else
 						$keepval = 0;
-				} else if( $stop ) {
-
-					if( intval($timestamp) <= intval($stop) )
+				} else if( $end ) {
+
+					if( intval($timestamp) <= intval($end) )
 						$keepval = 1;
 					else
@@ -322,5 +342,5 @@
 				//printf("timestamp = %s, value = %s\n", $timestamp, $value );
 
-				if( $keepval )
+				if( $keepval and !isset($arvalues[$timestamp] ) )
 					$arvalues[$timestamp] = $value;
 			}
@@ -330,5 +350,5 @@
 		//printf( "----arvalues----\n" );
 
-		ksort( $arvalues );
+		//ksort( $arvalues );
 		//printf( "----arsortvalues----\n" );
 		//print_r( $arvalues);
@@ -521,12 +541,20 @@
 					if( $toganame == 'nodes' ) {
 
-						if( !isset( $jobs[$jobid][$toganame] ) )
-							$jobs[$jobid][$toganame] = array();
-
-						$mynodes = explode( ';', $togavalue );
-
-						foreach( $mynodes as $node )
-
-							$jobs[$jobid][$toganame][] = $node;
+						if( $jobs[$jobid][status] == 'R' ) {
+						
+							if( !isset( $jobs[$jobid][$toganame] ) )
+								$jobs[$jobid][$toganame] = array();
+
+							$mynodes = explode( ';', $togavalue );
+
+							foreach( $mynodes as $node )
+
+								$jobs[$jobid][$toganame][] = $node;
+
+						} else if( $jobs[$jobid][status] == 'Q' ) {
+
+							$jobs[$jobid][$toganame] = $togavalue;
+						}
+						
 					} else {
 
Index: trunk/web/addons/toga/overview.php
===================================================================
--- trunk/web/addons/toga/overview.php	(revision 130)
+++ trunk/web/addons/toga/overview.php	(revision 135)
@@ -358,5 +358,10 @@
                         $req_cpu = $jobattrs[requested_time];
                         $req_memory = $jobattrs[requested_memory];
-                        $nodes = count( $jobattrs[nodes] );
+
+			if( $state == 'R' )
+				$nodes = count( $jobattrs[nodes] );
+			else
+				$nodes = $jobattrs[nodes];
+
                         $ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1;
                         $cpus = $nodes * $ppn;
@@ -440,10 +445,18 @@
 	$even = 1;
 
-	$overview_jobs = count( $sorted_jobs );
-	$overview_nodes = count( $gnodes );
-	$overview_cpus = 0;
-
-	$f_cpus = 0;
-	$f_jobs = 0;
+	$used_jobs = 0;
+	$used_cpus = 0;
+	$used_nodes = 0;
+
+	$all_used_nodes = array();
+
+	$avail_nodes = count( $gnodes );
+	$avail_cpus = cluster_sum("cpu_num", $metrics);
+
+	$view_cpus = 0;
+	$view_jobs = 0;
+	$view_nodes = 0;
+
+	$view_used_nodes = array();
 
 	foreach( $sorted_jobs as $jobid => $sortdec ) {
@@ -455,5 +468,11 @@
 		$cpus = $nodes * $ppn;
 
-		$overview_cpus = $overview_cpus + $cpus;
+		foreach( $jobs[$jobid][nodes] as $tempnode )
+			$all_used_nodes[] = $tempnode;
+
+		if( $jobs[$jobid][status] == 'R' ) {
+			$used_cpus += $cpus;
+			$used_jobs++;
+		}
 
 		if( $report_time == $heartbeat ) {
@@ -474,5 +493,4 @@
 
 			if( $display_job ) {
-
 
 				$tpl->newBlock("node");
@@ -486,5 +504,10 @@
 				$tpl->assign("req_cpu", makeTime( timeToEpoch( $jobs[$jobid][requested_time] ) ) );
 				$tpl->assign("req_memory", $jobs[$jobid][requested_memory] );
-				$nodes = count( $jobs[$jobid][nodes] );
+
+				if( $jobs[$jobid][status] == 'R' )
+					$nodes = count( $jobs[$jobid][nodes] );
+				else if( $jobs[$jobid][status] == 'Q' )
+					$nodes = $jobs[$jobid][nodes];
+
 				$ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1;
 				$cpus = $nodes * $ppn;
@@ -494,6 +517,12 @@
 				$job_start = $start_time;
 
-				$f_cpus = $f_cpus + $cpus;
-				$f_jobs++;
+				$view_cpus += $cpus;
+				$view_jobs++;
+
+				if( $jobs[$jobid][status] == 'R' )
+					foreach( $jobs[$jobid][nodes] as $tempnode )
+						$view_used_nodes[] = $tempnode;
+				else if( $jobs[$jobid][status] == 'Q' )
+					$view_nodes += $jobs[$jobid][nodes];
 
 				if( $even ) {
@@ -517,12 +546,27 @@
 		}
 	}
-
-	$tpl->assignGlobal("cpus_nr", $overview_cpus );
-	$tpl->assignGlobal("jobs_nr", $overview_jobs );
-	$tpl->assignGlobal("nodes_nr", $overview_nodes );
+	array_unique( $all_used_nodes );
+	array_unique( $view_used_nodes );
+	$used_nodes = count( $all_used_nodes );
+	$view_nodes += count( $view_used_nodes );
+
+	//$tpl->assignGlobal("cpus_nr", $overview_cpus );
+	//$tpl->assignGlobal("jobs_nr", $overview_jobs );
+
+	$tpl->assignGlobal("avail_nodes", $avail_nodes );
+	$tpl->assignGlobal("avail_cpus", $avail_cpus );
+
+	$tpl->assignGlobal("used_nodes", $used_nodes );
+	$tpl->assignGlobal("used_jobs", $used_jobs );
+	$tpl->assignGlobal("used_cpus", $used_cpus );
+
+	$tpl->assignGlobal("view_nodes", $view_nodes );
+	$tpl->assignGlobal("view_jobs", $view_jobs );
+	$tpl->assignGlobal("view_cpus", $view_cpus );
+
 	$tpl->assignGlobal("report_time", makeDate( $heartbeat));
 	
-	$tpl->assignGlobal("f_cpus_nr", $f_cpus );
-	$tpl->assignGlobal("f_jobs_nr", $f_jobs );
+	//$tpl->assignGlobal("f_cpus_nr", $f_cpus );
+	//$tpl->assignGlobal("f_jobs_nr", $f_jobs );
 
 	if( array_key_exists( "id", $filter ) and $start_time ) {
Index: trunk/web/addons/toga/templates/overview.tpl
===================================================================
--- trunk/web/addons/toga/templates/overview.tpl	(revision 130)
+++ trunk/web/addons/toga/templates/overview.tpl	(revision 135)
@@ -6,6 +6,18 @@
   <TD ALIGN="CENTER">
     <IMG SRC="{clusterimage}"><BR>
-    {nodes_nr} nodes total: {jobs_nr} jobs with {cpus_nr} CPU's (at {report_time}).<BR>
-    current view: {f_jobs_nr} jobs with {f_cpus_nr} CPU's{lag_msg}.
+
+<TABLE ALIGN=CENTER>
+<TR>
+<TD><FONT SIZE="-1" class=footer>Last updated:</FONT></TD><TD><FONT SIZE="-1" class=footer>{report_time}</TD>
+</TR><TR>
+<TD><FONT SIZE="-1" class=footer>Available:</FONT></TD><TD><FONT SIZE="-1" class=footer>{avail_nodes} nodes / {avail_cpus} cpu's</FONT></TD>
+</TR><TR>
+<TD><FONT SIZE="-1" class=footer>Usage:</FONT></TD><TD><FONT SIZE="-1" class=footer>{used_jobs} jobs - {used_nodes} nodes / {used_cpus} cpu's</FONT></TD>
+</TR><TR>
+<TD><FONT SIZE="-1" class=footer>View:</FONT></TD><TD><FONT SIZE="-1" class=footer>{view_jobs} jobs - {view_nodes} nodes / {view_cpus} cpu's</FONT></TD>
+</TR>
+</TABLE>
+</FONT>
+
   </TD>
   <TD ALIGN="CENTER">
@@ -15,5 +27,5 @@
 </TABLE>
 
-<BR><BR>
+<BR>
 
 <SCRIPT TYPE="text/javascript" SRC="ts_picker.js"></SCRIPT>
