forked from ganglia/ganglia-web
-
Notifications
You must be signed in to change notification settings - Fork 1
/
meta_view.php
240 lines (218 loc) · 8.96 KB
/
meta_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
<?php
$tpl = new Dwoo_Template_File( template("meta_view.tpl") );
$data = new Dwoo_Data();
discover_filters();
if ( !empty($filter_defs) ) {
$data->assign("filters", $filter_defs);
$data->assign("choose_filter", $choose_filter);
}
$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);
}
$sources = array();
# 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;
}
# Make sure the source is permitted by the filters, if any
if(!filter_permit($source))
continue;
$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&$get_metric_string";
}
$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%";
$clusname = $source == $self ? '' : $source;
$avg_cpu_num = find_avg($clusname, "", "cpu_num");
if ($avg_cpu_num == 0) $avg_cpu_num = 1;
$cluster_util = sprintf("%.0f", ((double) find_avg($clusname, "", "load_one") / $avg_cpu_num ) * 100);
$sources[$source]["name"] = $name;
$sources[$source]["cpu_num"] = $m["cpu_num"]['SUM'];
$sources[$source]["url"] = $url;
$sources[$source]["class"] = $class;
# Initialize some variables for the $sources array to be past to the template since private sources
# may not have these defined
$sources[$source]["alt_view"] = "";
$sources[$source]["cluster_load"] = "";
$sources[$source]["cluster_util"] = "";
$sources[$source]["num_dead_nodes"] = "";
$sources[$source]["range"] = "";
$sources[$source]["graph_url"] = "";
$sources[$source]["base64img"] = "";
if ($localtime)
$sources[$source]["localtime"] = "<font size=\"-1\">Localtime:</font><br> "
. date("Y-m-d H:i", $localtime);
# I dont like this either, but we need to have private clusters because some
# users are skittish about publishing the load info.
if(checkAccess($source, GangliaAcl::VIEW, $conf))
{
$sources[$source]["alt_view"] = "<FONT SIZE=\"-2\">$alt_url</FONT>";
$sources[$source]["public"] = 1;
if ($cluster_load)
$sources[$source]["cluster_load"] = "<font size=\"-1\">Current Load Avg (15, 5, 1m):</font>"
."<br> <b>$cluster_load</b>";
if (isset($cluster_util))
$sources[$source]["cluster_util"] = "<font size=\"-1\">Avg Utilization (last $range):</font>"
."<br> <b>$cluster_util%</b>";
$sources[$source]["num_nodes"] = $grid[$source]["HOSTS_UP"];
$sources[$source]["num_dead_nodes"] = $grid[$source]["HOSTS_DOWN"];
$sources[$source]["range"] = $range;
$sources[$source]["graph_url"] = $graph_url;
if(isset($base64img)) {
$sources[$source]["base64img"] = $base64img;
}
if ( $source == $self ) {
$sources[$source]["self_summary_graphs"] = 1;
} else {
$sources[$source]["summary_graphs"] = 1;
}
}
else
{
$sources[$source]["private"] = 1;
$sources[$source]["num_nodes"] = $grid[$source]["HOSTS_UP"] + $grid[$source]["HOSTS_DOWN"];
}
}
$data->assign("sources", $sources);
$snap_rows = array();
# Show load images.
if ($conf['show_meta_snapshot']=="yes") {
$data->assign("show_snapshot", 1);
$data->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 (! checkAccess($c, GangliaAcl::VIEW, $conf)) {
$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 = "";
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]\" alt=\"$names[$k]\" border=0 align=top></a></td>\n";
}
$snap_rows[$i]["names"] = $snapnames;
$snap_rows[$i]["images"] = $snapimgs;
$i += $cols;
}
$data->assign("snap_rows", $snap_rows);
}
$dwoo->output($tpl, $data);
?>