-
Notifications
You must be signed in to change notification settings - Fork 0
/
grid_mesh_view.php
225 lines (202 loc) · 8.18 KB
/
grid_mesh_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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<?php
/* $Id: meta_view.php 1710 2008-08-21 16:44:54Z bernardli $ */
$tpl = new TemplatePower( template("grid_mesh_view.tpl") );
$tpl->prepare();
/* Add first metric to draw - the one that we currently care about */
if (!$mesh_first_metric) {
$mesh_first_metric = 'cpu_report';
}
$tpl->assignGlobal("mesh_first_metric", $mesh_first_metric);
$source_names = array_keys($grid);
# Build a list of cluster names and randomly pick a smaller subset to
# display for control room mode. This allows a dedicated host to
# eventually cycle through all the graphs w/o scrolling the mouse. A bunch
# of these stations could monitor a large grid.
#
# For the standard meta view still display all the hosts.
if ( $context == "control" ) {
srand((double)microtime()*1000000);
shuffle($source_names);
$subset = array_slice($source_names, 0, abs($controlroom));
$source_names = $subset;
}
foreach( $source_names as $c)
{
$cpucount = $metrics[$c]["cpu_num"]['SUM'];
if (!$cpucount) $cpucount=1;
$load_one = $metrics[$c]["load_one"]['SUM'];
$value = (double) $load_one / $cpucount;
$sorted_sources[$c] = $value;
$values[$c] = $value;
isset($total_load) or $total_load = 0;
$total_load += $value;
}
if ($sort == "descending") {
$sorted_sources[$self] = 999999999;
arsort($sorted_sources);
} else if ($sort == "by name") { # SORT HACK to keep $self first; see below:
$sorted_sources["AAAAA.$self"] = $sorted_sources[$self];
unset($sorted_sources[$self]);
ksort($sorted_sources);
} else if ($sort == "by hosts up") {
foreach ($sorted_sources as $source => $val) {
$sorted_sources[$source] = intval($grid[$source]['HOSTS_UP']);
}
$sorted_sources[$self] = 999999999;
arsort($sorted_sources);
} else if ($sort == "by hosts down") {
foreach ($sorted_sources as $source => $val) {
$sorted_sources[$source] = intval($grid[$source]['HOSTS_DOWN']);
}
$sorted_sources[$self] = 999999999;
arsort($sorted_sources);
} else {
$sorted_sources[$self] = -1;
asort($sorted_sources);
}
# Display the sources. The first is ourself, the rest are our children.
foreach ( $sorted_sources as $source => $val )
{
# XXX: SORT HACK to keep $self first; see above
if ($source == "AAAAA.$self") {
$source = $self;
}
$m = $metrics[$source];
$sourceurl = rawurlencode($source);
if (isset($grid[$source]['GRID']) and $grid[$source]['GRID'])
{
$localtime = $grid[$source]['LOCALTIME'];
# Is this the our own grid?
if ($source==$self)
{
# Negative control room values means dont display grid summary.
if ($controlroom < 0) continue;
$num_sources = count($sorted_sources) - 1;
$name = "$self $meta_designator ($num_sources sources)";
$graph_url = "me=$sourceurl&$get_metric_string";
$url = "./?$get_metric_string";
}
else
{
# Set grid context.
$name = "$source $meta_designator";
$graph_url = "G=$sourceurl&$get_metric_string&st=$localtime";
$authority = $grid[$source]['AUTHORITY'];
$url = "$authority?gw=fwd&gs=$gridstack_url";
}
$alt_url = "<a href=\"./?t=yes&$get_metric_string\">(tree view)</a>";
$class = "grid";
}
else
{
# Set cluster context.
$name = $source;
$localtime = $grid[$source]['LOCALTIME'];
$graph_url = "c=$sourceurl&$get_metric_string&st=$localtime";
$url = "./?c=$sourceurl&$get_metric_string";
$alt_url = "<a href=\"./?p=2&$graph_url\">(physical view)</a>";
$class = "cluster";
}
$cpu_num = $m["cpu_num"]['SUM'] ? $m["cpu_num"]['SUM'] : 1;
$cluster_load15 = sprintf("%.0f", ((double) $m["load_fifteen"]['SUM'] / $cpu_num) * 100);
$cluster_load5 = sprintf("%.0f", ((double) $m["load_five"]['SUM'] / $cpu_num) * 100);
$cluster_load1 = sprintf("%.0f", ((double) $m["load_one"]['SUM'] / $cpu_num) * 100);
$cluster_load = "$cluster_load15%, $cluster_load5%, $cluster_load1%";
$tpl->newBlock ("source_info");
$tpl->assign("name", $name );
$tpl->assign("cpu_num", $m["cpu_num"]['SUM']);
$tpl->assign("url", $url);
$tpl->assign("class", $class);
if (isset($num_sources))
$tpl->assign("Sources: $num_sources");
# I dont like this either, but we need to have private clusters because some
# users are skittish about publishing the load info.
if (!isset($private[$source]) or !$private[$source])
{
$tpl->assign("alt_view", "<FONT SIZE=\"-2\">$alt_url</FONT>");
# Each block has a different namespace, so we need to redefine variables.
$tpl->newBlock("public");
if ($localtime)
$tpl->assign("localtime", "<font size=-1>Localtime:</font><br> "
. date("Y-m-d H:i", $localtime) );
if ($cluster_load)
$tpl->assign("cluster_load", "<font size=-1>Avg Load (15, 5, 1m):</font>"
."<br> $cluster_load");
$tpl->assign("cpu_num", $m["cpu_num"]['SUM']);
$tpl->assign("num_nodes", $grid[$source]["HOSTS_UP"] );
$tpl->assign("num_dead_nodes", $grid[$source]["HOSTS_DOWN"] );
$tpl->assign("range", $range);
$tpl->assign("name", $name );
$tpl->assign("url", $url);
$tpl->assign("graph_url", $graph_url);
if(isset($base64img)) {
$tpl->assign("base64img", $base64img);
}
}
else
{
$tpl->newBlock("private");
$tpl->assign("num_nodes", $grid[$source]["HOSTS_UP"] + $grid[$source]["HOSTS_DOWN"] );
$tpl->assign("cpu_num", $m["cpu_num"]['SUM']);
if ($localtime)
$tpl->assign("localtime", "<font size=-1>Localtime:</font><br> "
. date("Y-m-d H:i",$localtime));
}
}
# Show load images.
if ($show_meta_snapshot=="yes") {
$tpl->newBlock("show_snapshot");
$tpl->assign("self", "$self $meta_designator");
foreach ($sorted_sources as $c=>$value) {
if ($c==$self) continue;
if ($c=="AAAAA.$self") continue; # SORT HACK; see above
if (isset($private[$c]) and $private[$c]) {
$Private[$c] = template("images/cluster_private.jpg");
continue;
}
$names[]=$c;
if (isset($grid[$c]['GRID']) and $grid[$c]['GRID'])
$image = load_image("grid", $values[$c]);
else
$image = load_image("cluster", $values[$c]);
$Images[]=$image;
}
# Add private cluster pictures to the end.
if (isset($Private) and is_array($Private)) {
foreach ($Private as $c=>$image) {
$names[]=$c;
$Images[]=$image;
}
}
# All this fancyness is to get the Cluster names
# above the image. Not easy with template blocks.
$cols=5;
$i = 0;
$count=count($names);
while ($i < $count)
{
$snapnames = "";
$snapimgs = "";
$tpl->newBlock("snap_row");
foreach(range(0, $cols-1) as $j)
{
$k = $i + $j;
if ($k >= $count) break;
$n = $names[$k];
$snapnames .= "<td valign=bottom align=center><b>$n</b></td>\n";
$snapimgs .= "<td valign=top align=center>";
if (isset($grid[$n]['GRID']) and $grid[$n]['GRID'])
$snapimgs .= "<a href=\"" . $grid[$n]['AUTHORITY'] ."?gw=fwd&gs=$gridstack_url\">";
else
{
$nameurl = rawurlencode($n);
$snapimgs .= "<a href=\"./?c=$nameurl&$get_metric_string\">";
}
$snapimgs .= "<img src=$Images[$k] border=0 align=top></a></td>\n";
}
$tpl->assign("names", $snapnames);
$tpl->assign("images", $snapimgs);
$i += $cols;
}
}
$tpl->printToScreen();