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 734 2013-03-24 14:16:58Z ramonb $ |
---|
23 | */ |
---|
24 | |
---|
25 | include_once "./libtoga.php"; |
---|
26 | |
---|
27 | function datetimeToEpoch( $datetime ) |
---|
28 | { |
---|
29 | |
---|
30 | $datetime_fields = explode( ' ', $datetime ); |
---|
31 | |
---|
32 | $date = $datetime_fields[0]; |
---|
33 | $time = $datetime_fields[1]; |
---|
34 | |
---|
35 | $date_fields = explode( '-', $date ); |
---|
36 | |
---|
37 | $days = $date_fields[0]; |
---|
38 | $months = $date_fields[1]; |
---|
39 | $years = $date_fields[2]; |
---|
40 | |
---|
41 | //printf( "days = %s months = %s years = %s\n", $days, $months, $years ); |
---|
42 | |
---|
43 | $time_fields = explode( ':', $time ); |
---|
44 | |
---|
45 | $hours = $time_fields[0]; |
---|
46 | $minutes = $time_fields[1]; |
---|
47 | $seconds = $time_fields[2]; |
---|
48 | |
---|
49 | $timestamp = mktime( $hours, $minutes, $seconds, $months, $days, $years ); |
---|
50 | |
---|
51 | return $timestamp; |
---|
52 | } |
---|
53 | |
---|
54 | function makeHostView() |
---|
55 | { |
---|
56 | |
---|
57 | global $tpl, $metrics, $clustername, $hostname; |
---|
58 | global $cluster_ul, $hosts_up, $get_metric_string; |
---|
59 | global $cluster, $period_start, $period_stop; |
---|
60 | global $job_start, $job_stop, $view, $conf; |
---|
61 | |
---|
62 | $rrdirs = array(); |
---|
63 | if( $view == "overview-host" ) |
---|
64 | { |
---|
65 | $trd = new TarchRrdGraph( $clustername, $hostname ); |
---|
66 | $rrdirs = $trd->getRrdDirs( $period_start, $period_stop ); |
---|
67 | } |
---|
68 | else |
---|
69 | { |
---|
70 | $rrdirs[] = $conf['rrds'] . '/' . $cluster .'/'. $hostname; |
---|
71 | } |
---|
72 | |
---|
73 | $longtitle = "Batch Archive Node Report :: Powered by Job Monarch!"; |
---|
74 | $title = "Batch Archive Node Report"; |
---|
75 | |
---|
76 | makeHeader( 'host_view', $title, $longtitle ); |
---|
77 | |
---|
78 | $metrics = $metrics[$hostname]; |
---|
79 | $mymetrics = array(); |
---|
80 | |
---|
81 | foreach( $rrdirs as $rrdir ) |
---|
82 | { |
---|
83 | $ml = $trd->dirList( $rrdir ); |
---|
84 | |
---|
85 | foreach( $ml as $lmetr ) |
---|
86 | { |
---|
87 | $metrn_fields = explode( '.', $lmetr ); |
---|
88 | |
---|
89 | $metrn = $metrn_fields[0]; |
---|
90 | |
---|
91 | if( !in_array( $metrn, $mymetrics ) ) |
---|
92 | { |
---|
93 | $mymetrics[$metrn] = $metrics[$metrn]; |
---|
94 | } |
---|
95 | } |
---|
96 | } |
---|
97 | |
---|
98 | $hosts_up = $hosts_up[$hostname]; |
---|
99 | |
---|
100 | $tpl->assign("cluster", $clustername); |
---|
101 | $tpl->assign("host", $hostname); |
---|
102 | $tpl->assign("node_image", "../../".node_image($metrics)); |
---|
103 | $tpl->assign("sort",$sort); |
---|
104 | $tpl->assign("range",$range); |
---|
105 | |
---|
106 | if( !is_numeric( $period_start ) ) |
---|
107 | { |
---|
108 | $period_start = datetimeToEpoch( $period_start ); |
---|
109 | } |
---|
110 | if( !is_numeric( $period_stop ) ) |
---|
111 | { |
---|
112 | $period_stop = datetimeToEpoch( $period_stop ); |
---|
113 | } |
---|
114 | |
---|
115 | if($hosts_up) |
---|
116 | $tpl->assign("node_msg", "This host is up and running."); |
---|
117 | else |
---|
118 | $tpl->assign("node_msg", "This host is down."); |
---|
119 | |
---|
120 | $cluster_url=rawurlencode($clustername); |
---|
121 | $tpl->assign("cluster_url", $cluster_url); |
---|
122 | $tpl->assign("graphargs", "h=$hostname&$get_metric_string&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop"); |
---|
123 | |
---|
124 | # For the node view link. |
---|
125 | $tpl->assign("node_view","./?p=2&c=$cluster_url&h=$hostname"); |
---|
126 | |
---|
127 | $tpl->assign("ip", $hosts_up[IP]); |
---|
128 | |
---|
129 | foreach ($mymetrics as $name => $v) |
---|
130 | { |
---|
131 | if ($v[TYPE] == "string" or $v[TYPE]=="timestamp" or $always_timestamp[$name]) |
---|
132 | { |
---|
133 | # Long gmetric name/values will disrupt the display here. |
---|
134 | if ($v[SOURCE] == "gmond") $s_metrics[$name] = $v; |
---|
135 | } |
---|
136 | elseif ($v[SLOPE] == "zero" or $always_constant[$name]) |
---|
137 | { |
---|
138 | $c_metrics[$name] = $v; |
---|
139 | } |
---|
140 | else if ($reports[$metric]) |
---|
141 | { |
---|
142 | continue; |
---|
143 | } |
---|
144 | else |
---|
145 | { |
---|
146 | $graphargs = "c=$cluster_url&h=$hostname&m=$name" |
---|
147 | ."&z=medium&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop"; |
---|
148 | # Adding units to graph 2003 by Jason Smith <smithj4@bnl.gov>. |
---|
149 | if ($v[UNITS]) |
---|
150 | { |
---|
151 | $encodeUnits = rawurlencode($v[UNITS]); |
---|
152 | $graphargs .= "&vl=$encodeUnits"; |
---|
153 | } |
---|
154 | $g_metrics[$name][graph] = $graphargs; |
---|
155 | } |
---|
156 | } |
---|
157 | # Add the uptime metric for this host. Cannot be done in ganglia.php, |
---|
158 | # since it requires a fully-parsed XML tree. The classic contructor problem. |
---|
159 | $s_metrics[uptime][TYPE] = "string"; |
---|
160 | $s_metrics[uptime][VAL] = uptime($cluster[LOCALTIME] - $metrics[boottime][VAL]); |
---|
161 | |
---|
162 | # Add the gmond started timestamps & last reported time (in uptime format) from |
---|
163 | # the HOST tag: |
---|
164 | $s_metrics[gmond_started][TYPE] = "timestamp"; |
---|
165 | $s_metrics[gmond_started][VAL] = $hosts_up[GMOND_STARTED]; |
---|
166 | $s_metrics[last_reported][TYPE] = "string"; |
---|
167 | $s_metrics[last_reported][VAL] = uptime($cluster[LOCALTIME] - $hosts_up[REPORTED]); |
---|
168 | |
---|
169 | # Show string metrics |
---|
170 | if (is_array($s_metrics)) |
---|
171 | { |
---|
172 | ksort($s_metrics); |
---|
173 | foreach ($s_metrics as $name => $v ) |
---|
174 | { |
---|
175 | $tpl->newBlock("string_metric_info"); |
---|
176 | $tpl->assign("name", $name); |
---|
177 | if( $v[TYPE]=="timestamp" or $always_timestamp[$name]) |
---|
178 | { |
---|
179 | $tpl->assign("value", date("r", $v[VAL])); |
---|
180 | } |
---|
181 | else |
---|
182 | { |
---|
183 | $tpl->assign("value", "$v[VAL] $v[UNITS]"); |
---|
184 | } |
---|
185 | } |
---|
186 | } |
---|
187 | |
---|
188 | # Show constant metrics. |
---|
189 | if (is_array($c_metrics)) |
---|
190 | { |
---|
191 | ksort($c_metrics); |
---|
192 | foreach ($c_metrics as $name => $v ) |
---|
193 | { |
---|
194 | $tpl->newBlock("const_metric_info"); |
---|
195 | $tpl->assign("name", $name); |
---|
196 | $tpl->assign("value", "$v[VAL] $v[UNITS]"); |
---|
197 | } |
---|
198 | } |
---|
199 | |
---|
200 | # Show graphs. |
---|
201 | if (is_array($g_metrics)) |
---|
202 | { |
---|
203 | ksort($g_metrics); |
---|
204 | |
---|
205 | $i = 0; |
---|
206 | foreach ( $g_metrics as $name => $v ) |
---|
207 | { |
---|
208 | $tpl->newBlock("vol_metric_info"); |
---|
209 | $tpl->assign("graphargs", $v[graph]); |
---|
210 | $tpl->assign("alt", "$hostname $name"); |
---|
211 | if($i++ %2) |
---|
212 | { |
---|
213 | $tpl->assign("br", "<BR>"); |
---|
214 | } |
---|
215 | } |
---|
216 | } |
---|
217 | } |
---|
218 | |
---|
219 | ?> |
---|