-
Notifications
You must be signed in to change notification settings - Fork 170
/
host_view.php
357 lines (304 loc) · 13 KB
/
host_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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
<?php
include_once("./global.php");
function make_metric_cols_menu($metriccols) {
$metric_cols_menu =
"<select name=\"mc\" OnChange=\"ganglia_form.submit();\">\n";
foreach (range(1, 25) as $metric_cols) {
$metric_cols_menu .= "<option value=$metric_cols ";
if ($metric_cols == $metriccols)
$metric_cols_menu .= "selected";
$metric_cols_menu .= ">$metric_cols\n";
}
$metric_cols_menu .= "</select>\n";
return $metric_cols_menu;
}
$tpl = new Dwoo_Template_File( template("host_view.tpl") );
$data = new Dwoo_Data();
$data->assign("cluster", $user['clustername']);
$data->assign("may_edit_cluster", checkAccess( $user['clustername'],
GangliaAcl::EDIT,
$conf ) );
$data->assign("may_edit_views", checkAccess( GangliaAcl::ALL_VIEWS,
GangliaAcl::EDIT,
$conf) );
$data->assign("sort", $user['sort']);
$data->assign("range", $user['range']);
$data->assign("hostname", $user['hostname']);
$data->assign("graph_engine", $conf['graph_engine']);
function dump_var($var, $varId) {
ob_start();
var_dump($var);
error_log($varId . " = ". ob_get_clean());
}
function getOptionalReports($hostname,
$clustername,
$conf_dir,
$optional_cluster_graphs_for_host_view,
$range,
$cs,
$ce,
$zoom_support,
$graph_engine,
$may_edit_views,
$default_optional_graph_size) {
global $GRAPH_BASE_ID;
global $SHOW_EVENTS_BASE_ID;
$optional_reports = "";
$cluster_enc = rawurlencode($clustername);
$graph_args = "h=$hostname&c=$cluster_enc&r=$range";
if ($cs)
$graph_args .= "&cs=" . rawurlencode($cs);
if ($ce)
$graph_args .= "&ce=" . rawurlencode($ce);
// If we want zoomable support on graphs we need to add correct zoomable
// class to every image
$additional_graph_img_html_args = "";
if (isset($zoom_support) && $zoom_support === true)
$additional_graph_img_html_args = "class=cluster_zoomable";
///////////////////////////////////////////////////////////////////////////
// Let's find out what optional reports are included
// First we find out what the default (site-wide) reports are then look
// for host specific included or excluded reports
///////////////////////////////////////////////////////////////////////////
$default_reports = array("included_reports" => array(),
"excluded_reports" => array());
if ( is_file($conf_dir . "/default.json") ) {
$default_reports = array_merge(
$default_reports,
json_decode(file_get_contents($conf_dir . "/default.json"),
TRUE));
}
if ( is_file($conf_dir . "/default_host.json") ) {
$default_reports = array_merge(
$default_reports,
json_decode(file_get_contents($conf_dir . "/default_host.json"),
TRUE));
}
$cluster_file = $conf_dir .
"/cluster_" .
str_replace(" ", "_", $clustername) .
".json";
$cluster_override_reports = array("included_reports" => array(),
"excluded_reports" => array());
if ($optional_cluster_graphs_for_host_view) {
if (is_file($cluster_file)) {
$cluster_override_reports = array_merge(
$cluster_override_reports,
json_decode(file_get_contents($cluster_file), TRUE));
}
}
$host_file = $conf_dir . "/host_" . $hostname . ".json";
$override_reports = array("included_reports" => array(),
"excluded_reports" => array());
if ( is_file($host_file) ) {
$override_reports = array_merge(
$override_reports,
json_decode(file_get_contents($host_file), TRUE));
} else {
// If there is no host file, look for a default cluster file
$cluster_file = $conf_dir . "/cluster_" . $clustername . ".json";
if ( is_file($cluster_file) ) {
$override_reports = array_merge(
$override_reports,
json_decode(file_get_contents($cluster_file), TRUE));
}
}
// Merge arrays
$reports["included_reports"] = array_merge(
$default_reports["included_reports"],
$cluster_override_reports["included_reports"],
$override_reports["included_reports"]);
$reports["excluded_reports"] = array_merge(
$default_reports["excluded_reports"],
$cluster_override_reports["excluded_reports"],
$override_reports["excluded_reports"]);
// Remove duplicates
$reports["included_reports"] = array_unique($reports["included_reports"]);
$reports["excluded_reports"] = array_unique($reports["excluded_reports"]);
foreach ( $reports["included_reports"] as $index => $report_name ) {
if ( ! in_array( $report_name, $reports["excluded_reports"] ) ) {
$graph_anchor =
"<a href=\"./graph_all_periods.php?$graph_args&g=" . $report_name .
"&z=large\">";
$addMetricBtn = "<button class=\"cupid-green\" title=\"Metric Actions - Add to View, etc\" onclick=\"metricActions('{$hostname}','{$report_name}','graph',''); return false;\">+</button>";
$csvBtn = "<button title=\"Export to CSV\" class=\"cupid-green\" onClick=\"javascript:location.href='./graph.php?$graph_args&g={$report_name}&&csv=1';return false;\">CSV</button>";
$jsonBtn = "<button title=\"Export to JSON\" class=\"cupid-green\" onClick=\"javascript:location.href='./graph.php?$graph_args&g={$report_name}&json=1';return false;\">JSON</button>";
if ($graph_engine == "flot") {
$optional_reports .= $graph_anchor . "</a>";
$optional_reports .= '<div class="flotheader"><span class="flottitle">' . $report_name . '</span>';
if ($may_edit_views)
$optional_reports .= $addMetricBtn. ' ';
$optional_reports .= $csvBtn . ' ' . $jsonBtn . "</div>";
$optional_reports .= '<div id="placeholder_' . $graph_args . '&g=' . $report_name .'&z=medium" class="flotgraph2 img_view"></div>';
$optional_reports .= '<div id="placeholder_' . $graph_args . '&g=' . $report_name .'&z=medium_legend" class="flotlegend"></div>';
} else {
$optional_reports .= "<div class='img_view'>";
$graphId = $GRAPH_BASE_ID . $report_name;
$inspectBtn = "<button title=\"Inspect Graph\" onClick=\"inspectGraph('{$graph_args}&g={$report_name}'); return false;\" class=\"shiny-blue\">Inspect</button>";
$showEventBtn = '<input title="Hide/Show Events" type="checkbox" id="' . $SHOW_EVENTS_BASE_ID . $report_name . '" onclick="showEvents(\'' . $graphId . '\', this.checked)"/><label class="show_event_text" for="' . $SHOW_EVENTS_BASE_ID . $report_name . '">Hide/Show Events</label>';
if ($may_edit_views)
$optional_reports .= $addMetricBtn . ' ';
$optional_reports .= $csvBtn . ' ' . $jsonBtn . ' ' .$inspectBtn . ' ' . $showEventBtn . "<br />" . $graph_anchor . "<img id=\"" . $graphId . "\" $additional_graph_img_html_args border=\"0\" title=\"$cluster_enc\" src=\"./graph.php?$graph_args&g=" . $report_name ."&z=" . $default_optional_graph_size . "\" style=\"margin-top:5px;\" /></a></div>";
}
}
} // foreach
return $optional_reports;
}
function getMetricGroups($metrics,
$always_timestamp,
$always_constant,
$hostname,
$baseGraphArgs,
$data) {
global $conf;
$metric_groups_initially_collapsed =
isset($conf['metric_groups_initially_collapsed']) ?
$conf['metric_groups_initially_collapsed'] : TRUE;
$remember_open_metric_groups =
isset($conf['remember_open_metric_groups']) ?
$conf['remember_open_metric_groups'] : TRUE;
$open_groups = NULL;
if (isset($_GET['metric_group']) && ($_GET['metric_group'] != "")) {
$open_groups = explode ("_|_", htmlentities($_GET['metric_group']));
} else {
if ($remember_open_metric_groups &&
isset($_SESSION['metric_group']) &&
($_SESSION['metric_group'] != ""))
$open_groups = explode ("_|_", htmlentities($_SESSION['metric_group']));
}
// Updated definition of currently open metric groups
$new_open_groups = "";
$host_metrics = 0;
$metrics_group_data = array();
list($metricMap, $metricGroupMap) =
buildMetricMaps($metrics,
$always_timestamp,
$always_constant,
$baseGraphArgs);
// dump_var($metricMap, "metricMap");
// dump_var($metricGroupMap, "metricGroupMap");
if (is_array($metricMap) && is_array($metricGroupMap)) {
ksort($metricGroupMap);
if ($open_groups == NULL) {
if ($metric_groups_initially_collapsed)
$new_open_groups = "NOGROUPS";
else
$new_open_groups = "ALLGROUPS";
} else
$new_open_groups .= $open_groups[0];
foreach ($metricGroupMap as $group => $metric_array) {
if ($group == "") {
$group = "no_group";
}
$num_metrics = count($metric_array);
$metrics_group_data[$group]["group_metric_count"] = $num_metrics;
$host_metrics += $num_metrics;
if ($open_groups == NULL) {
$metrics_group_data[$group]["visible"] =
! $metric_groups_initially_collapsed;
} else {
$inList = in_array($group, $open_groups);
$metrics_group_data[$group]["visible"] =
((($open_groups[0] == "NOGROUPS") && $inList) ||
($open_groups[0] == "ALLGROUPS" && !$inList));
}
$visible = $metrics_group_data[$group]["visible"];
if (($visible && ($open_groups[0] == "NOGROUPS")) ||
(!$visible && ($open_groups[0] == "ALLGROUPS")))
$new_open_groups .= "_|_" . $group;
if (function_exists("sort_metric_group_metrics")) {
$metric_array = sort_metric_group_metrics($group, $metric_array);
} else {
// Sort by metric_name
asort($metric_array, SORT_NATURAL);
}
$i = 0;
foreach ($metric_array as $name) {
$metrics_group_data[$group]["metrics"][$name]["graphargs"] = $metricMap[$name]['graph'];
$metrics_group_data[$group]["metrics"][$name]["alt"] = "$hostname $name";
$metrics_group_data[$group]["metrics"][$name]["host_name"] = $hostname;
$metrics_group_data[$group]["metrics"][$name]["metric_name"] = $name;
$metrics_group_data[$group]["metrics"][$name]["title"] = $metricMap[$name]['title'];
$metrics_group_data[$group]["metrics"][$name]["desc"] = $metricMap[$name]['description'];
$metrics_group_data[$group]["metrics"][$name]["new_row"] = "";
if (!(++$i % $conf['metriccols']) && ($i != $num_metrics))
$metrics_group_data[$group]["metrics"][$name]["new_row"] = "</tr><tr>";
}
}
}
$data->assign("host_metrics_count", $host_metrics);
$_SESSION['metric_group'] = $new_open_groups;
$data->assign("g_metrics_group_data", $metrics_group_data);
$data->assign("g_open_metric_groups", $new_open_groups);
}
$optional_reports = getOptionalReports(
$user['hostname'],
$user['clustername'],
$conf['conf_dir'],
$conf['optional_cluster_graphs_for_host_view'],
$user['range'],
$user['cs'],
$user['ce'],
$conf['zoom_support'],
$conf['graph_engine'],
checkAccess( GangliaAcl::ALL_VIEWS,
GangliaAcl::EDIT,
$conf),
$conf['default_optional_graph_size']);
// dump_var($optional_reports, "optional_reports");
$data->assign("optional_reports", $optional_reports);
getHostOverViewData($user['hostname'],
$metrics,
$cluster,
$hosts_up,
$hosts_down,
$always_timestamp,
$always_constant,
$data);
# When this node is down, only show data when show_host_data_if_down is True
if ($hosts_down && !$conf['show_host_data_if_down']) {
$dwoo->output($tpl, $data);
return;
}
$data->assign('columns_dropdown', 1);
$data->assign("metric_cols_menu", make_metric_cols_menu($conf['metriccols']));
$data->assign("size_menu", $size_menu);
$size = isset($user['clustergraphsize']) ?
$user['clustergraphsize'] : 'default';
//set to 'default' to preserve old behavior
$size = ($size == 'medium') ? 'default' : $size;
// set host zoom class based on the size of the graph shown
$additional_host_img_css_classes = "";
if ( isset($conf['zoom_support']) && $conf['zoom_support'] === true )
$additional_host_img_css_classes = "host_${size}_zoomable";
$data->assign("additional_host_img_css_classes",
$additional_host_img_css_classes);
# in case this is not defined, set to LOCALTIME so uptime will be 0
# in the display
if (!isset($metrics['boottime']['VAL'])) {
$metrics['boottime']['VAL'] = $cluster['LOCALTIME'];
}
$cluster_url = rawurlencode($clustername);
$baseGraphArgs = "c=$cluster_url&h=" . $user['hostname']
. "&r=" . $user['range'] . "&z=$size&jr=$jobrange"
. "&js=$jobstart&st=$cluster[LOCALTIME]";
if ($user['cs'])
$baseGraphArgs .= "&cs=" . rawurlencode($user['cs']);
if ($user['ce'])
$baseGraphArgs .= "&ce=" . rawurlencode($user['ce']);
$data->assign("baseGraphArgs", htmlspecialchars_decode($baseGraphArgs));
getMetricGroups($metrics,
$always_timestamp,
$always_constant,
$user['hostname'],
$baseGraphArgs,
$data);
if ( $conf['graph_engine'] == "flot" ) {
$data->assign("graph_height", $conf['graph_sizes'][$size]["height"] + 50);
$data->assign("graph_width", $conf['graph_sizes'][$size]["width"]);
}
$data->assign('GRAPH_BASE_ID', $GRAPH_BASE_ID);
$data->assign('SHOW_EVENTS_BASE_ID', $SHOW_EVENTS_BASE_ID);
$data->assign('TIME_SHIFT_BASE_ID', $TIME_SHIFT_BASE_ID);
$dwoo->output($tpl, $data);
?>