[130] | 1 | <?php |
---|
| 2 | |
---|
| 3 | global $clustername, $tpl; |
---|
| 4 | |
---|
[138] | 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 | |
---|
[150] | 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; |
---|
[138] | 14 | |
---|
[150] | 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 = 1; |
---|
[138] | 16 | |
---|
[150] | 17 | if( $none_set == 1 ) { |
---|
[138] | 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 | |
---|
[141] | 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 | |
---|
[142] | 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 | |
---|
[145] | 130 | function epochToDatetime( $epoch ) { |
---|
| 131 | |
---|
| 132 | return strftime( "%d-%m-%Y %H:%M:%S", $epoch ); |
---|
| 133 | } |
---|
| 134 | |
---|
[141] | 135 | function timeToEpoch( $time ) { |
---|
| 136 | |
---|
| 137 | $time_fields = explode( ':', $time ); |
---|
| 138 | |
---|
| 139 | if( count($time_fields) == 3 ) { |
---|
| 140 | |
---|
| 141 | $hours = $time_fields[0]; |
---|
| 142 | $minutes = $time_fields[1]; |
---|
| 143 | $seconds = $time_fields[2]; |
---|
| 144 | |
---|
| 145 | } else if( count($time_fields) == 2 ) { |
---|
| 146 | |
---|
| 147 | $hours = 0; |
---|
| 148 | $minutes = $time_fields[0]; |
---|
| 149 | $seconds = $time_fields[1]; |
---|
| 150 | |
---|
| 151 | } else if( count($time_fields) == 1 ) { |
---|
| 152 | |
---|
| 153 | $hours = 0; |
---|
| 154 | $minutes = 0; |
---|
| 155 | $seconds = $time_fields[0]; |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | $myepoch = intval( $seconds + (intval( $minutes * 60 )) + (intval( $hours * 3600 )) ); |
---|
| 159 | |
---|
| 160 | return $myepoch; |
---|
| 161 | } |
---|
| 162 | |
---|
[130] | 163 | function makeSearchPage() { |
---|
[138] | 164 | global $clustername, $tpl, $id, $user, $name, $start_from_time, $start_to_time, $queue; |
---|
[143] | 165 | global $end_from_time, $end_to_time, $filter, $default_showhosts, $m, $hosts_up; |
---|
[149] | 166 | global $period_start, $period_stop; |
---|
[130] | 167 | |
---|
[143] | 168 | $metricname = $m; |
---|
[145] | 169 | //printf("job_start = %s job_stop = %s\n", $job_start, $job_stop ); |
---|
| 170 | //printf("start = %s stop = %s\n", $start, $stop ); |
---|
[143] | 171 | |
---|
[138] | 172 | $tpl->assign( "cluster", $clustername ); |
---|
| 173 | $tpl->assign( "id_value", $id ); |
---|
| 174 | $tpl->assign( "user_value", $user ); |
---|
| 175 | $tpl->assign( "queue_value", $queue ); |
---|
| 176 | $tpl->assign( "name_value", $name ); |
---|
| 177 | $tpl->assign( "start_from_value", rawurldecode( $start_from_time ) ); |
---|
| 178 | $tpl->assign( "start_to_value", rawurldecode( $start_to_time ) ); |
---|
| 179 | $tpl->assign( "end_from_value", rawurldecode( $end_from_time ) ); |
---|
| 180 | $tpl->assign( "end_to_value", rawurldecode( $end_to_time ) ); |
---|
| 181 | |
---|
| 182 | if( validateFormInput() ) { |
---|
| 183 | |
---|
[140] | 184 | $tpl->newBlock( "search_results" ); |
---|
[138] | 185 | $tdb = new TarchDbase(); |
---|
[142] | 186 | if( $start_from_time ) $start_from_time = datetimeToEpoch( $start_from_time ); |
---|
| 187 | if( $start_to_time ) $start_to_time = datetimeToEpoch( $start_to_time ); |
---|
| 188 | if( $end_from_time ) $end_from_time = datetimeToEpoch( $end_from_time ); |
---|
| 189 | if( $end_to_time ) $end_to_time = datetimeToEpoch( $end_to_time ); |
---|
[140] | 190 | $search_ids = $tdb->searchDbase( $id, $queue, $user, $name, $start_from_time, $start_to_time, $end_from_time, $end_to_time ); |
---|
[138] | 191 | |
---|
[140] | 192 | foreach( $search_ids as $foundid ) { |
---|
| 193 | |
---|
[141] | 194 | $job = $tdb->getJobArray( $foundid ); |
---|
| 195 | $nodes = $tdb->getNodesForJob( $foundid ); |
---|
| 196 | |
---|
| 197 | $tpl->newBlock( "node" ); |
---|
| 198 | $tpl->assign( "id", $job[id] ); |
---|
| 199 | $tpl->assign( "state", $job[status] ); |
---|
| 200 | $tpl->assign( "user", $job[owner] ); |
---|
| 201 | $tpl->assign( "queue", $job[queue] ); |
---|
| 202 | $tpl->assign( "name", $job[name] ); |
---|
| 203 | $tpl->assign( "req_cpu", makeTime( TimeToEpoch( $job[requested_time] ) ) ); |
---|
| 204 | $tpl->assign( "req_memory", $job[requested_memory] ); |
---|
| 205 | |
---|
| 206 | $nodes_nr = count( $nodes ); |
---|
[145] | 207 | |
---|
| 208 | // need to replace later with domain stored from dbase |
---|
| 209 | // |
---|
| 210 | //$job_domain = $job[domain]; |
---|
| 211 | |
---|
| 212 | $myhost = $_SERVER[HTTP_HOST]; |
---|
| 213 | $myhf = explode( '.', $myhost ); |
---|
| 214 | $myhf = array_reverse( $myhf ); |
---|
| 215 | array_pop( $myhf ); |
---|
| 216 | $myhf = array_reverse( $myhf ); |
---|
| 217 | $job_domain = implode( '.', $myhf ); |
---|
| 218 | |
---|
| 219 | //print_r( $job ); |
---|
| 220 | //printf( "job domain = %s\n", $job_domain); |
---|
[141] | 221 | $ppn = (int) $job[ppn] ? $job[ppn] : 1; |
---|
| 222 | $cpus = $nodes_nr * $ppn; |
---|
| 223 | |
---|
| 224 | $tpl->assign( "nodes", $nodes_nr ); |
---|
| 225 | $tpl->assign( "cpus", $cpus ); |
---|
| 226 | |
---|
[145] | 227 | $job_start = $job[start_timestamp]; |
---|
| 228 | $job_stop = $job[stop_timestamp]; |
---|
| 229 | $runningtime = intval( $job_stop - $job_start ); |
---|
| 230 | $tpl->assign( "started", makeDate( $job_start ) ); |
---|
| 231 | $tpl->assign( "finished", makeDate( $job_stop ) ); |
---|
[141] | 232 | $tpl->assign( "runningtime", makeTime( $runningtime ) ); |
---|
| 233 | |
---|
[143] | 234 | //print_r( $job ); |
---|
| 235 | //print_r( $nodes ); |
---|
| 236 | } |
---|
[140] | 237 | |
---|
| 238 | |
---|
| 239 | if( count( $search_ids ) == 1 ) { |
---|
| 240 | |
---|
| 241 | $tpl->newBlock( "showhosts" ); |
---|
[143] | 242 | |
---|
| 243 | $showhosts = isset($sh) ? $sh : $default_showhosts; |
---|
| 244 | //if( !$showhosts) $showhosts = $default_showhosts; |
---|
| 245 | $tpl->assign("checked$showhosts", "checked"); |
---|
| 246 | |
---|
| 247 | # Present a width list |
---|
[145] | 248 | $cols_menu = "<SELECT NAME=\"hc\" OnChange=\"archive_search_form.submit();\">\n"; |
---|
[143] | 249 | |
---|
| 250 | $hostcols = ($hc) ? $hc : 4; |
---|
| 251 | |
---|
| 252 | foreach(range(1,25) as $cols) { |
---|
| 253 | $cols_menu .= "<OPTION VALUE=$cols "; |
---|
| 254 | if ($cols == $hostcols) |
---|
| 255 | $cols_menu .= "SELECTED"; |
---|
| 256 | $cols_menu .= ">$cols\n"; |
---|
| 257 | } |
---|
| 258 | $cols_menu .= "</SELECT>\n"; |
---|
| 259 | |
---|
| 260 | $tpl->assign("metric","$metricname $units"); |
---|
| 261 | $tpl->assign("id", $id); |
---|
| 262 | # Host columns menu defined in header.php |
---|
| 263 | $tpl->assign("cols_menu", $cols_menu); |
---|
| 264 | |
---|
| 265 | if( $showhosts ) { |
---|
| 266 | //bla |
---|
| 267 | |
---|
[145] | 268 | //printf("job_start = %s job_stop = %s\n", $job_start, $job_stop ); |
---|
| 269 | //printf("start = %s stop = %s\n", $start, $stop ); |
---|
[143] | 270 | |
---|
[149] | 271 | if( !$period_start ) // Add an additional 5 minutes before |
---|
| 272 | $period_start = intval( $job_start - (intval( $runningtime * 0.10 ) ) ); |
---|
[145] | 273 | else |
---|
[149] | 274 | $period_start = datetimeToEpoch( $period_start ); |
---|
[143] | 275 | |
---|
[149] | 276 | if( !$period_stop ) // Add an additional 5 minutes after |
---|
| 277 | $period_stop = intval( $job_stop + (intval( $runningtime * 0.10 ) ) ); |
---|
[145] | 278 | else |
---|
[149] | 279 | $period_stop = datetimeToEpoch( $period_stop ); |
---|
[143] | 280 | |
---|
[145] | 281 | //printf("start = %s stop = %s\n", $start, $stop ); |
---|
[143] | 282 | |
---|
[149] | 283 | $tpl->assign("period_start", epochToDatetime( $period_start ) ); |
---|
| 284 | $tpl->assign("period_stop", epochToDatetime( $period_stop ) ); |
---|
[143] | 285 | |
---|
[145] | 286 | $hosts_up = array(); |
---|
| 287 | |
---|
| 288 | foreach( $nodes as $mynode ) |
---|
| 289 | $hosts_up[] = $mynode[hostname]; |
---|
| 290 | |
---|
| 291 | //print_r( $hosts_up ); |
---|
| 292 | |
---|
| 293 | $sorted_hosts = array(); |
---|
| 294 | //$hosts_up = $jobs[$filter[id]][nodes]; |
---|
| 295 | |
---|
[143] | 296 | foreach ($hosts_up as $host ) { |
---|
[145] | 297 | $host = $host. '.'.$job_domain; |
---|
[143] | 298 | $cpus = $metrics[$host]["cpu_num"][VAL]; |
---|
| 299 | if (!$cpus) $cpus=1; |
---|
| 300 | $load_one = $metrics[$host]["load_one"][VAL]; |
---|
| 301 | $load = ((float) $load_one)/$cpus; |
---|
| 302 | $host_load[$host] = $load; |
---|
| 303 | $percent_hosts[load_color($load)] += 1; |
---|
| 304 | if ($metricname=="load_one") |
---|
| 305 | $sorted_hosts[$host] = $load; |
---|
| 306 | else |
---|
| 307 | $sorted_hosts[$host] = $metrics[$host][$metricname][VAL]; |
---|
| 308 | } |
---|
| 309 | switch ($sort) { |
---|
| 310 | case "descending": |
---|
| 311 | arsort($sorted_hosts); |
---|
| 312 | break; |
---|
| 313 | case "by hostname": |
---|
| 314 | ksort($sorted_hosts); |
---|
| 315 | break; |
---|
| 316 | default: |
---|
| 317 | case "ascending": |
---|
| 318 | asort($sorted_hosts); |
---|
| 319 | break; |
---|
| 320 | } |
---|
| 321 | |
---|
| 322 | //$sorted_hosts = array_merge($down_hosts, $sorted_hosts); |
---|
| 323 | |
---|
| 324 | # First pass to find the max value in all graphs for this |
---|
| 325 | # metric. The $start,$end variables comes from get_context.php, |
---|
| 326 | # included in index.php. |
---|
| 327 | list($min, $max) = find_limits($sorted_hosts, $metricname); |
---|
| 328 | |
---|
| 329 | # Second pass to output the graphs or metrics. |
---|
| 330 | $i = 1; |
---|
| 331 | foreach ( $sorted_hosts as $host=>$value ) { |
---|
| 332 | $tpl->newBlock ("sorted_list"); |
---|
| 333 | //$host = $host. '.'.$domain; |
---|
| 334 | $host_url = rawurlencode($host); |
---|
| 335 | $cluster_url = rawurlencode($clustername); |
---|
| 336 | |
---|
| 337 | $textval = ""; |
---|
| 338 | //printf("host = %s, value = %s", $host, $value); |
---|
| 339 | //echo "$host: $value, "; |
---|
| 340 | $val = $metrics[$host][$metricname]; |
---|
| 341 | $class = "metric"; |
---|
[149] | 342 | $host_link="\"?c=$cluster_url&h=$host_url&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop\""; |
---|
[143] | 343 | |
---|
| 344 | if ($val[TYPE]=="timestamp" or $always_timestamp[$metricname]) { |
---|
| 345 | $textval = date("r", $val[VAL]); |
---|
| 346 | } elseif ($val[TYPE]=="string" or $val[SLOPE]=="zero" or $always_constant[$metricname] or ($max_graphs > 0 and $i > $max_graphs )) { |
---|
| 347 | $textval = "$val[VAL] $val[UNITS]"; |
---|
| 348 | } else { |
---|
[149] | 349 | $graphargs = "z=small&c=$cluster_url&m=$metricname&h=$host_url&v=$val[VAL]&x=$max&n=$min&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop"; |
---|
[143] | 350 | } |
---|
| 351 | if ($textval) { |
---|
| 352 | $cell="<td class=$class>". "<b><a href=$host_link>$host</a></b><br>". "<i>$metricname:</i> <b>$textval</b></td>"; |
---|
| 353 | } else { |
---|
[145] | 354 | $cell="<td><a href=$host_link>". "<img src=\"./graph.php?$graphargs\" ". "alt=\"$host\" border=0></a></td>"; |
---|
[143] | 355 | } |
---|
| 356 | |
---|
| 357 | $tpl->assign("metric_image", $cell); |
---|
| 358 | if (! ($i++ % $hostcols) ) |
---|
| 359 | $tpl->assign ("br", "</tr><tr>"); |
---|
| 360 | } |
---|
| 361 | |
---|
| 362 | //einde bla |
---|
| 363 | } |
---|
[140] | 364 | } |
---|
| 365 | |
---|
[138] | 366 | } |
---|
[130] | 367 | } |
---|
| 368 | ?> |
---|