1 | <?php |
---|
2 | /* |
---|
3 | * |
---|
4 | * This file is part of Jobmonarch |
---|
5 | * |
---|
6 | * Copyright (C) 2006-2013 Ramon Bastiaans |
---|
7 | * |
---|
8 | * Jobmonarch is free software; you can redistribute it and/or modify |
---|
9 | * it under the terms of the GNU General Public License as published by |
---|
10 | * the Free Software Foundation; either version 2 of the License, or |
---|
11 | * (at your option) any later version. |
---|
12 | * |
---|
13 | * Jobmonarch is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
21 | * |
---|
22 | * SVN $Id: host_view.php 759 2013-03-27 19:50:05Z ramonb $ |
---|
23 | */ |
---|
24 | |
---|
25 | include_once "./libtoga.php"; |
---|
26 | |
---|
27 | $my_dir = getcwd(); |
---|
28 | |
---|
29 | global $context; |
---|
30 | |
---|
31 | $context = 'cluster'; |
---|
32 | |
---|
33 | if( $view == "overview-host" ) |
---|
34 | { |
---|
35 | chdir( $GANGLIA_PATH ); |
---|
36 | |
---|
37 | include "./ganglia.php"; |
---|
38 | include "./get_ganglia.php"; |
---|
39 | |
---|
40 | chdir( $my_dir ); |
---|
41 | } |
---|
42 | |
---|
43 | function datetimeToEpoch( $datetime ) |
---|
44 | { |
---|
45 | |
---|
46 | $datetime_fields = explode( ' ', $datetime ); |
---|
47 | |
---|
48 | $date = $datetime_fields[0]; |
---|
49 | $time = $datetime_fields[1]; |
---|
50 | |
---|
51 | $date_fields = explode( '-', $date ); |
---|
52 | |
---|
53 | $days = $date_fields[0]; |
---|
54 | $months = $date_fields[1]; |
---|
55 | $years = $date_fields[2]; |
---|
56 | |
---|
57 | //printf( "days = %s months = %s years = %s\n", $days, $months, $years ); |
---|
58 | |
---|
59 | $time_fields = explode( ':', $time ); |
---|
60 | |
---|
61 | $hours = $time_fields[0]; |
---|
62 | $minutes = $time_fields[1]; |
---|
63 | $seconds = $time_fields[2]; |
---|
64 | |
---|
65 | $timestamp = mktime( $hours, $minutes, $seconds, $months, $days, $years ); |
---|
66 | |
---|
67 | return $timestamp; |
---|
68 | } |
---|
69 | |
---|
70 | function makeHostView() |
---|
71 | { |
---|
72 | |
---|
73 | global $dwoo, $metrics, $clustername, $hostname; |
---|
74 | global $cluster_ul, $hosts_up, $get_metric_string; |
---|
75 | global $cluster, $period_start, $period_stop; |
---|
76 | global $job_start, $job_stop, $view, $conf, $range; |
---|
77 | |
---|
78 | $tpl = new Dwoo_Template_File("templates/host_view.tpl"); |
---|
79 | $tpl_data = new Dwoo_Data(); |
---|
80 | |
---|
81 | $rrdirs = array(); |
---|
82 | |
---|
83 | if( $view == "overview-host" ) |
---|
84 | { |
---|
85 | $rrdirs[] = $conf['rrds'] . '/' . $clustername .'/'. $hostname; |
---|
86 | } |
---|
87 | else |
---|
88 | { |
---|
89 | $trd = new TarchRrdGraph( $clustername, $hostname ); |
---|
90 | $rrdirs = $trd->getRrdDirs( $period_start, $period_stop ); |
---|
91 | } |
---|
92 | |
---|
93 | $longtitle = "Batch Archive Node Report :: Powered by Job Monarch!"; |
---|
94 | $title = "Batch Archive Node Report"; |
---|
95 | |
---|
96 | makeHeader( 'host_view', $title, $longtitle ); |
---|
97 | |
---|
98 | #print_r( $rrdirs); |
---|
99 | |
---|
100 | $metrics = $metrics[$hostname]; |
---|
101 | $mymetrics = array(); |
---|
102 | |
---|
103 | foreach( $rrdirs as $rrdir ) |
---|
104 | { |
---|
105 | #printf("rrd dir %s\n", $rrdir ); |
---|
106 | if( $view == "overview-host" ) |
---|
107 | { |
---|
108 | $mymetrics = $metrics; |
---|
109 | #print_r( $mymetrics ); |
---|
110 | } |
---|
111 | else |
---|
112 | { |
---|
113 | #printf("archive mode\n"); |
---|
114 | $ml = $trd->dirList( $rrdir ); |
---|
115 | |
---|
116 | foreach( $ml as $lmetr ) |
---|
117 | { |
---|
118 | $metrn_fields = explode( '.', $lmetr ); |
---|
119 | |
---|
120 | $metrn = $metrn_fields[0]; |
---|
121 | |
---|
122 | if( !in_array( $metrn, $mymetrics ) ) |
---|
123 | { |
---|
124 | $mymetrics[$metrn] = $metrics[$metrn]; |
---|
125 | } |
---|
126 | } |
---|
127 | } |
---|
128 | } |
---|
129 | |
---|
130 | $hosts_up = $hosts_up[$hostname]; |
---|
131 | |
---|
132 | $tpl_data->assign("cluster", $clustername); |
---|
133 | $tpl_data->assign("host", $hostname); |
---|
134 | $tpl_data->assign("node_image", "../../".node_image($metrics)); |
---|
135 | $tpl_data->assign("sort",$sort); |
---|
136 | $tpl_data->assign("range",$range); |
---|
137 | |
---|
138 | if( !is_numeric( $period_start ) ) |
---|
139 | { |
---|
140 | $period_start = datetimeToEpoch( $period_start ); |
---|
141 | } |
---|
142 | if( !is_numeric( $period_stop ) ) |
---|
143 | { |
---|
144 | $period_stop = datetimeToEpoch( $period_stop ); |
---|
145 | } |
---|
146 | |
---|
147 | if($hosts_up) |
---|
148 | $tpl_data->assign("node_msg", "This host is up and running."); |
---|
149 | else |
---|
150 | $tpl_data->assign("node_msg", "This host is down."); |
---|
151 | |
---|
152 | $cluster_url=rawurlencode($clustername); |
---|
153 | $tpl_data->assign("cluster_url", $cluster_url); |
---|
154 | |
---|
155 | $graphargs = "h=$hostname&r=$range&job_start=$job_start&job_stop=$job_stop"; |
---|
156 | |
---|
157 | if( $range == 'job' ) |
---|
158 | { |
---|
159 | $graphargs .= "&period_start=$period_start&period_stop=$period_stop"; |
---|
160 | } |
---|
161 | else |
---|
162 | { |
---|
163 | $tijd = time(); |
---|
164 | $graphargs .= "&st=$tijd"; |
---|
165 | } |
---|
166 | |
---|
167 | $tpl_data->assign("graphargs", "$graphargs"); |
---|
168 | |
---|
169 | # For the node view link. |
---|
170 | $tpl_data->assign("node_view","./?p=2&c=$cluster_url&h=$hostname"); |
---|
171 | |
---|
172 | $tpl_data->assign("ip", $hosts_up[IP]); |
---|
173 | |
---|
174 | #print_r( $mymetrics ); |
---|
175 | |
---|
176 | foreach ($mymetrics as $name => $v) |
---|
177 | { |
---|
178 | if ($v[TYPE] == "string" or $v[TYPE]=="timestamp" or $always_timestamp[$name]) |
---|
179 | { |
---|
180 | # Long gmetric name/values will disrupt the display here. |
---|
181 | if ($v[SOURCE] == "gmond") $s_metrics[$name] = $v; |
---|
182 | } |
---|
183 | else if ($v[SLOPE] == "zero" or $always_constant[$name]) |
---|
184 | { |
---|
185 | $c_metrics[$name] = $v; |
---|
186 | } |
---|
187 | else if ($reports[$metric]) |
---|
188 | { |
---|
189 | continue; |
---|
190 | } |
---|
191 | else |
---|
192 | { |
---|
193 | $graphargs = "c=$cluster_url&h=$hostname&m=$name&z=overview-medium&r=$range&job_start=$job_start&job_stop=$job_stop"; |
---|
194 | |
---|
195 | if( $range == 'job' ) |
---|
196 | { |
---|
197 | $graphargs .= "&period_start=$period_start&period_stop=$period_stop"; |
---|
198 | } |
---|
199 | else |
---|
200 | { |
---|
201 | $tijd = time(); |
---|
202 | $graphargs .= "&st=$tijd"; |
---|
203 | } |
---|
204 | # Adding units to graph 2003 by Jason Smith <smithj4@bnl.gov>. |
---|
205 | if ($v[UNITS]) |
---|
206 | { |
---|
207 | $encodeUnits = rawurlencode($v[UNITS]); |
---|
208 | $graphargs .= "&vl=$encodeUnits"; |
---|
209 | } |
---|
210 | $g_metrics[$name][graph] = $graphargs; |
---|
211 | } |
---|
212 | } |
---|
213 | # Add the uptime metric for this host. Cannot be done in ganglia.php, |
---|
214 | # since it requires a fully-parsed XML tree. The classic contructor problem. |
---|
215 | $s_metrics[uptime][TYPE] = "string"; |
---|
216 | $s_metrics[uptime][VAL] = uptime($cluster[LOCALTIME] - $metrics[boottime][VAL]); |
---|
217 | |
---|
218 | # Add the gmond started timestamps & last reported time (in uptime format) from |
---|
219 | # the HOST tag: |
---|
220 | $s_metrics[gmond_started][TYPE] = "timestamp"; |
---|
221 | $s_metrics[gmond_started][VAL] = $hosts_up[GMOND_STARTED]; |
---|
222 | $s_metrics[last_reported][TYPE] = "string"; |
---|
223 | $s_metrics[last_reported][VAL] = uptime($cluster[LOCALTIME] - $hosts_up[REPORTED]); |
---|
224 | |
---|
225 | # Show string metrics |
---|
226 | if (is_array($s_metrics)) |
---|
227 | { |
---|
228 | ksort($s_metrics); |
---|
229 | $string_metric_info_loop = array(); |
---|
230 | foreach ($s_metrics as $name => $v ) |
---|
231 | { |
---|
232 | $metric_info = array(); |
---|
233 | $metric_info["name"] = $name; |
---|
234 | if( $v[TYPE]=="timestamp" or $always_timestamp[$name]) |
---|
235 | { |
---|
236 | $metric_info["value"] = date("r", $v[VAL]); |
---|
237 | } |
---|
238 | else |
---|
239 | { |
---|
240 | $metric_info["value"] = "$v[VAL] $v[UNITS]"; |
---|
241 | } |
---|
242 | $string_metric_info_loop[] = $metric_info; |
---|
243 | } |
---|
244 | $tpl_data->assign("string_metric_info", $string_metric_info_loop ); |
---|
245 | } |
---|
246 | |
---|
247 | # Show constant metrics. |
---|
248 | if (is_array($c_metrics)) |
---|
249 | { |
---|
250 | ksort($c_metrics); |
---|
251 | $const_metric_info_loop = array(); |
---|
252 | foreach ($c_metrics as $name => $v ) |
---|
253 | { |
---|
254 | $const_info = array(); |
---|
255 | $const_infp["name"] = $name; |
---|
256 | $const_info["value"] = "$v[VAL] $v[UNITS]"; |
---|
257 | $const_metric_info_loop[] = $const_info; |
---|
258 | } |
---|
259 | $tpl_data->assign("const_metric_info", $const_metric_info_loop ); |
---|
260 | } |
---|
261 | |
---|
262 | # Show graphs. |
---|
263 | if (is_array($g_metrics)) |
---|
264 | { |
---|
265 | ksort($g_metrics); |
---|
266 | $vol_metric_info_loop = array(); |
---|
267 | |
---|
268 | $i = 0; |
---|
269 | foreach ( $g_metrics as $name => $v ) |
---|
270 | { |
---|
271 | $metric_info = array(); |
---|
272 | $metric_info["graphargs"] = $v[graph]; |
---|
273 | $metric_info["alt"] = "$hostname $name"; |
---|
274 | $vol_metric_info_loop[] = $metric_info; |
---|
275 | } |
---|
276 | $tpl_data->assign("vol_metric_info", $vol_metric_info_loop ); |
---|
277 | } |
---|
278 | $dwoo->output($tpl, $tpl_data); |
---|
279 | } |
---|
280 | |
---|
281 | ?> |
---|