-
Notifications
You must be signed in to change notification settings - Fork 0
/
host_view.php
176 lines (159 loc) · 5.75 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
<?php
/* $Id: host_view.php 2203 2010-01-08 17:25:32Z d_pocock $ */
$tpl = new TemplatePower( template("host_view.tpl") );
$tpl->assignInclude("extra", template("host_extra.tpl"));
$tpl->prepare();
$tpl->assign("cluster", $clustername);
$tpl->assign("host", $hostname);
$tpl->assign("node_image", node_image($metrics));
$tpl->assign("sort",$sort);
$tpl->assign("range",$range);
if($hosts_up)
$tpl->assign("node_msg", "This host is up and running.");
else
$tpl->assign("node_msg", "This host is down.");
$cluster_url=rawurlencode($clustername);
$tpl->assign("cluster_url", $cluster_url);
$tpl->assign("graphargs", "h=$hostname&$get_metric_string&st=$cluster[LOCALTIME]");
# For the node view link.
$tpl->assign("node_view","./?p=2&c=$cluster_url&h=$hostname");
# No reason to go on if this node is down.
if ($hosts_down)
{
$tpl->printToScreen();
return;
}
$tpl->assign("ip", $hosts_up['IP']);
$tpl->newBlock('columns_dropdown');
$tpl->assign("metric_cols_menu", $metric_cols_menu);
$g_metrics_group = array();
foreach ($metrics as $name => $v)
{
if ($v['TYPE'] == "string" or $v['TYPE']=="timestamp" or
(isset($always_timestamp[$name]) and $always_timestamp[$name]))
{
$s_metrics[$name] = $v;
}
elseif ($v['SLOPE'] == "zero" or
(isset($always_constant[$name]) and $always_constant[$name]))
{
$c_metrics[$name] = $v;
}
else if (isset($reports[$name]) and $reports[$metric])
continue;
else
{
$graphargs = "c=$cluster_url&h=$hostname&v=$v[VAL]"
."&m=$name&r=$range&z=medium&jr=$jobrange"
."&js=$jobstart&st=$cluster[LOCALTIME]";
# Adding units to graph 2003 by Jason Smith <[email protected]>.
if ($v['UNITS']) {
$encodeUnits = rawurlencode($v['UNITS']);
$graphargs .= "&vl=$encodeUnits";
}
if (isset($v['TITLE'])) {
$title = $v['TITLE'];
$graphargs .= "&ti=$title";
}
$g_metrics[$name]['graph'] = $graphargs;
$g_metrics[$name]['description'] = isset($v['DESC']) ? $v['DESC'] : '';
# Setup an array of groups that can be used for sorting in group view
if ( isset($metrics[$name]['GROUP']) ) {
$groups = $metrics[$name]['GROUP'];
} else {
$groups = array("");
}
foreach ( $groups as $group) {
if ( isset($g_metrics_group[$group]) ) {
$g_metrics_group[$group] = array_merge($g_metrics_group[$group], (array)$name);
} else {
$g_metrics_group[$group] = array($name);
}
}
}
}
# Add the uptime metric for this host. Cannot be done in ganglia.php,
# since it requires a fully-parsed XML tree. The classic contructor problem.
$s_metrics['uptime']['TYPE'] = "string";
$s_metrics['uptime']['VAL'] = uptime($cluster['LOCALTIME'] - $metrics['boottime']['VAL']);
$s_metrics['uptime']['TITLE'] = "Uptime";
# Add the gmond started timestamps & last reported time (in uptime format) from
# the HOST tag:
$s_metrics['gmond_started']['TYPE'] = "timestamp";
$s_metrics['gmond_started']['VAL'] = $hosts_up['GMOND_STARTED'];
$s_metrics['gmond_started']['TITLE'] = "Gmond Started";
$s_metrics['last_reported']['TYPE'] = "string";
$s_metrics['last_reported']['VAL'] = uptime($cluster['LOCALTIME'] - $hosts_up['REPORTED']);
$s_metrics['last_reported']['TITLE'] = "Last Reported";
# Show string metrics
if (is_array($s_metrics))
{
ksort($s_metrics);
foreach ($s_metrics as $name => $v )
{
# RFM - If units aren't defined for metric, make it be the empty string
! array_key_exists('UNITS', $v) and $v['UNITS'] = "";
$tpl->newBlock("string_metric_info");
if (isset($v['TITLE'])) {
$tpl->assign("name", $v['TITLE']);
}
else {
$tpl->assign("name", $name);
}
if( $v['TYPE']=="timestamp" or (isset($always_timestamp[$name]) and $always_timestamp[$name]))
{
$tpl->assign("value", date("r", $v['VAL']));
}
else
{
$tpl->assign("value", $v['VAL'] . " " . $v['UNITS']);
}
}
}
# Show constant metrics.
if (is_array($c_metrics))
{
ksort($c_metrics);
foreach ($c_metrics as $name => $v )
{
$tpl->newBlock("const_metric_info");
if (isset($v['TITLE'])) {
$tpl->assign("name", $v['TITLE']);
}
else {
$tpl->assign("name", $name);
}
$tpl->assign("value", "$v[VAL] $v[UNITS]");
}
}
# Show graphs.
if ( is_array($g_metrics) && is_array($g_metrics_group) )
{
ksort($g_metrics_group);
foreach ( $g_metrics_group as $group => $metric_array )
{
if ( $group == "" ) {
$group = "no_group";
}
$tpl->newBlock("vol_group_info");
$tpl->assign("group", $group);
$c = count($metric_array);
$tpl->assign("group_metric_count", $c);
$i = 0;
ksort($g_metrics);
foreach ( $g_metrics as $name => $v )
{
if ( in_array($name, $metric_array) ) {
$tpl->newBlock("vol_metric_info");
$tpl->assign("graphargs", $v['graph']);
$tpl->assign("alt", "$hostname $name");
if (isset($v['description']))
$tpl->assign("desc", $v['description']);
if ( !(++$i % $metriccols) && ($i != $c) )
$tpl->assign("new_row", "</TR><TR>");
}
}
}
}
$tpl->printToScreen();
?>