function physical_racks() { global $hosts_up, $hosts_down; # 2Key = "Rack ID / Rank (order in rack)" = [hostname, UP|DOWN] $rack = NULL; # If we don't know a node's location, it goes in a negative ID rack. $i = 1; $unknownID = -1; if (is_array($hosts_up)) { foreach ($hosts_up as $host => $v) { # Try to find the node's location in the cluster. list($rack, $rank, $plane) = findlocation($v); if ($rack >= 0 and $rank >= 0 and $plane >= 0 and !array_key_exists($rank, $racks[$rack])) { $racks[$rack][$rank] = $v['NAME']; continue; } else { $i++; if (!($i % 25)) { $unknownID--; } $racks[$unknownID][] = $v['NAME']; } } } if (is_array($hosts_down)) { foreach ($hosts_down as $host => $v) { list($rack, $rank, $plane) = findlocation($v); if ($rack >= 0 and $rank >= 0 and $plane >= 0 and !array_key_exists($rank, $racks[$rack])) { $racks[$rack][$rank] = $v['NAME']; continue; } else { $i++; if (!($i % 25)) { $unknownID--; } $racks[$unknownID][] = $v['NAME']; } } } # Sort the racks array. if ($unknownID < -1) { krsort($racks); } else { ksort($racks); reset($racks); while (list($rack, ) = each($racks)) { # In our convention, y=0 is close to the floor. (Easier to wire up) krsort($racks[$rack]); } } return $racks; }
# Host is specified in get_context.php. if (empty($hostname)) { print "<h1>Missing a Node Name</h1>"; return; } $tpl = new Dwoo_Template_File(template("show_node.tpl")); $data = new Dwoo_Data(); $data->assign("extra", template("node_extra.tpl")); $up = $hosts_up ? 1 : 0; $class = $up ? "even" : "down"; $data->assign("class", $class); $data->assign("name", $hostname); # $metrics is an array of [Metrics][Hostname][NAME|VAL|TYPE|UNITS|SOURCE]. # Find the host's physical location in the cluster. $hostattrs = $up ? $hosts_up : $hosts_down; list($rack, $rank, $plane) = findlocation($hostattrs); $location = $rack < 0 ? "Unknown" : "Rack {$rack}, Rank {$rank}, Plane {$plane}."; $data->assign("location", $location); if (isset($hostattrs['ip'])) { $data->assign("ip", $hostattrs['ip']); } else { $data->assign("ip", ""); } # The metrics we need for this node. $mem_total_gb = $metrics['mem_total']['VAL'] / 1048576; $load_one = $metrics['load_one']['VAL']; $load_five = $metrics['load_five']['VAL']; $load_fifteen = $metrics['load_fifteen']['VAL']; $cpu_user = $metrics['cpu_user']['VAL']; $cpu_system = $metrics['cpu_system']['VAL']; $cpu_idle = $metrics['cpu_idle']['VAL'];