[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; |
---|
[157] | 7 | global $end_from_time, $end_to_time, $period_start, $period_stop; |
---|
[138] | 8 | |
---|
| 9 | $error = 0; |
---|
[157] | 10 | $error_msg = "<FONT COLOR=\"red\"><B>"; |
---|
| 11 | $show_msg = 0; |
---|
[138] | 12 | |
---|
| 13 | $none_set = 0; |
---|
| 14 | |
---|
[152] | 15 | if( $id == '' and $user == '' and $name == '' and $start_from_time == '' and $start_to_time == '' and $queue == '' and $end_from_time == '' and $end_to_time == '') { |
---|
| 16 | $error = 1; |
---|
[157] | 17 | $show_msg = 1; |
---|
| 18 | $error_msg .= "No search criteria set!"; |
---|
[152] | 19 | } |
---|
[138] | 20 | |
---|
[152] | 21 | if( !is_numeric($id) and !$error and $id != '') { |
---|
[138] | 22 | |
---|
| 23 | $error = 1; |
---|
[157] | 24 | $show_msg = 1; |
---|
| 25 | $error_msg .= "Id must be a number"; |
---|
[138] | 26 | } |
---|
| 27 | |
---|
[157] | 28 | //printf( "period_start = %s period_stop = %s\n", $period_start, $period_stop ); |
---|
| 29 | |
---|
| 30 | if( !$error and $period_start != '' ) { |
---|
| 31 | //printf( "period_start = %s period_stop = %s\n", $period_start, $period_stop ); |
---|
| 32 | $pstart_epoch = datetimeToEpoch( $period_start ); |
---|
| 33 | //printf( "period_start = %s period_stop = %s\n", $period_start, $period_stop ); |
---|
| 34 | if( $period_stop != '' ) { |
---|
| 35 | |
---|
| 36 | $pstop_epoch = datetimeToEpoch( $period_stop ); |
---|
[158] | 37 | //printf( "pstop_epoch = %s pstart_epoch = %s\n", $pstop_epoch, $pstart_epoch ); |
---|
[157] | 38 | |
---|
| 39 | if( $pstart_epoch > $pstop_epoch ) { |
---|
| 40 | |
---|
| 41 | $show_msg = 1; |
---|
| 42 | $error_msg .= "Graph timeperiod reset: start date/time can't be later than end"; |
---|
| 43 | $period_stop = ''; |
---|
| 44 | $period_start = ''; |
---|
| 45 | } else if( $pstop_epoch == $pstart_epoch ) { |
---|
| 46 | |
---|
| 47 | $show_msg = 1; |
---|
| 48 | $error_msg .= "Graph timeperiod reset: start and end date/time can't be the same"; |
---|
| 49 | $period_stop = ''; |
---|
| 50 | $period_start = ''; |
---|
| 51 | } |
---|
| 52 | } |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | $error_msg .= "</B></FONT>"; |
---|
[138] | 56 | // doe checks en set error en error_msg in case shit |
---|
| 57 | |
---|
[157] | 58 | if( $show_msg ) |
---|
[138] | 59 | $tpl->assign( "form_error_msg", $error_msg ); |
---|
[157] | 60 | |
---|
| 61 | return ($error ? 0 : 1 ); |
---|
[138] | 62 | } |
---|
| 63 | |
---|
[141] | 64 | function makeTime( $time ) { |
---|
| 65 | |
---|
| 66 | $days = intval( $time / 86400 ); |
---|
| 67 | $time = ($days>0) ? $time % ($days * 86400) : $time; |
---|
| 68 | |
---|
| 69 | //printf( "time = %s, days = %s\n", $time, $days ); |
---|
| 70 | |
---|
| 71 | $date_str = ''; |
---|
| 72 | $day_str = ''; |
---|
| 73 | |
---|
| 74 | if( $days > 0 ) { |
---|
| 75 | if( $days > 1 ) |
---|
| 76 | $day_str .= $days . ' days'; |
---|
| 77 | else |
---|
| 78 | $day_str .= $days . ' day'; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | $hours = intval( $time / 3600 ); |
---|
| 82 | $time = $hours ? $time % ($hours * 3600) : $time; |
---|
| 83 | |
---|
| 84 | //printf( "time = %s, days = %s, hours = %s\n", $time, $days, $hours ); |
---|
| 85 | |
---|
| 86 | if( $hours > 0 ) { |
---|
| 87 | $date_str .= $hours . ':'; |
---|
| 88 | $date_unit = 'hours'; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | $minutes = intval( $time / 60 ); |
---|
| 92 | $seconds = $minutes ? $time % ($minutes * 60) : $time; |
---|
| 93 | |
---|
| 94 | if( $minutes > 0 ) { |
---|
| 95 | |
---|
| 96 | if( $minutes >= 10 ) |
---|
| 97 | $date_str .= $minutes . ':'; |
---|
| 98 | else |
---|
| 99 | $date_str .= '0' . $minutes . ':'; |
---|
| 100 | |
---|
| 101 | $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit; |
---|
| 102 | } else { |
---|
| 103 | if($hours > 0 ) { |
---|
| 104 | $date_str .= '00:'; |
---|
| 105 | $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit; |
---|
| 106 | } |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | $date_unit = (!isset($date_unit)) ? 'seconds' : $date_unit; |
---|
| 111 | |
---|
| 112 | if( $seconds > 0 ) { |
---|
| 113 | |
---|
| 114 | if( $seconds >= 10 ) |
---|
| 115 | $date_str .= $seconds . ' ' . $date_unit; |
---|
| 116 | else |
---|
| 117 | $date_str .= '0' . $seconds . ' ' . $date_unit; |
---|
| 118 | |
---|
| 119 | } else if ( $hours > 0 or $minutes > 0 ) |
---|
| 120 | |
---|
| 121 | $date_str .= '00 ' . $date_unit; |
---|
| 122 | |
---|
| 123 | if( $days > 0) { |
---|
| 124 | |
---|
| 125 | if( $hours > 0 or $minutes > 0 or $seconds > 0 ) |
---|
| 126 | $date_str = $day_str . ' - ' . $date_str; |
---|
| 127 | else |
---|
| 128 | $date_str = $day_str; |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | return $date_str; |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | function makeDate( $time ) { |
---|
| 135 | return strftime( "%a %d %b %Y %H:%M:%S", $time ); |
---|
| 136 | } |
---|
| 137 | |
---|
[142] | 138 | function datetimeToEpoch( $datetime ) { |
---|
| 139 | |
---|
[157] | 140 | //printf("datetime = %s\n", $datetime ); |
---|
[142] | 141 | $datetime_fields = explode( ' ', $datetime ); |
---|
| 142 | |
---|
| 143 | $date = $datetime_fields[0]; |
---|
| 144 | $time = $datetime_fields[1]; |
---|
| 145 | |
---|
| 146 | $date_fields = explode( '-', $date ); |
---|
| 147 | |
---|
| 148 | $days = $date_fields[0]; |
---|
| 149 | $months = $date_fields[1]; |
---|
| 150 | $years = $date_fields[2]; |
---|
| 151 | |
---|
[157] | 152 | //printf( "days = %s months = %s years = %s\n", $days, $months, $years ); |
---|
| 153 | |
---|
[142] | 154 | $time_fields = explode( ':', $time ); |
---|
| 155 | |
---|
| 156 | $hours = $time_fields[0]; |
---|
| 157 | $minutes = $time_fields[1]; |
---|
| 158 | $seconds = $time_fields[2]; |
---|
| 159 | |
---|
[157] | 160 | //printf( "hours = %s minutes = %s seconds = %s\n", $hours, $minutes, $seconds ); |
---|
| 161 | |
---|
[142] | 162 | $timestamp = mktime( $hours, $minutes, $seconds, $months, $days, $years ); |
---|
| 163 | |
---|
[157] | 164 | //printf( "timestamp = %s\n", $timestamp ); |
---|
| 165 | |
---|
[142] | 166 | return $timestamp; |
---|
| 167 | } |
---|
| 168 | |
---|
[145] | 169 | function epochToDatetime( $epoch ) { |
---|
| 170 | |
---|
| 171 | return strftime( "%d-%m-%Y %H:%M:%S", $epoch ); |
---|
| 172 | } |
---|
| 173 | |
---|
[141] | 174 | function timeToEpoch( $time ) { |
---|
| 175 | |
---|
| 176 | $time_fields = explode( ':', $time ); |
---|
| 177 | |
---|
| 178 | if( count($time_fields) == 3 ) { |
---|
| 179 | |
---|
| 180 | $hours = $time_fields[0]; |
---|
| 181 | $minutes = $time_fields[1]; |
---|
| 182 | $seconds = $time_fields[2]; |
---|
| 183 | |
---|
| 184 | } else if( count($time_fields) == 2 ) { |
---|
| 185 | |
---|
| 186 | $hours = 0; |
---|
| 187 | $minutes = $time_fields[0]; |
---|
| 188 | $seconds = $time_fields[1]; |
---|
| 189 | |
---|
| 190 | } else if( count($time_fields) == 1 ) { |
---|
| 191 | |
---|
| 192 | $hours = 0; |
---|
| 193 | $minutes = 0; |
---|
| 194 | $seconds = $time_fields[0]; |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | $myepoch = intval( $seconds + (intval( $minutes * 60 )) + (intval( $hours * 3600 )) ); |
---|
| 198 | |
---|
| 199 | return $myepoch; |
---|
| 200 | } |
---|
| 201 | |
---|
[180] | 202 | function sortJobs( $jobs, $nodes, $sortby, $sortorder ) { |
---|
| 203 | |
---|
| 204 | //printf("sortby = %s sortorder = %s\n", $sortby, $sortorder ); |
---|
| 205 | |
---|
| 206 | $sorted = array(); |
---|
| 207 | |
---|
| 208 | $cmp = create_function( '$a, $b', |
---|
| 209 | "global \$sortby, \$sortorder;". |
---|
| 210 | |
---|
| 211 | "if( \$a == \$b ) return 0;". |
---|
| 212 | |
---|
| 213 | "if (\$sortorder==\"desc\")". |
---|
| 214 | "return ( \$a < \$b ) ? 1 : -1;". |
---|
| 215 | "else if (\$sortorder==\"asc\")". |
---|
| 216 | "return ( \$a > \$b ) ? 1 : -1;" ); |
---|
| 217 | |
---|
| 218 | //print_r( $jobs ); |
---|
| 219 | |
---|
| 220 | foreach( $jobs as $jobid => $jobattrs ) { |
---|
| 221 | |
---|
| 222 | $state = $jobattrs[status]; |
---|
| 223 | $user = $jobattrs[owner]; |
---|
| 224 | $queue = $jobattrs[queue]; |
---|
| 225 | $name = $jobattrs[name]; |
---|
| 226 | $req_cpu = $jobattrs[requested_time]; |
---|
| 227 | $req_memory = $jobattrs[requested_memory]; |
---|
| 228 | |
---|
| 229 | //if( $state == 'R' ) |
---|
| 230 | $mynodes = count( $nodes[$jobid] ); |
---|
| 231 | //else |
---|
| 232 | // $nodes = $jobattrs[nodes]; |
---|
| 233 | |
---|
| 234 | $ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1; |
---|
| 235 | $cpus = $mynodes * $ppn; |
---|
| 236 | $start_time = (int) $jobattrs[start_timestamp]; |
---|
| 237 | $stop_time = (int) $jobattrs[stop_timestamp]; |
---|
| 238 | $runningtime = $stop_time - $start_time; |
---|
| 239 | |
---|
| 240 | switch( $sortby ) { |
---|
| 241 | case "id": |
---|
| 242 | $sorted[$jobid] = $jobid; |
---|
| 243 | break; |
---|
| 244 | |
---|
| 245 | case "state": |
---|
| 246 | $sorted[$jobid] = $state; |
---|
| 247 | break; |
---|
| 248 | |
---|
| 249 | case "user": |
---|
| 250 | $sorted[$jobid] = $user; |
---|
| 251 | break; |
---|
| 252 | |
---|
| 253 | case "queue": |
---|
| 254 | $sorted[$jobid] = $queue; |
---|
| 255 | break; |
---|
| 256 | |
---|
| 257 | case "name": |
---|
| 258 | $sorted[$jobid] = $name; |
---|
| 259 | break; |
---|
| 260 | |
---|
| 261 | case "req_cpu": |
---|
| 262 | $sorted[$jobid] = timeToEpoch( $req_cpu ); |
---|
| 263 | break; |
---|
| 264 | |
---|
| 265 | case "req_mem": |
---|
| 266 | $sorted[$jobid] = $req_memory; |
---|
| 267 | break; |
---|
| 268 | |
---|
| 269 | case "nodes": |
---|
| 270 | $sorted[$jobid] = $mynodes; |
---|
| 271 | break; |
---|
| 272 | |
---|
| 273 | case "cpus": |
---|
| 274 | $sorted[$jobid] = $cpus; |
---|
| 275 | break; |
---|
| 276 | |
---|
| 277 | case "start": |
---|
| 278 | $sorted[$jobid] = $start_time; |
---|
| 279 | break; |
---|
| 280 | |
---|
[181] | 281 | case "finished": |
---|
| 282 | $sorted[$jobid] = $stop_time; |
---|
| 283 | break; |
---|
| 284 | |
---|
[180] | 285 | case "runningtime": |
---|
| 286 | $sorted[$jobid] = $runningtime; |
---|
| 287 | break; |
---|
| 288 | |
---|
| 289 | default: |
---|
| 290 | break; |
---|
| 291 | |
---|
| 292 | } |
---|
| 293 | } |
---|
| 294 | |
---|
| 295 | //uasort( $sorted, $cmp ); |
---|
| 296 | if( $sortorder == "asc" ) |
---|
| 297 | arsort( $sorted ); |
---|
| 298 | else if( $sortorder == "desc" ) |
---|
| 299 | asort( $sorted ); |
---|
| 300 | |
---|
| 301 | //print_r( $sorted ); |
---|
| 302 | |
---|
| 303 | return array_keys( $sorted ); |
---|
| 304 | } |
---|
| 305 | |
---|
[130] | 306 | function makeSearchPage() { |
---|
[138] | 307 | global $clustername, $tpl, $id, $user, $name, $start_from_time, $start_to_time, $queue; |
---|
[143] | 308 | global $end_from_time, $end_to_time, $filter, $default_showhosts, $m, $hosts_up; |
---|
[180] | 309 | global $period_start, $period_stop, $sortby, $sortorder; |
---|
[130] | 310 | |
---|
[143] | 311 | $metricname = $m; |
---|
[145] | 312 | //printf("job_start = %s job_stop = %s\n", $job_start, $job_stop ); |
---|
| 313 | //printf("start = %s stop = %s\n", $start, $stop ); |
---|
[143] | 314 | |
---|
[138] | 315 | $tpl->assign( "cluster", $clustername ); |
---|
| 316 | $tpl->assign( "id_value", $id ); |
---|
| 317 | $tpl->assign( "user_value", $user ); |
---|
| 318 | $tpl->assign( "queue_value", $queue ); |
---|
| 319 | $tpl->assign( "name_value", $name ); |
---|
| 320 | $tpl->assign( "start_from_value", rawurldecode( $start_from_time ) ); |
---|
| 321 | $tpl->assign( "start_to_value", rawurldecode( $start_to_time ) ); |
---|
| 322 | $tpl->assign( "end_from_value", rawurldecode( $end_from_time ) ); |
---|
| 323 | $tpl->assign( "end_to_value", rawurldecode( $end_to_time ) ); |
---|
| 324 | |
---|
| 325 | if( validateFormInput() ) { |
---|
| 326 | |
---|
[140] | 327 | $tpl->newBlock( "search_results" ); |
---|
[180] | 328 | $tpl->assign( "sortby", $sortby); |
---|
| 329 | $tpl->assign( "sortorder", $sortorder); |
---|
[138] | 330 | $tdb = new TarchDbase(); |
---|
[142] | 331 | if( $start_from_time ) $start_from_time = datetimeToEpoch( $start_from_time ); |
---|
| 332 | if( $start_to_time ) $start_to_time = datetimeToEpoch( $start_to_time ); |
---|
| 333 | if( $end_from_time ) $end_from_time = datetimeToEpoch( $end_from_time ); |
---|
| 334 | if( $end_to_time ) $end_to_time = datetimeToEpoch( $end_to_time ); |
---|
[140] | 335 | $search_ids = $tdb->searchDbase( $id, $queue, $user, $name, $start_from_time, $start_to_time, $end_from_time, $end_to_time ); |
---|
[138] | 336 | |
---|
[180] | 337 | $jobs = array(); |
---|
| 338 | $nodes = array(); |
---|
[140] | 339 | |
---|
[180] | 340 | //print_r( $search_ids ); |
---|
[141] | 341 | |
---|
[180] | 342 | foreach( $search_ids as $myid ) { |
---|
| 343 | |
---|
| 344 | //printf( "myid %s\n", $myid ); |
---|
| 345 | $jobs[$myid] = $tdb->getJobArray( $myid ); |
---|
| 346 | $nodes[$myid] = $tdb->getNodesForJob( $myid ); |
---|
| 347 | } |
---|
| 348 | |
---|
| 349 | //print_r( $nodes ); |
---|
| 350 | $sorted_search = sortJobs( $jobs, $nodes, $sortby, $sortorder ); |
---|
| 351 | |
---|
| 352 | //print_r( $sorted_search ); |
---|
| 353 | foreach( $sorted_search as $sortid ) { |
---|
| 354 | |
---|
| 355 | $job = $jobs[$sortid]; |
---|
| 356 | //print_r( $job ); |
---|
| 357 | $foundid = $job[id]; |
---|
| 358 | //printf( "foundid %s\n", $foundid ); |
---|
| 359 | |
---|
| 360 | //$job = $tdb->getJobArray( $foundid ); |
---|
| 361 | //$nodes = $tdb->getNodesForJob( $foundid ); |
---|
| 362 | |
---|
[141] | 363 | $tpl->newBlock( "node" ); |
---|
| 364 | $tpl->assign( "id", $job[id] ); |
---|
| 365 | $tpl->assign( "state", $job[status] ); |
---|
| 366 | $tpl->assign( "user", $job[owner] ); |
---|
| 367 | $tpl->assign( "queue", $job[queue] ); |
---|
| 368 | $tpl->assign( "name", $job[name] ); |
---|
| 369 | $tpl->assign( "req_cpu", makeTime( TimeToEpoch( $job[requested_time] ) ) ); |
---|
| 370 | $tpl->assign( "req_memory", $job[requested_memory] ); |
---|
| 371 | |
---|
[180] | 372 | $nodes_nr = count( $nodes[$foundid] ); |
---|
[145] | 373 | |
---|
| 374 | // need to replace later with domain stored from dbase |
---|
| 375 | // |
---|
| 376 | //$job_domain = $job[domain]; |
---|
| 377 | |
---|
[156] | 378 | //$myhost = $_SERVER[HTTP_HOST]; |
---|
| 379 | //$myhf = explode( '.', $myhost ); |
---|
| 380 | //$myhf = array_reverse( $myhf ); |
---|
| 381 | //array_pop( $myhf ); |
---|
| 382 | //$myhf = array_reverse( $myhf ); |
---|
| 383 | //$job_domain = implode( '.', $myhf ); |
---|
[145] | 384 | |
---|
| 385 | //print_r( $job ); |
---|
| 386 | //printf( "job domain = %s\n", $job_domain); |
---|
[141] | 387 | $ppn = (int) $job[ppn] ? $job[ppn] : 1; |
---|
| 388 | $cpus = $nodes_nr * $ppn; |
---|
| 389 | |
---|
| 390 | $tpl->assign( "nodes", $nodes_nr ); |
---|
| 391 | $tpl->assign( "cpus", $cpus ); |
---|
| 392 | |
---|
[145] | 393 | $job_start = $job[start_timestamp]; |
---|
| 394 | $job_stop = $job[stop_timestamp]; |
---|
| 395 | $runningtime = intval( $job_stop - $job_start ); |
---|
| 396 | $tpl->assign( "started", makeDate( $job_start ) ); |
---|
| 397 | $tpl->assign( "finished", makeDate( $job_stop ) ); |
---|
[141] | 398 | $tpl->assign( "runningtime", makeTime( $runningtime ) ); |
---|
| 399 | |
---|
[143] | 400 | //print_r( $job ); |
---|
| 401 | //print_r( $nodes ); |
---|
| 402 | } |
---|
[140] | 403 | |
---|
| 404 | if( count( $search_ids ) == 1 ) { |
---|
| 405 | |
---|
| 406 | $tpl->newBlock( "showhosts" ); |
---|
[143] | 407 | |
---|
| 408 | $showhosts = isset($sh) ? $sh : $default_showhosts; |
---|
| 409 | //if( !$showhosts) $showhosts = $default_showhosts; |
---|
| 410 | $tpl->assign("checked$showhosts", "checked"); |
---|
| 411 | |
---|
| 412 | # Present a width list |
---|
[145] | 413 | $cols_menu = "<SELECT NAME=\"hc\" OnChange=\"archive_search_form.submit();\">\n"; |
---|
[143] | 414 | |
---|
| 415 | $hostcols = ($hc) ? $hc : 4; |
---|
| 416 | |
---|
| 417 | foreach(range(1,25) as $cols) { |
---|
| 418 | $cols_menu .= "<OPTION VALUE=$cols "; |
---|
| 419 | if ($cols == $hostcols) |
---|
| 420 | $cols_menu .= "SELECTED"; |
---|
| 421 | $cols_menu .= ">$cols\n"; |
---|
| 422 | } |
---|
| 423 | $cols_menu .= "</SELECT>\n"; |
---|
| 424 | |
---|
| 425 | $tpl->assign("metric","$metricname $units"); |
---|
| 426 | $tpl->assign("id", $id); |
---|
| 427 | # Host columns menu defined in header.php |
---|
| 428 | $tpl->assign("cols_menu", $cols_menu); |
---|
| 429 | |
---|
| 430 | if( $showhosts ) { |
---|
| 431 | //bla |
---|
| 432 | |
---|
[145] | 433 | //printf("job_start = %s job_stop = %s\n", $job_start, $job_stop ); |
---|
| 434 | //printf("start = %s stop = %s\n", $start, $stop ); |
---|
[143] | 435 | |
---|
[157] | 436 | if( !$period_start ) // Add an extra 10% to graphstart |
---|
[149] | 437 | $period_start = intval( $job_start - (intval( $runningtime * 0.10 ) ) ); |
---|
[145] | 438 | else |
---|
[149] | 439 | $period_start = datetimeToEpoch( $period_start ); |
---|
[143] | 440 | |
---|
[157] | 441 | if( !$period_stop ) // Add an extra 10% to graphend |
---|
[149] | 442 | $period_stop = intval( $job_stop + (intval( $runningtime * 0.10 ) ) ); |
---|
[145] | 443 | else |
---|
[149] | 444 | $period_stop = datetimeToEpoch( $period_stop ); |
---|
[143] | 445 | |
---|
[145] | 446 | //printf("start = %s stop = %s\n", $start, $stop ); |
---|
[143] | 447 | |
---|
[149] | 448 | $tpl->assign("period_start", epochToDatetime( $period_start ) ); |
---|
| 449 | $tpl->assign("period_stop", epochToDatetime( $period_stop ) ); |
---|
[143] | 450 | |
---|
[145] | 451 | $hosts_up = array(); |
---|
| 452 | |
---|
[186] | 453 | foreach( $nodes[$id] as $mynode ) |
---|
[145] | 454 | $hosts_up[] = $mynode[hostname]; |
---|
| 455 | |
---|
| 456 | $sorted_hosts = array(); |
---|
| 457 | //$hosts_up = $jobs[$filter[id]][nodes]; |
---|
| 458 | |
---|
[143] | 459 | foreach ($hosts_up as $host ) { |
---|
[156] | 460 | //$host = $host. '.'.$job_domain; |
---|
[143] | 461 | $cpus = $metrics[$host]["cpu_num"][VAL]; |
---|
| 462 | if (!$cpus) $cpus=1; |
---|
| 463 | $load_one = $metrics[$host]["load_one"][VAL]; |
---|
| 464 | $load = ((float) $load_one)/$cpus; |
---|
| 465 | $host_load[$host] = $load; |
---|
| 466 | $percent_hosts[load_color($load)] += 1; |
---|
| 467 | if ($metricname=="load_one") |
---|
| 468 | $sorted_hosts[$host] = $load; |
---|
| 469 | else |
---|
| 470 | $sorted_hosts[$host] = $metrics[$host][$metricname][VAL]; |
---|
| 471 | } |
---|
| 472 | switch ($sort) { |
---|
| 473 | case "descending": |
---|
| 474 | arsort($sorted_hosts); |
---|
| 475 | break; |
---|
| 476 | case "by hostname": |
---|
| 477 | ksort($sorted_hosts); |
---|
| 478 | break; |
---|
| 479 | default: |
---|
| 480 | case "ascending": |
---|
| 481 | asort($sorted_hosts); |
---|
| 482 | break; |
---|
| 483 | } |
---|
| 484 | |
---|
| 485 | //$sorted_hosts = array_merge($down_hosts, $sorted_hosts); |
---|
| 486 | |
---|
| 487 | # First pass to find the max value in all graphs for this |
---|
| 488 | # metric. The $start,$end variables comes from get_context.php, |
---|
| 489 | # included in index.php. |
---|
| 490 | list($min, $max) = find_limits($sorted_hosts, $metricname); |
---|
| 491 | |
---|
| 492 | # Second pass to output the graphs or metrics. |
---|
| 493 | $i = 1; |
---|
| 494 | foreach ( $sorted_hosts as $host=>$value ) { |
---|
| 495 | $tpl->newBlock ("sorted_list"); |
---|
| 496 | //$host = $host. '.'.$domain; |
---|
| 497 | $host_url = rawurlencode($host); |
---|
| 498 | $cluster_url = rawurlencode($clustername); |
---|
| 499 | |
---|
| 500 | $textval = ""; |
---|
| 501 | //printf("host = %s, value = %s", $host, $value); |
---|
| 502 | //echo "$host: $value, "; |
---|
| 503 | $val = $metrics[$host][$metricname]; |
---|
| 504 | $class = "metric"; |
---|
[149] | 505 | $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] | 506 | |
---|
| 507 | if ($val[TYPE]=="timestamp" or $always_timestamp[$metricname]) { |
---|
| 508 | $textval = date("r", $val[VAL]); |
---|
| 509 | } elseif ($val[TYPE]=="string" or $val[SLOPE]=="zero" or $always_constant[$metricname] or ($max_graphs > 0 and $i > $max_graphs )) { |
---|
| 510 | $textval = "$val[VAL] $val[UNITS]"; |
---|
| 511 | } else { |
---|
[152] | 512 | $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&min=$min&max=$max"; |
---|
[143] | 513 | } |
---|
| 514 | if ($textval) { |
---|
| 515 | $cell="<td class=$class>". "<b><a href=$host_link>$host</a></b><br>". "<i>$metricname:</i> <b>$textval</b></td>"; |
---|
| 516 | } else { |
---|
[145] | 517 | $cell="<td><a href=$host_link>". "<img src=\"./graph.php?$graphargs\" ". "alt=\"$host\" border=0></a></td>"; |
---|
[143] | 518 | } |
---|
| 519 | |
---|
| 520 | $tpl->assign("metric_image", $cell); |
---|
| 521 | if (! ($i++ % $hostcols) ) |
---|
| 522 | $tpl->assign ("br", "</tr><tr>"); |
---|
| 523 | } |
---|
| 524 | |
---|
| 525 | //einde bla |
---|
| 526 | } |
---|
[140] | 527 | } |
---|
| 528 | |
---|
[138] | 529 | } |
---|
[130] | 530 | } |
---|
| 531 | ?> |
---|