-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcluster_view.php
294 lines (261 loc) · 9.62 KB
/
cluster_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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
<?php
/* $Id: cluster_view.php 1710 2008-08-21 16:44:54Z bernardli $ */
$tpl = new TemplatePower( template("cluster_view.tpl") );
$tpl->assignInclude("extra", template("cluster_extra.tpl"));
$tpl->prepare();
$tpl->assign("images","./templates/$template_name/images");
$cpu_num = !$showhosts ? $metrics["cpu_num"]['SUM'] : cluster_sum("cpu_num", $metrics);
$load_one_sum = !$showhosts ? $metrics["load_one"]['SUM'] : cluster_sum("load_one", $metrics);
$load_five_sum = !$showhosts ? $metrics["load_five"]['SUM'] : cluster_sum("load_five", $metrics);
$load_fifteen_sum = !$showhosts ? $metrics["load_fifteen"]['SUM'] : cluster_sum("load_fifteen", $metrics);
#
# Correct handling of *_report metrics
#
if (!$showhosts) {
if(array_key_exists($metricname, $metrics))
$units = $metrics[$metricname]['UNITS'];
}
else {
if(array_key_exists($metricname, $metrics[key($metrics)]))
$units = $metrics[key($metrics)][$metricname]['UNITS'];
}
if(isset($cluster['HOSTS_UP'])) {
$tpl->assign("num_nodes", intval($cluster['HOSTS_UP']));
} else {
$tpl->assign("num_nodes", 0);
}
if(isset($cluster['HOSTS_DOWN'])) {
$tpl->assign("num_dead_nodes", intval($cluster['HOSTS_DOWN']));
} else {
$tpl->assign("num_dead_nodes", 0);
}
$tpl->assign("cpu_num", $cpu_num);
$tpl->assign("localtime", date("Y-m-d H:i", $cluster['LOCALTIME']));
if (!$cpu_num) $cpu_num = 1;
$cluster_load15 = sprintf("%.0f", ((double) $load_fifteen_sum / $cpu_num) * 100);
$cluster_load5 = sprintf("%.0f", ((double) $load_five_sum / $cpu_num) * 100);
$cluster_load1 = sprintf("%.0f", ((double) $load_one_sum / $cpu_num) * 100);
$tpl->assign("cluster_load", "$cluster_load15%, $cluster_load5%, $cluster_load1%");
$cluster_url=rawurlencode($clustername);
$tpl->assign("cluster", $clustername);
$tpl->assign("cluster_contact", $ex_grid[$clustername]["contact"]);
#
# Summary graphs
#
$graph_args = "c=$cluster_url&$get_metric_string&st=$cluster[LOCALTIME]";
$tpl->assign("graph_args", $graph_args);
if (!isset($optional_graphs))
$optional_graphs = array();
foreach ($optional_graphs as $g) {
$tpl->newBlock('optional_graphs');
$tpl->assign('name',$g);
$tpl->assign('graph_args',$graph_args);
$tpl->gotoBlock('_ROOT');
}
#
# Correctly handle *_report cases and blank (" ") units
#
if (isset($units)) {
if ($units == " ")
$units = "";
else
$units=$units ? "($units)" : "";
}
else {
$units = "";
}
$tpl->assign("metric","$metricname $units");
$tpl->assign("sort", $sort);
$tpl->assign("range", $range);
$tpl->assign("checked$showhosts", "checked");
$sorted_hosts = array();
$down_hosts = array();
$percent_hosts = array();
if ($showhosts)
{
foreach ($hosts_up as $host => $val)
{
$cpus = $metrics[$host]["cpu_num"]['VAL'];
if (!$cpus) $cpus=1;
$load_one = $metrics[$host]["load_one"]['VAL'];
$load = ((float) $load_one)/$cpus;
$host_load[$host] = $load;
if(isset($percent_hosts[load_color($load)])) {
$percent_hosts[load_color($load)] += 1;
} else {
$percent_hosts[load_color($load)] = 1;
}
if ($metricname=="load_one")
$sorted_hosts[$host] = $load;
else if (isset($metrics[$host][$metricname]))
$sorted_hosts[$host] = $metrics[$host][$metricname]['VAL'];
else
$sorted_hosts[$host] = "";
}
foreach ($hosts_down as $host => $val)
{
$load = -1.0;
$down_hosts[$host] = $load;
if(isset($percent_hosts[load_color($load)])) {
$percent_hosts[load_color($load)] += 1;
} else {
$percent_hosts[load_color($load)] = 1;
}
}
# Show pie chart of loads
$pie_args = "title=" . rawurlencode("Cluster Load Percentages");
$pie_args .= "&size=250x150";
foreach($load_colors as $name=>$color)
{
if (!array_key_exists($color, $percent_hosts))
continue;
$n = $percent_hosts[$color];
$name_url = rawurlencode($name);
$pie_args .= "&$name_url=$n,$color";
}
$tpl->assign("pie_args", $pie_args);
# Host columns menu defined in header.php
$tpl->newBlock('columns_size_dropdown');
$tpl->assign("cols_menu", $cols_menu);
$tpl->assign("size_menu", $size_menu);
$tpl->newBlock('node_legend');
}
else
{
# Show pie chart of hosts up/down
$pie_args = "title=" . rawurlencode("Host Status");
$pie_args .= "&size=250x150";
$up_color = $load_colors["25-50"];
$down_color = $load_colors["down"];
$pie_args .= "&Up=$cluster[HOSTS_UP],$up_color";
$pie_args .= "&Down=$cluster[HOSTS_DOWN],$down_color";
$tpl->assign("pie_args", $pie_args);
}
# No reason to go on if we have no up hosts.
if (!is_array($hosts_up) or !$showhosts) {
$tpl->printToScreen();
return;
}
switch ($sort)
{
/*
case "descending":
arsort($sorted_hosts);
break;
case "by name":
uksort($sorted_hosts, "strnatcmp");
break;
default:
case "ascending":
asort($sorted_hosts);
break;
*/
case "DESC":
arsort($sorted_hosts);
break;
case "Name":
uksort($sorted_hosts, "strnatcmp");
break;
default:
case "ASC":
asort($sorted_hosts);
break;
}
$sorted_hosts = array_merge($down_hosts, $sorted_hosts);
# First pass to find the max value in all graphs for this
# metric. The $start,$end variables comes from get_context.php,
# included in index.php.
list($min, $max) = find_limits($sorted_hosts, $metricname);
# Second pass to output the graphs or metrics.
$i = 1;
foreach ( $sorted_hosts as $host => $value )
{
$tpl->newBlock ("sorted_list");
$host_url = rawurlencode($host);
$host_link="\"?c=$cluster_url&h=$host_url&$get_metric_string\"";
$textval = "";
#echo "$host: $value, ";
if (isset($hosts_down[$host]) and $hosts_down[$host])
{
if ($cluster['LOCALTIME'] - $hosts_down[$host]['REPORTED'] > 259200) continue;
$last_heartbeat = $cluster['LOCALTIME'] - $hosts_down[$host]['REPORTED'];
$age = $last_heartbeat > 3600 ? uptime($last_heartbeat) : "${last_heartbeat}s";
$class = "down";
$textval = "down <br> <font size=-2>Last heartbeat $age ago</font>";
}
else
{
if(isset($metrics[$host][$metricname]))
$val = $metrics[$host][$metricname];
else
$val = NULL;
$class = "metric";
if ($val['TYPE']=="timestamp" or
(isset($always_timestamp[$metricname]) and
$always_timestamp[$metricname]))
{
$textval = date("r", $val['VAL']);
}
elseif ($val['TYPE']=="string" or $val['SLOPE']=="zero" or
(isset($always_constant[$metricname]) and
$always_constant[$metricname] or
($max_graphs > 0 and $i > $max_graphs )))
{
$textval = "$val[VAL] $val[UNITS]";
}
else
{
$load_color = load_color($host_load[$host]);
$size = isset($clustergraphsize) ? $clustergraphsize : 'small';
$graphargs = (isset($reports[$metricname]) and
$reports[$metricname]) ?
"g=$metricname&" : "m=$metricname&";
$graphargs .= "z=$size&c=$cluster_url&h=$host_url"
."&l=$load_color&v=$val[VAL]&x=$max&n=$min"
."&r=$range&su=1&st=$cluster[LOCALTIME]";
if ($metrics[$host][$metricname]['UNITS']) {
$encodeUnits = rawurlencode($metrics[$host][$metricname]['UNITS']);
$graphargs .= "&vl=$encodeUnits";
}
}
}
if ($textval)
{
$cell="<td class=$class>".
"<b><a href=$host_link>$host</a></b><br>".
"<i>$metricname:</i> <b>$textval</b></td>";
}
else
{
$n_dns = "";
$a_ip = ip2net($host_group[$host]['IP']);
$n_ip = $a_ip['nip'];
$w_ip = $a_ip['wip'];
if ($zone_list[$n_ip]) {
$n_dns = "<a href='./tools/?q={$zone_list[$n_ip][0]}&m=dns&TB_iframe=ture&width=980&height=600' class='thickbox'>".$zone_list[$n_ip][0].'</a>';
if ($zone_list[$n_ip][1]) {
$n_dns .= "<br><a href='./tools/?q={$zone_list[$n_ip][1]}&m=dns&TB_iframe=ture&width=980&height=600' class='thickbox'>".$zone_list[$n_ip][1].'</a>';
}
}
if ($zone_list[$w_ip]) {
$n_dns .= "<br><a href='./tools/?q={$zone_list[$w_ip][0]}&m=dns&TB_iframe=ture&width=980&height=600' class='thickbox'>".$zone_list[$w_ip][0].'</a>';
}
if (!$n_dns) {
$n_dns = "<br><a class='thickbox' href='./tools/?c=$clustername&h=$host&g=$metricname&m=graph_view&thickbox=1&TB_iframe=ture&width=980&height=600'>{$host_group[$host]['IP']}</a>";
}
$cell="<td align=center valign=bottom>$n_dns<br><a href=$host_link>".
"<div class='img'><img src=\"./graph.php?$graphargs\" ".
"alt=\"$host\" border=0></div></a></td>";
if ($_GET['output_list']) {
$output_list .= "$w_ip $n_ip {$zone_list[$n_ip][0]} {$zone_list[$n_ip][1]} {$zone_list[$n_ip][2]}<br>";
}
}
$tpl->assign("metric_image", $cell);
if (! ($i++ % $hostcols) )
$tpl->assign ("br", "</tr><tr>");
}
$tpl->printToScreen();
if ($_GET['output_list']) {
echo "<br>$output_list<br>";
}
?>