-
Notifications
You must be signed in to change notification settings - Fork 0
/
physical_view.php
96 lines (76 loc) · 2.63 KB
/
physical_view.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/* $Id: physical_view.php 583 2005-10-04 18:45:16Z knobi1 $ */
#
# Displays the cluster in a physical view. Cluster nodes in
# this view are located by Rack, Rank, and Plane in the physical
# cluster.
#
# Originally written by Federico Sacerdoti <[email protected]>
# Part of the Ganglia Project, All Rights Reserved.
#
# Called from index.php, so cluster and xml tree vars
# ($metrics, $clusters, $hosts) are set, and header.php
# already called.
$tpl = new TemplatePower( template("physical_view.tpl") );
$tpl->prepare();
$tpl->assign("cluster",$clustername);
$cluster_url=rawurlencode($clustername);
$tpl->assign("cluster_url",$cluster_url);
# Assign the verbosity level. Can take the value of the 'p' CGI variable.
$verbose = $physical ? $physical : 2;
# The name of the variable changes based on the level. Nice.
$tpl->assign("checked$verbose","checked");
#
# Give the capacities of this cluster: total #CPUs, Memory, Disk, etc.
#
$CPUs = cluster_sum("cpu_num", $metrics);
# Divide by 1024^2 to get Memory in GB.
$Memory = sprintf("%.1f GB", cluster_sum("mem_total", $metrics)/(float)1048576);
$Disk = cluster_sum("disk_total", $metrics);
$Disk = $Disk ? sprintf("%.1f GB", $Disk) : "Unknown";
list($most_full, $most_full_host) = cluster_min("part_max_used", $metrics);
$tpl->assign("CPUs", $CPUs);
$tpl->assign("Memory", $Memory);
$tpl->assign("Disk", $Disk);
# Show which node has the most full disk.
$most_full_hosturl=rawurlencode($most_full_host);
$most_full = $most_full ? "<a href=\"./?p=1&c=$cluster_url&h=$most_full_host\">".
"$most_full_host ($most_full% Used)</a>" : "Unknown";
$tpl->assign("most_full", $most_full);
$tpl->assign("cols_menu", $cols_menu);
#-------------------------------------------------------------------------------
# Displays a rack and all its nodes.
function showrack($ID)
{
global $verbose, $racks, $metrics, $cluster, $hosts_up, $hosts_down;
global $cluster_url, $tpl, $clusters;
if ($ID>=0) {
$tpl->assign("RackID","<tr><th>Rack $ID</th></tr>");
}
# A string of node HTML for the template.
$nodes="";
foreach ($racks[$ID] as $name)
{
$nodes .= nodebox($name, $verbose);
}
return $nodes;
}
#-------------------------------------------------------------------------------
#
# My Main
#
# 2Key = "Rack ID / Rank (order in rack)" = [hostname, UP|DOWN]
$racks = physical_racks();
# Make a $cols-wide table of Racks.
$i=1;
foreach ($racks as $rack=>$v)
{
$tpl->newBlock("racks");
$racknodes = showrack($rack);
$tpl->assign("nodes", $racknodes);
if (! ($i++ % $hostcols)) {
$tpl->assign("tr","</tr><tr>");
}
}
$tpl->printToScreen();
?>