1 | <?php |
---|
2 | |
---|
3 | global $clustername, $tpl; |
---|
4 | |
---|
5 | function validateFormInput() { |
---|
6 | global $clustername, $tpl, $id, $user, $name, $start_from_time, $start_to_time, $queue; |
---|
7 | global $end_from_time, $end_to_time; |
---|
8 | |
---|
9 | $error = 0; |
---|
10 | |
---|
11 | $none_set = 0; |
---|
12 | |
---|
13 | //if( $id == '' or $user == '' or $name == '' or $start_from_time == '' or $start_to_time == '' or $queue == '' or $end_from_time == '' or $end_to_time == '') $none_set = 1; |
---|
14 | |
---|
15 | //if (!isset($id) and !isset($user) and !isset($start_from_time) and !isset($start_to_time) and !isset($end_from_time) and !isset($end_to_time) and !isset($queue) ) $none_set = 0; |
---|
16 | |
---|
17 | if( $none_set ) { |
---|
18 | $error = 1; |
---|
19 | $error_msg = "<FONT COLOR=\"red\"><B>No search criteria set!</B></FONT>"; |
---|
20 | } |
---|
21 | |
---|
22 | // doe checks en set error en error_msg in case shit |
---|
23 | |
---|
24 | if( $error) { |
---|
25 | $tpl->assign( "form_error_msg", $error_msg ); |
---|
26 | return 0; |
---|
27 | } else { |
---|
28 | return 1; |
---|
29 | } |
---|
30 | } |
---|
31 | |
---|
32 | function makeTime( $time ) { |
---|
33 | |
---|
34 | $days = intval( $time / 86400 ); |
---|
35 | $time = ($days>0) ? $time % ($days * 86400) : $time; |
---|
36 | |
---|
37 | //printf( "time = %s, days = %s\n", $time, $days ); |
---|
38 | |
---|
39 | $date_str = ''; |
---|
40 | $day_str = ''; |
---|
41 | |
---|
42 | if( $days > 0 ) { |
---|
43 | if( $days > 1 ) |
---|
44 | $day_str .= $days . ' days'; |
---|
45 | else |
---|
46 | $day_str .= $days . ' day'; |
---|
47 | } |
---|
48 | |
---|
49 | $hours = intval( $time / 3600 ); |
---|
50 | $time = $hours ? $time % ($hours * 3600) : $time; |
---|
51 | |
---|
52 | //printf( "time = %s, days = %s, hours = %s\n", $time, $days, $hours ); |
---|
53 | |
---|
54 | if( $hours > 0 ) { |
---|
55 | $date_str .= $hours . ':'; |
---|
56 | $date_unit = 'hours'; |
---|
57 | } |
---|
58 | |
---|
59 | $minutes = intval( $time / 60 ); |
---|
60 | $seconds = $minutes ? $time % ($minutes * 60) : $time; |
---|
61 | |
---|
62 | if( $minutes > 0 ) { |
---|
63 | |
---|
64 | if( $minutes >= 10 ) |
---|
65 | $date_str .= $minutes . ':'; |
---|
66 | else |
---|
67 | $date_str .= '0' . $minutes . ':'; |
---|
68 | |
---|
69 | $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit; |
---|
70 | } else { |
---|
71 | if($hours > 0 ) { |
---|
72 | $date_str .= '00:'; |
---|
73 | $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit; |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | |
---|
78 | $date_unit = (!isset($date_unit)) ? 'seconds' : $date_unit; |
---|
79 | |
---|
80 | if( $seconds > 0 ) { |
---|
81 | |
---|
82 | if( $seconds >= 10 ) |
---|
83 | $date_str .= $seconds . ' ' . $date_unit; |
---|
84 | else |
---|
85 | $date_str .= '0' . $seconds . ' ' . $date_unit; |
---|
86 | |
---|
87 | } else if ( $hours > 0 or $minutes > 0 ) |
---|
88 | |
---|
89 | $date_str .= '00 ' . $date_unit; |
---|
90 | |
---|
91 | if( $days > 0) { |
---|
92 | |
---|
93 | if( $hours > 0 or $minutes > 0 or $seconds > 0 ) |
---|
94 | $date_str = $day_str . ' - ' . $date_str; |
---|
95 | else |
---|
96 | $date_str = $day_str; |
---|
97 | } |
---|
98 | |
---|
99 | return $date_str; |
---|
100 | } |
---|
101 | |
---|
102 | function makeDate( $time ) { |
---|
103 | return strftime( "%a %d %b %Y %H:%M:%S", $time ); |
---|
104 | } |
---|
105 | |
---|
106 | function datetimeToEpoch( $datetime ) { |
---|
107 | |
---|
108 | $datetime_fields = explode( ' ', $datetime ); |
---|
109 | |
---|
110 | $date = $datetime_fields[0]; |
---|
111 | $time = $datetime_fields[1]; |
---|
112 | |
---|
113 | $date_fields = explode( '-', $date ); |
---|
114 | |
---|
115 | $days = $date_fields[0]; |
---|
116 | $months = $date_fields[1]; |
---|
117 | $years = $date_fields[2]; |
---|
118 | |
---|
119 | $time_fields = explode( ':', $time ); |
---|
120 | |
---|
121 | $hours = $time_fields[0]; |
---|
122 | $minutes = $time_fields[1]; |
---|
123 | $seconds = $time_fields[2]; |
---|
124 | |
---|
125 | $timestamp = mktime( $hours, $minutes, $seconds, $months, $days, $years ); |
---|
126 | |
---|
127 | return $timestamp; |
---|
128 | } |
---|
129 | |
---|
130 | function timeToEpoch( $time ) { |
---|
131 | |
---|
132 | $time_fields = explode( ':', $time ); |
---|
133 | |
---|
134 | if( count($time_fields) == 3 ) { |
---|
135 | |
---|
136 | $hours = $time_fields[0]; |
---|
137 | $minutes = $time_fields[1]; |
---|
138 | $seconds = $time_fields[2]; |
---|
139 | |
---|
140 | } else if( count($time_fields) == 2 ) { |
---|
141 | |
---|
142 | $hours = 0; |
---|
143 | $minutes = $time_fields[0]; |
---|
144 | $seconds = $time_fields[1]; |
---|
145 | |
---|
146 | } else if( count($time_fields) == 1 ) { |
---|
147 | |
---|
148 | $hours = 0; |
---|
149 | $minutes = 0; |
---|
150 | $seconds = $time_fields[0]; |
---|
151 | } |
---|
152 | |
---|
153 | $myepoch = intval( $seconds + (intval( $minutes * 60 )) + (intval( $hours * 3600 )) ); |
---|
154 | |
---|
155 | return $myepoch; |
---|
156 | } |
---|
157 | |
---|
158 | function makeSearchPage() { |
---|
159 | global $clustername, $tpl, $id, $user, $name, $start_from_time, $start_to_time, $queue; |
---|
160 | global $end_from_time, $end_to_time, $filter, $default_showhosts, $m, $hosts_up; |
---|
161 | |
---|
162 | $metricname = $m; |
---|
163 | |
---|
164 | $tpl->assign( "cluster", $clustername ); |
---|
165 | $tpl->assign( "id_value", $id ); |
---|
166 | $tpl->assign( "user_value", $user ); |
---|
167 | $tpl->assign( "queue_value", $queue ); |
---|
168 | $tpl->assign( "name_value", $name ); |
---|
169 | $tpl->assign( "start_from_value", rawurldecode( $start_from_time ) ); |
---|
170 | $tpl->assign( "start_to_value", rawurldecode( $start_to_time ) ); |
---|
171 | $tpl->assign( "end_from_value", rawurldecode( $end_from_time ) ); |
---|
172 | $tpl->assign( "end_to_value", rawurldecode( $end_to_time ) ); |
---|
173 | |
---|
174 | if( validateFormInput() ) { |
---|
175 | |
---|
176 | $tpl->newBlock( "search_results" ); |
---|
177 | $tdb = new TarchDbase(); |
---|
178 | if( $start_from_time ) $start_from_time = datetimeToEpoch( $start_from_time ); |
---|
179 | if( $start_to_time ) $start_to_time = datetimeToEpoch( $start_to_time ); |
---|
180 | if( $end_from_time ) $end_from_time = datetimeToEpoch( $end_from_time ); |
---|
181 | if( $end_to_time ) $end_to_time = datetimeToEpoch( $end_to_time ); |
---|
182 | $search_ids = $tdb->searchDbase( $id, $queue, $user, $name, $start_from_time, $start_to_time, $end_from_time, $end_to_time ); |
---|
183 | |
---|
184 | foreach( $search_ids as $foundid ) { |
---|
185 | |
---|
186 | $job = $tdb->getJobArray( $foundid ); |
---|
187 | $nodes = $tdb->getNodesForJob( $foundid ); |
---|
188 | |
---|
189 | $tpl->newBlock( "node" ); |
---|
190 | $tpl->assign( "id", $job[id] ); |
---|
191 | $tpl->assign( "state", $job[status] ); |
---|
192 | $tpl->assign( "user", $job[owner] ); |
---|
193 | $tpl->assign( "queue", $job[queue] ); |
---|
194 | $tpl->assign( "name", $job[name] ); |
---|
195 | $tpl->assign( "req_cpu", makeTime( TimeToEpoch( $job[requested_time] ) ) ); |
---|
196 | $tpl->assign( "req_memory", $job[requested_memory] ); |
---|
197 | |
---|
198 | $nodes_nr = count( $nodes ); |
---|
199 | $domain = $job[domain]; |
---|
200 | $ppn = (int) $job[ppn] ? $job[ppn] : 1; |
---|
201 | $cpus = $nodes_nr * $ppn; |
---|
202 | |
---|
203 | $tpl->assign( "nodes", $nodes_nr ); |
---|
204 | $tpl->assign( "cpus", $cpus ); |
---|
205 | |
---|
206 | $runningtime = intval( $job[stop_timestamp] - $job[start_timestamp] ); |
---|
207 | $tpl->assign( "started", makeDate( $job[start_timestamp] ) ); |
---|
208 | $tpl->assign( "finished", makeDate( $job[stop_timestamp] ) ); |
---|
209 | $tpl->assign( "runningtime", makeTime( $runningtime ) ); |
---|
210 | |
---|
211 | //print_r( $job ); |
---|
212 | //print_r( $nodes ); |
---|
213 | } |
---|
214 | |
---|
215 | |
---|
216 | if( count( $search_ids ) == 1 ) { |
---|
217 | |
---|
218 | $tpl->newBlock( "showhosts" ); |
---|
219 | |
---|
220 | $showhosts = isset($sh) ? $sh : $default_showhosts; |
---|
221 | //if( !$showhosts) $showhosts = $default_showhosts; |
---|
222 | $tpl->assign("checked$showhosts", "checked"); |
---|
223 | |
---|
224 | # Present a width list |
---|
225 | $cols_menu = "<SELECT NAME=\"hc\" OnChange=\"toga_form.submit();\">\n"; |
---|
226 | |
---|
227 | $hostcols = ($hc) ? $hc : 4; |
---|
228 | |
---|
229 | foreach(range(1,25) as $cols) { |
---|
230 | $cols_menu .= "<OPTION VALUE=$cols "; |
---|
231 | if ($cols == $hostcols) |
---|
232 | $cols_menu .= "SELECTED"; |
---|
233 | $cols_menu .= ">$cols\n"; |
---|
234 | } |
---|
235 | $cols_menu .= "</SELECT>\n"; |
---|
236 | |
---|
237 | $tpl->assign("metric","$metricname $units"); |
---|
238 | $tpl->assign("id", $id); |
---|
239 | # Host columns menu defined in header.php |
---|
240 | $tpl->assign("cols_menu", $cols_menu); |
---|
241 | |
---|
242 | if( $showhosts ) { |
---|
243 | //bla |
---|
244 | |
---|
245 | if( !isset($start) ) $start="jobstart"; |
---|
246 | if( !isset($stop) ) $stop="now"; |
---|
247 | //$tpl->assign("start", $start); |
---|
248 | //$tpl->assign("stop", $stop); |
---|
249 | |
---|
250 | $sorted_hosts = array(); |
---|
251 | $hosts_up = $jobs[$filter[id]][nodes]; |
---|
252 | |
---|
253 | $r = intval($job_runningtime * 1.25); |
---|
254 | |
---|
255 | $jobrange = ($job_runningtime < 3600) ? -3600 : -$r ; |
---|
256 | $jobstart = $report_time - $job_runningtime; |
---|
257 | |
---|
258 | if ($reports[$metricname]) |
---|
259 | $metricval = "g"; |
---|
260 | else |
---|
261 | $metricval = "m"; |
---|
262 | |
---|
263 | foreach ($hosts_up as $host ) { |
---|
264 | $host = $host. '.'.$domain; |
---|
265 | $cpus = $metrics[$host]["cpu_num"][VAL]; |
---|
266 | if (!$cpus) $cpus=1; |
---|
267 | $load_one = $metrics[$host]["load_one"][VAL]; |
---|
268 | $load = ((float) $load_one)/$cpus; |
---|
269 | $host_load[$host] = $load; |
---|
270 | $percent_hosts[load_color($load)] += 1; |
---|
271 | if ($metricname=="load_one") |
---|
272 | $sorted_hosts[$host] = $load; |
---|
273 | else |
---|
274 | $sorted_hosts[$host] = $metrics[$host][$metricname][VAL]; |
---|
275 | } |
---|
276 | switch ($sort) { |
---|
277 | case "descending": |
---|
278 | arsort($sorted_hosts); |
---|
279 | break; |
---|
280 | case "by hostname": |
---|
281 | ksort($sorted_hosts); |
---|
282 | break; |
---|
283 | default: |
---|
284 | case "ascending": |
---|
285 | asort($sorted_hosts); |
---|
286 | break; |
---|
287 | } |
---|
288 | |
---|
289 | //$sorted_hosts = array_merge($down_hosts, $sorted_hosts); |
---|
290 | |
---|
291 | # First pass to find the max value in all graphs for this |
---|
292 | # metric. The $start,$end variables comes from get_context.php, |
---|
293 | # included in index.php. |
---|
294 | list($min, $max) = find_limits($sorted_hosts, $metricname); |
---|
295 | |
---|
296 | # Second pass to output the graphs or metrics. |
---|
297 | $i = 1; |
---|
298 | foreach ( $sorted_hosts as $host=>$value ) { |
---|
299 | $tpl->newBlock ("sorted_list"); |
---|
300 | //$host = $host. '.'.$domain; |
---|
301 | $host_url = rawurlencode($host); |
---|
302 | $cluster_url = rawurlencode($clustername); |
---|
303 | |
---|
304 | $textval = ""; |
---|
305 | //printf("host = %s, value = %s", $host, $value); |
---|
306 | //echo "$host: $value, "; |
---|
307 | $val = $metrics[$host][$metricname]; |
---|
308 | $class = "metric"; |
---|
309 | $host_link="\"?c=$cluster_url&h=$host_url&r=job&jr=$jobrange&js=$jobstart\""; |
---|
310 | |
---|
311 | if ($val[TYPE]=="timestamp" or $always_timestamp[$metricname]) { |
---|
312 | $textval = date("r", $val[VAL]); |
---|
313 | } elseif ($val[TYPE]=="string" or $val[SLOPE]=="zero" or $always_constant[$metricname] or ($max_graphs > 0 and $i > $max_graphs )) { |
---|
314 | $textval = "$val[VAL] $val[UNITS]"; |
---|
315 | } else { |
---|
316 | $load_color = load_color($host_load[$host]); |
---|
317 | $graphargs = ($reports[$metricname]) ? "g=$metricname&" : "m=$metricname&"; |
---|
318 | $graphargs .= "z=small&c=$cluster_url&h=$host_url&l=$load_color" ."&v=$val[VAL]&x=$max&n=$min&r=job&jr=$jobrange&js=$jobstart"; |
---|
319 | } |
---|
320 | if ($textval) { |
---|
321 | $cell="<td class=$class>". "<b><a href=$host_link>$host</a></b><br>". "<i>$metricname:</i> <b>$textval</b></td>"; |
---|
322 | } else { |
---|
323 | $cell="<td><a href=$host_link>". "<img src=\"../../graph.php?$graphargs\" ". "alt=\"$host\" height=112 width=225 border=0></a></td>"; |
---|
324 | } |
---|
325 | |
---|
326 | $tpl->assign("metric_image", $cell); |
---|
327 | if (! ($i++ % $hostcols) ) |
---|
328 | $tpl->assign ("br", "</tr><tr>"); |
---|
329 | } |
---|
330 | |
---|
331 | //einde bla |
---|
332 | } |
---|
333 | } |
---|
334 | |
---|
335 | } |
---|
336 | } |
---|
337 | ?> |
---|