prepare();
#
# Proper english grammer...
#
$upcount=count($hosts[$cluster]);
$downcount=count($hosts_down[$cluster]);
$cpus=__reduce("cpu_num", __sum, $cluster);
$Cs = $cpus>1 ? "s" : "";
$Ns = $upcount>1 ? "s" : "";
$be = $Ns ? "are" : "is";
$tpl->assign("up_nodes", "There $be $upcount node$Ns ($cpus CPU$Cs) up and running.");
$Ns = $downcount>1 ? "s" : "";
$be = $Ns ? "are" : "is";
if ($downcount) {
$tpl->assign("down_nodes", "There $be $downcount node$Ns down.");
}
else {
$tpl->assign("down_nodes", "There are no nodes down.");
}
$tpl->assign( "load_one", __reduce("load_one", __sum, $cluster));
$tpl->assign( "load_five", __reduce("load_five", __sum, $cluster));
$tpl->assign( "load_fifteen", __reduce("load_fifteen", __sum, $cluster));
$clusterURL=rawurlencode($cluster);
$tpl->assign( "cluster", $cluster );
$tpl->assign( "load_graph", "");
$tpl->assign( "mem_graph", "
");
$tpl->assign( "cpu_graph", "
");
$firsthost=key($metrics[$cluster][$metric]);
$units=$metrics[$cluster][$metric][$firsthost][UNITS];
$units=$units ? "($units)" : "";
$tpl->assign("metric","$metric $units");
$i = 1;
if (is_array($hosts[$cluster])) {
foreach( $hosts[$cluster] as $k => $v )
{
$cpu_num = $metrics[$cluster]["cpu_num"][$k][VAL];
if(!$cpu_num || $cpu_num == 0)
{
$cpu_num = 1;
}
$load_one = $metrics[$cluster]["load_one"][$k][VAL];
$snapshot[$k] = $load_one/ $cpu_num;
}
arsort($snapshot);
foreach ($snapshot as $k => $v)
{
$tpl->newBlock ( "snapshot" );
$tpl->assign ( "node_image", node_image($cluster, $k));
if (!( $i++ % 25) )
{
$tpl->assign ("br", "
");
}
}
}
if (is_array($hosts_down[$cluster])) {
foreach ( $hosts_down[$cluster] as $k => $v )
{
$tpl->newBlock( "snapshot" );
$tpl->assign ( "node_image", node_image($cluster, $k));
if (!( $i++ % 25 ))
{
$tpl->assign ("br", "
");
}
}
}
# No reason to go on if we have no up hosts.
if (!is_array($hosts[$cluster])) {
$tpl->printToScreen();
exit;
}
switch ($sort)
{
case "descending":
__sort($metric, __sort_des, $cluster);
break;
case "by hostname":
__sort_name($metric, $cluster);
break;
default:
case "ascending":
__sort($metric, __sort_asc, $cluster);
break;
}
# First pass to find the max value in all graphs for this
# metric. The $start variable comes from get_context.php, included
# in index.php.
$max=0;
$min=0;
foreach ( $metrics[$cluster][$metric] as $host => $val ) {
if( $val[TYPE]=="string" or ($max_graphs > 0 and $i > $max_graphs )) {
continue;
}
$rrd_dir = "$rrds/$cluster/$host";
$command = RRDTOOL . " graph - --start $start --end N ".
"DEF:limits='$rrd_dir/$metric.rrd':'sum':AVERAGE ".
"PRINT:limits:MAX:%le ".
"PRINT:limits:MIN:%le";
exec($command,$out);
$thismax=$out[1];
if ($max < $thismax) {
$max = $thismax;
}
$thismin=$out[2];
if ($min > $thismin) {
$min = $thismin;
}
}
# Note: sprintf cannot convert a float in scientific notation
# to a decimal. Therefore we must use %f for all metrics.
$max = sprintf("%.2f",$max);
$min = ($min>0) ? sprintf("%.2f",$min) : $min;
# Second pass to output the graphs or metrics.
$i = 1;
foreach ( $metrics[$cluster][$metric] as $host => $val )
{
$tpl->newBlock ("sorted_list");
$host_url = rawurlencode($host);
$host_link="$host";
if ($val[TYPE]=="timestamp")
{
$date = date("r", $val[VAL]);
$cell="