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 762 2013-03-27 20:27:01Z ramonb $ |
---|
23 | */ |
---|
24 | |
---|
25 | include_once "./libtoga.php"; |
---|
26 | |
---|
27 | if( $view == "overview-host" ) |
---|
28 | { |
---|
29 | $my_dir = getcwd(); |
---|
30 | |
---|
31 | global $context; |
---|
32 | |
---|
33 | $context = 'cluster'; |
---|
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 | unset( $mymetrics['last_reported_timestamp'] ); // Ganglia bug? |
---|
110 | #print_r( $mymetrics ); |
---|
111 | } |
---|
112 | else |
---|
113 | { |
---|
114 | #printf("archive mode\n"); |
---|
115 | $ml = $trd->dirList( $rrdir ); |
---|
116 | |
---|
117 | foreach( $ml as $lmetr ) |
---|
118 | { |
---|
119 | $metrn_fields = explode( '.', $lmetr ); |
---|
120 | |
---|
121 | $metrn = $metrn_fields[0]; |
---|
122 | |
---|
123 | if( !in_array( $metrn, $mymetrics ) ) |
---|
124 | { |
---|
125 | $mymetrics[$metrn] = $metrics[$metrn]; |
---|
126 | } |
---|
127 | } |
---|
128 | } |
---|
129 | } |
---|
130 | |
---|
131 | $hosts_up = $hosts_up[$hostname]; |
---|
132 | |
---|
133 | $tpl_data->assign("cluster", $clustername); |
---|
134 | $tpl_data->assign("host", $hostname); |
---|
135 | $tpl_data->assign("node_image", "../../".node_image($metrics)); |
---|
136 | $tpl_data->assign("sort",$sort); |
---|
137 | $tpl_data->assign("range",$range); |
---|
138 | |
---|
139 | if( !is_numeric( $period_start ) ) |
---|
140 | { |
---|
141 | $period_start = datetimeToEpoch( $period_start ); |
---|
142 | } |
---|
143 | if( !is_numeric( $period_stop ) ) |
---|
144 | { |
---|
145 | $period_stop = datetimeToEpoch( $period_stop ); |
---|
146 | } |
---|
147 | |
---|
148 | if($hosts_up) |
---|
149 | $tpl_data->assign("node_msg", "This host is up and running."); |
---|
150 | else |
---|
151 | $tpl_data->assign("node_msg", "This host is down."); |
---|
152 | |
---|
153 | $cluster_url=rawurlencode($clustername); |
---|
154 | $tpl_data->assign("cluster_url", $cluster_url); |
---|
155 | |
---|
156 | $graphargs = "h=$hostname&r=$range&job_start=$job_start&job_stop=$job_stop"; |
---|
157 | |
---|
158 | if( $range == 'job' ) |
---|
159 | { |
---|
160 | $graphargs .= "&period_start=$period_start&period_stop=$period_stop"; |
---|
161 | } |
---|
162 | else |
---|
163 | { |
---|
164 | $tijd = time(); |
---|
165 | $graphargs .= "&st=$tijd"; |
---|
166 | } |
---|
167 | |
---|
168 | $tpl_data->assign("graphargs", "$graphargs"); |
---|
169 | |
---|
170 | # For the node view link. |
---|
171 | $tpl_data->assign("node_view","./?p=2&c=$cluster_url&h=$hostname"); |
---|
172 | |
---|
173 | $tpl_data->assign("ip", $hosts_up['IP']); |
---|
174 | |
---|
175 | #print_r( $mymetrics ); |
---|
176 | |
---|
177 | foreach ($mymetrics as $name => $v) |
---|
178 | { |
---|
179 | if ($v['TYPE'] == "string" or $v['TYPE']=="timestamp" or $always_timestamp[$name] or $v['NAME']=='last_reported_timestamp') |
---|
180 | { |
---|
181 | # Long gmetric name/values will disrupt the display here. |
---|
182 | if ($v['SOURCE'] == "gmond") $s_metrics[$name] = $v; |
---|
183 | } |
---|
184 | else if ($v['SLOPE'] == "zero" or $always_constant[$name]) |
---|
185 | { |
---|
186 | $c_metrics[$name] = $v; |
---|
187 | } |
---|
188 | else if ($reports[$metric]) |
---|
189 | { |
---|
190 | continue; |
---|
191 | } |
---|
192 | else |
---|
193 | { |
---|
194 | $graphargs = "c=$cluster_url&h=$hostname&m=$name&z=overview-medium&r=$range&job_start=$job_start&job_stop=$job_stop"; |
---|
195 | |
---|
196 | if( $range == 'job' ) |
---|
197 | { |
---|
198 | $graphargs .= "&period_start=$period_start&period_stop=$period_stop"; |
---|
199 | } |
---|
200 | else |
---|
201 | { |
---|
202 | $tijd = time(); |
---|
203 | $graphargs .= "&st=$tijd"; |
---|
204 | } |
---|
205 | # Adding units to graph 2003 by Jason Smith <smithj4@bnl.gov>. |
---|
206 | if ($v['UNITS']) |
---|
207 | { |
---|
208 | $encodeUnits = rawurlencode($v['UNITS']); |
---|
209 | $graphargs .= "&vl=$encodeUnits"; |
---|
210 | } |
---|
211 | $g_metrics[$name]['graph'] = $graphargs; |
---|
212 | } |
---|
213 | } |
---|
214 | # Add the uptime metric for this host. Cannot be done in ganglia.php, |
---|
215 | # since it requires a fully-parsed XML tree. The classic contructor problem. |
---|
216 | $s_metrics['uptime']['TYPE'] = "string"; |
---|
217 | $s_metrics['uptime']['VAL'] = uptime($cluster['LOCALTIME'] - $metrics['boottime']['VAL']); |
---|
218 | |
---|
219 | # Add the gmond started timestamps & last reported time (in uptime format) from |
---|
220 | # the HOST tag: |
---|
221 | $s_metrics['gmond_started']['TYPE'] = "timestamp"; |
---|
222 | $s_metrics['gmond_started']['VAL'] = $hosts_up['GMOND_STARTED']; |
---|
223 | $s_metrics['last_reported']['TYPE'] = "string"; |
---|
224 | $s_metrics['last_reported']['VAL'] = uptime($cluster['LOCALTIME'] - $hosts_up['REPORTED']); |
---|
225 | |
---|
226 | # Show string metrics |
---|
227 | if (is_array($s_metrics)) |
---|
228 | { |
---|
229 | ksort($s_metrics); |
---|
230 | $string_metric_info_loop = array(); |
---|
231 | foreach ($s_metrics as $name => $v ) |
---|
232 | { |
---|
233 | $metric_info = array(); |
---|
234 | $metric_info["name"] = $name; |
---|
235 | if( $v['TYPE']=="timestamp" or $always_timestamp[$name]) |
---|
236 | { |
---|
237 | $metric_info["value"] = date("r", $v['VAL']); |
---|
238 | } |
---|
239 | else |
---|
240 | { |
---|
241 | $metric_info["value"] = $v['VAL']." ". $v['UNITS']; |
---|
242 | } |
---|
243 | $string_metric_info_loop[] = $metric_info; |
---|
244 | } |
---|
245 | $tpl_data->assign("string_metric_info", $string_metric_info_loop ); |
---|
246 | } |
---|
247 | |
---|
248 | # Show constant metrics. |
---|
249 | if (is_array($c_metrics)) |
---|
250 | { |
---|
251 | ksort($c_metrics); |
---|
252 | $const_metric_info_loop = array(); |
---|
253 | foreach ($c_metrics as $name => $v ) |
---|
254 | { |
---|
255 | $const_info = array(); |
---|
256 | $const_infp["name"] = $name; |
---|
257 | $const_info["value"] = $v[VAL]." ". $v[UNITS]; |
---|
258 | $const_metric_info_loop[] = $const_info; |
---|
259 | } |
---|
260 | $tpl_data->assign("const_metric_info", $const_metric_info_loop ); |
---|
261 | } |
---|
262 | |
---|
263 | # Show graphs. |
---|
264 | if (is_array($g_metrics)) |
---|
265 | { |
---|
266 | ksort($g_metrics); |
---|
267 | $vol_metric_info_loop = array(); |
---|
268 | |
---|
269 | $i = 0; |
---|
270 | foreach ( $g_metrics as $name => $v ) |
---|
271 | { |
---|
272 | $metric_info = array(); |
---|
273 | $metric_info["graphargs"] = $v['graph']; |
---|
274 | $metric_info["alt"] = "$hostname $name"; |
---|
275 | $vol_metric_info_loop[] = $metric_info; |
---|
276 | } |
---|
277 | $tpl_data->assign("vol_metric_info", $vol_metric_info_loop ); |
---|
278 | } |
---|
279 | $dwoo->output($tpl, $tpl_data); |
---|
280 | } |
---|
281 | |
---|
282 | ?> |
---|