[113] | 1 | <?php |
---|
[225] | 2 | /* |
---|
| 3 | * |
---|
| 4 | * This file is part of Jobmonarch |
---|
| 5 | * |
---|
| 6 | * Copyright (C) 2006 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 | * |
---|
[231] | 22 | * SVN $Id: overview.php 268 2006-06-27 10:20:05Z bastiaans $ |
---|
[225] | 23 | */ |
---|
| 24 | |
---|
[126] | 25 | global $GANGLIA_PATH, $clustername, $tpl, $filter, $cluster, $get_metric_string, $cluster_url, $sh; |
---|
[263] | 26 | global $hosts_up, $m, $start, $end, $filterorder, $COLUMN_REQUESTED_MEMORY, $COLUMN_QUEUED, $hostname, $piefilter; |
---|
[114] | 27 | |
---|
[163] | 28 | $data_gatherer = new DataGatherer( $clustername ); |
---|
[114] | 29 | |
---|
[116] | 30 | $tpl->assign( "clustername", $clustername ); |
---|
| 31 | |
---|
[206] | 32 | if( $JOB_ARCHIVE ) |
---|
[129] | 33 | $tpl->assign( "cluster_url", rawurlencode($clustername) ); |
---|
| 34 | |
---|
[114] | 35 | $data_gatherer->parseXML(); |
---|
[117] | 36 | |
---|
[114] | 37 | $heartbeat = $data_gatherer->getHeartbeat(); |
---|
| 38 | $jobs = $data_gatherer->getJobs(); |
---|
[126] | 39 | $gnodes = $data_gatherer->getNodes(); |
---|
[124] | 40 | $cpus = $data_gatherer->getCpus(); |
---|
[114] | 41 | |
---|
[263] | 42 | function setupFilterSettings() { |
---|
| 43 | global $tpl, $filter, $clustername, $piefilter; |
---|
[122] | 44 | |
---|
[263] | 45 | $filter_image_url = ""; |
---|
[119] | 46 | |
---|
[263] | 47 | $tpl->gotoBlock( "_ROOT" ); |
---|
[122] | 48 | |
---|
[263] | 49 | foreach( $filter as $filtername => $filtervalue ) { |
---|
| 50 | $tpl->assign( "f_".$filtername, $filtervalue ); |
---|
| 51 | $filter_image_url .= "&$filtername=$filtervalue"; |
---|
| 52 | } |
---|
[114] | 53 | |
---|
[263] | 54 | $tpl->assign( "clusterimage", "./image.php?c=".rawurlencode($clustername)."&view=big-clusterimage".$filter_image_url ); |
---|
| 55 | $tpl->assign( "f_order", $filterorder ); |
---|
[114] | 56 | |
---|
[263] | 57 | if( array_key_exists( "id", $filter ) ) |
---|
| 58 | $piefilter = 'id'; |
---|
| 59 | else if( array_key_exists( "user", $filter ) ) |
---|
| 60 | $piefilter = 'user'; |
---|
| 61 | else if( array_key_exists( "queue", $filter ) ) |
---|
| 62 | $piefilter = 'queue'; |
---|
[122] | 63 | |
---|
[263] | 64 | $pie = drawPie(); |
---|
| 65 | $tpl->assign("pie", $pie ); |
---|
| 66 | } |
---|
[122] | 67 | |
---|
[120] | 68 | function timeToEpoch( $time ) { |
---|
| 69 | |
---|
| 70 | $time_fields = explode( ':', $time ); |
---|
| 71 | |
---|
| 72 | if( count($time_fields) == 3 ) { |
---|
| 73 | |
---|
| 74 | $hours = $time_fields[0]; |
---|
| 75 | $minutes = $time_fields[1]; |
---|
| 76 | $seconds = $time_fields[2]; |
---|
| 77 | |
---|
[128] | 78 | } else if( count($time_fields) == 2 ) { |
---|
| 79 | |
---|
| 80 | $hours = 0; |
---|
| 81 | $minutes = $time_fields[0]; |
---|
| 82 | $seconds = $time_fields[1]; |
---|
| 83 | |
---|
| 84 | } else if( count($time_fields) == 1 ) { |
---|
| 85 | |
---|
| 86 | $hours = 0; |
---|
| 87 | $minutes = 0; |
---|
| 88 | $seconds = $time_fields[0]; |
---|
[120] | 89 | } |
---|
[128] | 90 | |
---|
| 91 | $myepoch = intval( $seconds + (intval( $minutes * 60 )) + (intval( $hours * 3600 )) ); |
---|
| 92 | |
---|
| 93 | return $myepoch; |
---|
[120] | 94 | } |
---|
| 95 | |
---|
[114] | 96 | function makeTime( $time ) { |
---|
| 97 | |
---|
| 98 | $days = intval( $time / 86400 ); |
---|
[128] | 99 | $time = ($days>0) ? $time % ($days * 86400) : $time; |
---|
[115] | 100 | |
---|
[128] | 101 | //printf( "time = %s, days = %s\n", $time, $days ); |
---|
| 102 | |
---|
| 103 | $date_str = ''; |
---|
| 104 | $day_str = ''; |
---|
| 105 | |
---|
[114] | 106 | if( $days > 0 ) { |
---|
| 107 | if( $days > 1 ) |
---|
[128] | 108 | $day_str .= $days . ' days'; |
---|
[114] | 109 | else |
---|
[128] | 110 | $day_str .= $days . ' day'; |
---|
[114] | 111 | } |
---|
[115] | 112 | |
---|
[114] | 113 | $hours = intval( $time / 3600 ); |
---|
[115] | 114 | $time = $hours ? $time % ($hours * 3600) : $time; |
---|
| 115 | |
---|
[128] | 116 | //printf( "time = %s, days = %s, hours = %s\n", $time, $days, $hours ); |
---|
| 117 | |
---|
[114] | 118 | if( $hours > 0 ) { |
---|
| 119 | $date_str .= $hours . ':'; |
---|
[128] | 120 | $date_unit = 'hours'; |
---|
[114] | 121 | } |
---|
[115] | 122 | |
---|
[114] | 123 | $minutes = intval( $time / 60 ); |
---|
[115] | 124 | $seconds = $minutes ? $time % ($minutes * 60) : $time; |
---|
| 125 | |
---|
[114] | 126 | if( $minutes > 0 ) { |
---|
[115] | 127 | |
---|
| 128 | if( $minutes >= 10 ) |
---|
| 129 | $date_str .= $minutes . ':'; |
---|
| 130 | else |
---|
| 131 | $date_str .= '0' . $minutes . ':'; |
---|
| 132 | |
---|
[114] | 133 | $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit; |
---|
[128] | 134 | } else { |
---|
| 135 | if($hours > 0 ) { |
---|
| 136 | $date_str .= '00:'; |
---|
| 137 | $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit; |
---|
| 138 | } |
---|
[114] | 139 | } |
---|
[115] | 140 | |
---|
[128] | 141 | |
---|
[114] | 142 | $date_unit = (!isset($date_unit)) ? 'seconds' : $date_unit; |
---|
| 143 | |
---|
[115] | 144 | if( $seconds > 0 ) { |
---|
| 145 | |
---|
| 146 | if( $seconds >= 10 ) |
---|
| 147 | $date_str .= $seconds . ' ' . $date_unit; |
---|
| 148 | else |
---|
| 149 | $date_str .= '0' . $seconds . ' ' . $date_unit; |
---|
| 150 | |
---|
[128] | 151 | } else if ( $hours > 0 or $minutes > 0 ) |
---|
| 152 | |
---|
[115] | 153 | $date_str .= '00 ' . $date_unit; |
---|
| 154 | |
---|
[128] | 155 | if( $days > 0) { |
---|
| 156 | |
---|
| 157 | if( $hours > 0 or $minutes > 0 or $seconds > 0 ) |
---|
| 158 | $date_str = $day_str . ' - ' . $date_str; |
---|
| 159 | else |
---|
| 160 | $date_str = $day_str; |
---|
| 161 | } |
---|
| 162 | |
---|
[114] | 163 | return $date_str; |
---|
| 164 | } |
---|
| 165 | |
---|
[246] | 166 | //function makeDate( $time ) { |
---|
| 167 | // return strftime( "%a %d %b %Y %H:%M:%S", $time ); |
---|
| 168 | //} |
---|
[114] | 169 | |
---|
| 170 | function colorRed( $color ) { |
---|
| 171 | return substr( $color, 0, 2 ); |
---|
| 172 | } |
---|
| 173 | function colorGreen( $color ) { |
---|
| 174 | return substr( $color, 2, 2 ); |
---|
| 175 | } |
---|
| 176 | function colorBlue( $color ) { |
---|
| 177 | return substr( $color, 4, 2 ); |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | function colorDiffer( $first, $second ) { |
---|
| 181 | |
---|
| 182 | // Make sure these two colors differ atleast 50 R/G/B |
---|
| 183 | $min_diff = 50; |
---|
| 184 | |
---|
[147] | 185 | $c1r = hexDec( colorRed( $first ) ); |
---|
| 186 | $c1g = hexDec( colorGreen( $first ) ); |
---|
| 187 | $c1b = hexDec( colorBlue( $first ) ); |
---|
[114] | 188 | |
---|
[147] | 189 | $c2r = hexDec( colorRed( $second ) ); |
---|
| 190 | $c2g = hexDec( colorGreen( $second ) ); |
---|
| 191 | $c2b = hexDec( colorBlue( $second ) ); |
---|
[114] | 192 | |
---|
| 193 | $rdiff = ($c1r >= $c2r) ? $c1r - $c2r : $c2r - $c1r; |
---|
| 194 | $gdiff = ($c1g >= $c2g) ? $c1g - $c2g : $c2g - $c1g; |
---|
| 195 | $bdiff = ($c1b >= $c2b) ? $c1b - $c2b : $c2b - $c1b; |
---|
| 196 | |
---|
| 197 | if( $rdiff >= $min_diff or $gdiff >= $min_diff or $bdiff >= $min_diff ) |
---|
| 198 | return TRUE; |
---|
| 199 | else |
---|
| 200 | return FALSE; |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | function randomColor( $known_colors ) { |
---|
| 204 | |
---|
[147] | 205 | $start = "004E00"; |
---|
| 206 | |
---|
| 207 | $start_red = colorRed( $start ); |
---|
| 208 | $start_green = colorGreen( $start ); |
---|
| 209 | $start_blue = colorBlue( $start ); |
---|
| 210 | |
---|
| 211 | $end = "FFFFFF"; |
---|
[114] | 212 | |
---|
[147] | 213 | $end_red = colorRed( $end ); |
---|
| 214 | $end_green = colorGreen( $end ); |
---|
| 215 | $end_blue = colorBlue( $end ); |
---|
[114] | 216 | |
---|
[147] | 217 | $change_color = TRUE; |
---|
[114] | 218 | |
---|
[147] | 219 | while( $change_color ) { |
---|
[114] | 220 | |
---|
[147] | 221 | $change_color = FALSE; |
---|
[114] | 222 | |
---|
[147] | 223 | $new_red = rand( hexDec( $start_red ), hexDec( $end_red ) ); |
---|
| 224 | $new_green = rand( hexDec( $start_green ), hexDec( $end_green ) ); |
---|
| 225 | $new_blue = rand( hexDec( $start_blue ), hexDec( $end_blue ) ); |
---|
[114] | 226 | |
---|
[147] | 227 | $new = decHex( $new_red ) . decHex( $new_green ) . decHex( $new_blue ); |
---|
[114] | 228 | |
---|
[147] | 229 | foreach( $known_colors as $old ) |
---|
[114] | 230 | |
---|
[147] | 231 | if( !colorDiffer( $new, $old ) ) |
---|
[114] | 232 | |
---|
[147] | 233 | $change_color = TRUE; |
---|
[114] | 234 | } |
---|
| 235 | |
---|
| 236 | // Whoa! Actually found a good color ;) |
---|
[147] | 237 | return $new; |
---|
[114] | 238 | } |
---|
| 239 | |
---|
[126] | 240 | function drawJobPie() { |
---|
| 241 | } |
---|
[114] | 242 | |
---|
[126] | 243 | function drawUserPie() { |
---|
[124] | 244 | |
---|
[126] | 245 | } |
---|
| 246 | |
---|
| 247 | function drawQueuePie() { |
---|
| 248 | |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | |
---|
[127] | 252 | function drawPie() { |
---|
[124] | 253 | |
---|
[127] | 254 | global $jobs, $gnodes, $piefilter, $filter; |
---|
[114] | 255 | |
---|
[126] | 256 | $nodes = $gnodes; |
---|
[127] | 257 | |
---|
| 258 | if( isset($piefilter) ) |
---|
| 259 | $pie_args = "title=" . rawurlencode("Cluster ".$piefilter." usage"); |
---|
| 260 | else |
---|
| 261 | $pie_args = "title=" . rawurlencode("Cluster queue usage"); |
---|
| 262 | |
---|
[114] | 263 | $pie_args .= "&size=250x150"; |
---|
| 264 | |
---|
| 265 | $queues = array(); |
---|
| 266 | $nr_jobs = count( $jobs ); |
---|
| 267 | $nr_nodes = count( $nodes ); |
---|
| 268 | |
---|
| 269 | $emptynodes = 0; |
---|
| 270 | |
---|
[123] | 271 | $job_weight = array(); |
---|
| 272 | |
---|
[114] | 273 | foreach( $nodes as $node ) { |
---|
| 274 | |
---|
| 275 | $myjobs = $node->getJobs(); |
---|
| 276 | |
---|
| 277 | if( count( $myjobs ) == 0 ) |
---|
| 278 | $emptynodes++; |
---|
| 279 | } |
---|
[123] | 280 | $used_nodes = $nr_nodes - $emptynodes; |
---|
[114] | 281 | |
---|
| 282 | $empty_percentage = ($emptynodes / $nr_nodes) * 100; |
---|
| 283 | $job_percentage = 100 - $empty_percentage; |
---|
| 284 | |
---|
[127] | 285 | $qcolors = array(); |
---|
[114] | 286 | $color = randomColor( $qcolors ); |
---|
| 287 | $qcolors[] = $color; |
---|
| 288 | $pie_args .= "&free=$empty_percentage,$color"; |
---|
| 289 | |
---|
[127] | 290 | if( isset( $piefilter ) ) |
---|
| 291 | $filterpie = array(); |
---|
| 292 | |
---|
[123] | 293 | foreach( $nodes as $node ) { |
---|
[114] | 294 | |
---|
[123] | 295 | $node_jobs = $node->getJobs(); |
---|
| 296 | $nr_node_jobs = count( $node_jobs ); |
---|
| 297 | $myhost = $node->getHostname(); |
---|
[114] | 298 | |
---|
[123] | 299 | foreach( $node_jobs as $myjob ) { |
---|
[114] | 300 | |
---|
[123] | 301 | // Determine the weight of this job on the node it is running |
---|
| 302 | // - what percentage of the node is in use by this job |
---|
| 303 | // |
---|
| 304 | $job_weight[$myjob] = ( 100 / count( $node_jobs ) ) / 100; |
---|
| 305 | $qname = $jobs[$myjob][queue]; |
---|
| 306 | |
---|
[127] | 307 | if( isset($piefilter) ) { |
---|
| 308 | $countjob = 1; |
---|
| 309 | if( $piefilter == 'id' ) { |
---|
| 310 | if( $myjob != $filter[$piefilter] ) |
---|
| 311 | $countjob = 0; |
---|
| 312 | } else if( $piefilter == 'user' ) { |
---|
| 313 | if( $jobs[$myjob][owner] != $filter[$piefilter] ) |
---|
| 314 | $countjob = 0; |
---|
| 315 | } else { |
---|
| 316 | if( $jobs[$myjob][$piefilter] != $filter[$piefilter] ) |
---|
| 317 | $countjob = 0; |
---|
| 318 | } |
---|
| 319 | |
---|
| 320 | if( $countjob ) { |
---|
| 321 | |
---|
| 322 | if( !isset( $filterpie[$filter[$piefilter]] ) ) |
---|
| 323 | $filterpie[$filter[$piefilter]] = $job_weight[$myjob]; |
---|
| 324 | else |
---|
| 325 | $filterpie[$filter[$piefilter]] = $filterpie[$filter[$piefilter]] + $job_weight[$myjob]; |
---|
| 326 | } else { |
---|
| 327 | if( !isset( $filterpie["other"] ) ) |
---|
| 328 | $filterpie["other"] = $job_weight[$myjob]; |
---|
| 329 | else |
---|
| 330 | $filterpie["other"] = $filterpie["other"] + $job_weight[$myjob]; |
---|
| 331 | |
---|
| 332 | } |
---|
| 333 | |
---|
| 334 | } else { |
---|
| 335 | |
---|
| 336 | if( !isset( $queues[$qname] ) ) |
---|
| 337 | $queues[$qname] = $job_weight[$myjob]; |
---|
| 338 | else |
---|
| 339 | $queues[$qname] = $queues[$qname] + $job_weight[$myjob]; |
---|
| 340 | } |
---|
[114] | 341 | } |
---|
| 342 | } |
---|
| 343 | |
---|
[127] | 344 | //$qcolors = array(); |
---|
| 345 | if( isset( $piefilter ) ) |
---|
| 346 | $graphvals = $filterpie; |
---|
| 347 | else |
---|
| 348 | $graphvals = $queues; |
---|
[114] | 349 | |
---|
[127] | 350 | foreach( $graphvals as $name => $totalweight) { |
---|
| 351 | |
---|
[123] | 352 | $percentage = ( $totalweight / $used_nodes ) * $job_percentage; |
---|
| 353 | |
---|
[114] | 354 | $color = randomColor( $qcolors ); |
---|
| 355 | $qcolors[] = $color; |
---|
[127] | 356 | $pie_args .= "&$name=$percentage,$color"; |
---|
[114] | 357 | } |
---|
| 358 | $pie = "../../pie.php?$pie_args"; |
---|
| 359 | |
---|
| 360 | return $pie; |
---|
| 361 | } |
---|
| 362 | |
---|
| 363 | |
---|
[117] | 364 | function sortJobs( $jobs, $sortby, $sortorder ) { |
---|
[114] | 365 | |
---|
[117] | 366 | $sorted = array(); |
---|
[114] | 367 | |
---|
[117] | 368 | $cmp = create_function( '$a, $b', |
---|
| 369 | "global \$sortby, \$sortorder;". |
---|
[116] | 370 | |
---|
[117] | 371 | "if( \$a == \$b ) return 0;". |
---|
[116] | 372 | |
---|
[117] | 373 | "if (\$sortorder==\"desc\")". |
---|
| 374 | "return ( \$a < \$b ) ? 1 : -1;". |
---|
| 375 | "else if (\$sortorder==\"asc\")". |
---|
| 376 | "return ( \$a > \$b ) ? 1 : -1;" ); |
---|
| 377 | |
---|
| 378 | foreach( $jobs as $jobid => $jobattrs ) { |
---|
| 379 | |
---|
| 380 | $state = $jobattrs[status]; |
---|
| 381 | $user = $jobattrs[owner]; |
---|
| 382 | $queue = $jobattrs[queue]; |
---|
| 383 | $name = $jobattrs[name]; |
---|
| 384 | $req_cpu = $jobattrs[requested_time]; |
---|
| 385 | $req_memory = $jobattrs[requested_memory]; |
---|
[135] | 386 | |
---|
| 387 | if( $state == 'R' ) |
---|
| 388 | $nodes = count( $jobattrs[nodes] ); |
---|
| 389 | else |
---|
| 390 | $nodes = $jobattrs[nodes]; |
---|
| 391 | |
---|
[117] | 392 | $ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1; |
---|
| 393 | $cpus = $nodes * $ppn; |
---|
[245] | 394 | $queued_time = (int) $jobattrs[queued_timestamp]; |
---|
[117] | 395 | $start_time = (int) $jobattrs[start_timestamp]; |
---|
| 396 | $runningtime = $report_time - $start_time; |
---|
| 397 | |
---|
| 398 | switch( $sortby ) { |
---|
| 399 | case "id": |
---|
| 400 | $sorted[$jobid] = $jobid; |
---|
| 401 | break; |
---|
| 402 | |
---|
| 403 | case "state": |
---|
| 404 | $sorted[$jobid] = $state; |
---|
| 405 | break; |
---|
| 406 | |
---|
| 407 | case "user": |
---|
| 408 | $sorted[$jobid] = $user; |
---|
| 409 | break; |
---|
| 410 | |
---|
| 411 | case "queue": |
---|
| 412 | $sorted[$jobid] = $queue; |
---|
| 413 | break; |
---|
| 414 | |
---|
| 415 | case "name": |
---|
| 416 | $sorted[$jobid] = $name; |
---|
| 417 | break; |
---|
| 418 | |
---|
| 419 | case "req_cpu": |
---|
[128] | 420 | $sorted[$jobid] = timeToEpoch( $req_cpu ); |
---|
[117] | 421 | break; |
---|
| 422 | |
---|
| 423 | case "req_mem": |
---|
| 424 | $sorted[$jobid] = $req_memory; |
---|
| 425 | break; |
---|
| 426 | |
---|
| 427 | case "nodes": |
---|
| 428 | $sorted[$jobid] = $nodes; |
---|
| 429 | break; |
---|
| 430 | |
---|
| 431 | case "cpus": |
---|
| 432 | $sorted[$jobid] = $cpus; |
---|
| 433 | break; |
---|
| 434 | |
---|
[245] | 435 | case "queued": |
---|
| 436 | $sorted[$jobid] = $queued_time; |
---|
| 437 | break; |
---|
| 438 | |
---|
[117] | 439 | case "start": |
---|
| 440 | $sorted[$jobid] = $start_time; |
---|
| 441 | break; |
---|
| 442 | |
---|
| 443 | case "runningtime": |
---|
| 444 | $sorted[$jobid] = $runningtime; |
---|
| 445 | break; |
---|
| 446 | |
---|
| 447 | default: |
---|
| 448 | break; |
---|
| 449 | |
---|
| 450 | } |
---|
| 451 | } |
---|
| 452 | |
---|
[128] | 453 | //uasort( $sorted, $cmp ); |
---|
| 454 | if( $sortorder == "asc" ) |
---|
| 455 | arsort( $sorted ); |
---|
| 456 | else if( $sortorder == "desc" ) |
---|
| 457 | asort( $sorted ); |
---|
[117] | 458 | |
---|
| 459 | return $sorted; |
---|
| 460 | } |
---|
| 461 | |
---|
| 462 | function makeOverview() { |
---|
| 463 | |
---|
| 464 | global $jobs, $nodes, $heartbeat, $clustername, $tpl; |
---|
[126] | 465 | global $sortorder, $sortby, $filter, $sh, $hc, $m; |
---|
| 466 | global $cluster_url, $get_metric_string, $host_url, $metrics; |
---|
[129] | 467 | global $start, $end, $reports, $gnodes, $default_showhosts; |
---|
[263] | 468 | global $COLUMN_QUEUED, $COLUMN_REQUESTED_MEMORY, $hostname; |
---|
[126] | 469 | $metricname = $m; |
---|
| 470 | |
---|
[117] | 471 | $tpl->assign("sortorder", $sortorder ); |
---|
| 472 | $tpl->assign("sortby", $sortby ); |
---|
| 473 | |
---|
| 474 | $sorted_jobs = sortJobs( $jobs, $sortby, $sortorder ); |
---|
| 475 | |
---|
[118] | 476 | $even = 1; |
---|
| 477 | |
---|
[135] | 478 | $used_jobs = 0; |
---|
| 479 | $used_cpus = 0; |
---|
| 480 | $used_nodes = 0; |
---|
[124] | 481 | |
---|
[208] | 482 | $queued_jobs = 0; |
---|
| 483 | $queued_nodes = 0; |
---|
| 484 | $queued_cpus = 0; |
---|
| 485 | |
---|
| 486 | $total_nodes = 0; |
---|
| 487 | $total_cpus = 0; |
---|
| 488 | $total_jobs = 0; |
---|
| 489 | |
---|
[135] | 490 | $all_used_nodes = array(); |
---|
[208] | 491 | $total_used_nodes = array(); |
---|
[124] | 492 | |
---|
[208] | 493 | $running_name_nodes = array(); |
---|
| 494 | |
---|
| 495 | $running_nodes = 0; |
---|
| 496 | $running_jobs = 0; |
---|
| 497 | $running_cpus = 0; |
---|
| 498 | |
---|
[135] | 499 | $avail_nodes = count( $gnodes ); |
---|
| 500 | $avail_cpus = cluster_sum("cpu_num", $metrics); |
---|
| 501 | |
---|
| 502 | $view_cpus = 0; |
---|
| 503 | $view_jobs = 0; |
---|
| 504 | $view_nodes = 0; |
---|
| 505 | |
---|
[208] | 506 | $all_nodes = 0; |
---|
| 507 | $all_jobs = 0; |
---|
| 508 | $all_cpus = 0; |
---|
[135] | 509 | |
---|
[208] | 510 | $view_name_nodes = array(); |
---|
| 511 | |
---|
[241] | 512 | if( $COLUMN_REQUESTED_MEMORY ) { |
---|
[242] | 513 | $tpl->newBlock( "column_header_req_mem" ); |
---|
[241] | 514 | } |
---|
| 515 | |
---|
[242] | 516 | if( $COLUMN_QUEUED ) { |
---|
| 517 | $tpl->newBlock( "column_header_queued" ); |
---|
| 518 | } |
---|
| 519 | |
---|
[263] | 520 | $last_displayed_job = null; |
---|
| 521 | |
---|
[117] | 522 | foreach( $sorted_jobs as $jobid => $sortdec ) { |
---|
| 523 | |
---|
| 524 | $report_time = $jobs[$jobid][reported]; |
---|
| 525 | |
---|
[208] | 526 | if( $jobs[$jobid][status] == 'R' ) |
---|
| 527 | $nodes = count( $jobs[$jobid][nodes] ); |
---|
| 528 | else if( $jobs[$jobid][status] == 'Q' ) |
---|
| 529 | $nodes = $jobs[$jobid][nodes]; |
---|
| 530 | |
---|
[124] | 531 | $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1; |
---|
| 532 | $cpus = $nodes * $ppn; |
---|
| 533 | |
---|
[208] | 534 | if( $report_time == $heartbeat ) { |
---|
[124] | 535 | |
---|
[208] | 536 | $display_job = 1; |
---|
| 537 | |
---|
| 538 | foreach( $jobs[$jobid][nodes] as $tempnode ) |
---|
| 539 | $all_used_nodes[] = $tempnode; |
---|
| 540 | |
---|
[135] | 541 | $used_cpus += $cpus; |
---|
| 542 | |
---|
[208] | 543 | if( $jobs[$jobid][status] == 'R' ) { |
---|
| 544 | $running_cpus += $cpus; |
---|
| 545 | $running_jobs++; |
---|
[117] | 546 | |
---|
[268] | 547 | $found_node_job = 0; |
---|
| 548 | |
---|
[263] | 549 | foreach( $jobs[$jobid][nodes] as $tempnode ) { |
---|
[208] | 550 | $running_name_nodes[] = $tempnode; |
---|
[263] | 551 | |
---|
| 552 | if( isset( $hostname ) && $hostname != '' ) |
---|
| 553 | //$filter[host] = $hostname; |
---|
| 554 | |
---|
| 555 | $domain_len = 0 - strlen( $jobs[$jobid][domain] ); |
---|
| 556 | $hostnode = $tempnode; |
---|
| 557 | if( substr( $hostnode, $domain_len ) != $jobs[$jobid][domain] ) { |
---|
| 558 | $hostnode = $hostnode. '.'. $jobs[$jobid][domain]; |
---|
| 559 | } |
---|
| 560 | |
---|
[268] | 561 | if( $hostname == $hostnode ) { |
---|
| 562 | $found_node_job = 1; |
---|
| 563 | $display_job = 1; |
---|
| 564 | } else if( !$found_node_job ) { |
---|
[263] | 565 | $display_job = 0; |
---|
[268] | 566 | } |
---|
[263] | 567 | } |
---|
[208] | 568 | } |
---|
[117] | 569 | |
---|
[208] | 570 | if( $jobs[$jobid][status] == 'Q' ) { |
---|
[263] | 571 | if( isset( $hostname ) && $hostname != '' ) |
---|
| 572 | $display_job = 0; |
---|
| 573 | |
---|
[208] | 574 | $queued_cpus += $cpus; |
---|
| 575 | $queued_nodes += $nodes; |
---|
| 576 | $queued_jobs++; |
---|
| 577 | } |
---|
| 578 | |
---|
[119] | 579 | foreach( $filter as $filtername=>$filtervalue ) { |
---|
[118] | 580 | |
---|
[124] | 581 | if( $filtername == 'id' && $jobid != $filtervalue ) |
---|
| 582 | $display_job = 0; |
---|
| 583 | else if( $filtername == 'state' && $jobs[$jobid][status] != $filtervalue ) |
---|
| 584 | $display_job = 0; |
---|
| 585 | else if( $filtername == 'queue' && $jobs[$jobid][queue] != $filtervalue ) |
---|
| 586 | $display_job = 0; |
---|
| 587 | else if( $filtername == 'user' && $jobs[$jobid][owner] != $filtervalue ) |
---|
| 588 | $display_job = 0; |
---|
[118] | 589 | } |
---|
| 590 | |
---|
[119] | 591 | if( $display_job ) { |
---|
[117] | 592 | |
---|
[119] | 593 | $tpl->newBlock("node"); |
---|
| 594 | $tpl->assign( "clustername", $clustername ); |
---|
| 595 | $tpl->assign("id", $jobid ); |
---|
[263] | 596 | |
---|
| 597 | $last_displayed_job = $jobid; |
---|
| 598 | |
---|
[119] | 599 | $tpl->assign("state", $jobs[$jobid][status] ); |
---|
[240] | 600 | |
---|
| 601 | $fullstate = ''; |
---|
| 602 | if( $jobs[$jobid][status] == 'R' ) { |
---|
| 603 | $fullstate = "Running"; |
---|
| 604 | } else if( $jobs[$jobid][status] == 'Q' ) { |
---|
| 605 | $fullstate = "Queued"; |
---|
| 606 | } |
---|
| 607 | |
---|
| 608 | $tpl->assign("fullstate", $fullstate ); |
---|
| 609 | |
---|
[119] | 610 | $tpl->assign("user", $jobs[$jobid][owner] ); |
---|
| 611 | $tpl->assign("queue", $jobs[$jobid][queue] ); |
---|
[240] | 612 | |
---|
| 613 | $fulljobname = $jobs[$jobid][name]; |
---|
| 614 | $shortjobname = ''; |
---|
| 615 | |
---|
| 616 | $tpl->assign("fulljobname", $fulljobname ); |
---|
| 617 | |
---|
| 618 | if( mb_strwidth( $fulljobname ) > 10 ) { |
---|
| 619 | $tpl->newBlock("jobname_hint_start"); |
---|
| 620 | $tpl->gotoBlock("node"); |
---|
| 621 | |
---|
| 622 | $shortjobname = mb_strimwidth( $fulljobname, 0, 9 ) . '..'; |
---|
| 623 | } else { |
---|
| 624 | $shortjobname = $fulljobname; |
---|
| 625 | } |
---|
| 626 | |
---|
| 627 | $tpl->assign("name", $shortjobname ); |
---|
| 628 | |
---|
| 629 | if( strlen( $fulljobname ) > 10 ) { |
---|
| 630 | $tpl->newBlock("jobname_hint_end"); |
---|
| 631 | $tpl->gotoBlock("node"); |
---|
| 632 | } |
---|
| 633 | |
---|
[126] | 634 | $domain = $jobs[$jobid][domain]; |
---|
[120] | 635 | $tpl->assign("req_cpu", makeTime( timeToEpoch( $jobs[$jobid][requested_time] ) ) ); |
---|
[135] | 636 | |
---|
[241] | 637 | if( $COLUMN_REQUESTED_MEMORY ) { |
---|
| 638 | $tpl->newBlock( "column_req_mem" ); |
---|
| 639 | $tpl->assign( "req_memory", $jobs[$jobid][requested_memory] ); |
---|
| 640 | $tpl->gotoBlock( "node" ); |
---|
| 641 | } |
---|
[135] | 642 | |
---|
[242] | 643 | if( $COLUMN_QUEUED ) { |
---|
| 644 | $tpl->newBlock( "column_queued" ); |
---|
[243] | 645 | $tpl->assign( "queued", makeDate( $jobs[$jobid][queued_timestamp] ) ); |
---|
[242] | 646 | $tpl->gotoBlock( "node" ); |
---|
| 647 | } |
---|
| 648 | |
---|
[119] | 649 | $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1; |
---|
| 650 | $cpus = $nodes * $ppn; |
---|
| 651 | $tpl->assign("nodes", $nodes ); |
---|
| 652 | $tpl->assign("cpus", $cpus ); |
---|
| 653 | $start_time = (int) $jobs[$jobid][start_timestamp]; |
---|
[126] | 654 | $job_start = $start_time; |
---|
[119] | 655 | |
---|
[135] | 656 | $view_cpus += $cpus; |
---|
| 657 | $view_jobs++; |
---|
[124] | 658 | |
---|
[135] | 659 | if( $jobs[$jobid][status] == 'R' ) |
---|
| 660 | foreach( $jobs[$jobid][nodes] as $tempnode ) |
---|
[208] | 661 | $view_name_nodes[] = $tempnode; |
---|
[135] | 662 | else if( $jobs[$jobid][status] == 'Q' ) |
---|
[208] | 663 | $view_nodes += (int) $jobs[$jobid][nodes]; |
---|
[135] | 664 | |
---|
[119] | 665 | if( $even ) { |
---|
| 666 | |
---|
| 667 | $tpl->assign("nodeclass", "even"); |
---|
| 668 | $even = 0; |
---|
| 669 | } else { |
---|
| 670 | |
---|
| 671 | $tpl->assign("nodeclass", "odd"); |
---|
| 672 | $even = 1; |
---|
| 673 | } |
---|
| 674 | |
---|
| 675 | if( $start_time ) { |
---|
| 676 | |
---|
| 677 | $runningtime = makeTime( $report_time - $start_time ); |
---|
[126] | 678 | $job_runningtime = $report_time - $start_time; |
---|
[119] | 679 | $tpl->assign("started", makeDate( $start_time ) ); |
---|
| 680 | $tpl->assign("runningtime", $runningtime ); |
---|
| 681 | } |
---|
[117] | 682 | } |
---|
[116] | 683 | } |
---|
[114] | 684 | } |
---|
[250] | 685 | $all_used_nodes = array_unique( $all_used_nodes ); |
---|
| 686 | $view_name_nodes = array_unique( $view_name_nodes ); |
---|
| 687 | $running_name_nodes = array_unique( $running_name_nodes ); |
---|
[208] | 688 | |
---|
[135] | 689 | $used_nodes = count( $all_used_nodes ); |
---|
[208] | 690 | $view_nodes += count( $view_name_nodes ); |
---|
| 691 | $running_nodes += count( $running_name_nodes ); |
---|
[124] | 692 | |
---|
[208] | 693 | $total_nodes = $queued_nodes + $running_nodes; |
---|
| 694 | $total_cpus = $queued_cpus + $running_cpus; |
---|
| 695 | $total_jobs = $queued_jobs + $running_jobs; |
---|
| 696 | |
---|
[135] | 697 | $tpl->assignGlobal("avail_nodes", $avail_nodes ); |
---|
| 698 | $tpl->assignGlobal("avail_cpus", $avail_cpus ); |
---|
| 699 | |
---|
[208] | 700 | $tpl->assignGlobal("queued_nodes", $queued_nodes ); |
---|
| 701 | $tpl->assignGlobal("queued_jobs", $queued_jobs ); |
---|
| 702 | $tpl->assignGlobal("queued_cpus", $queued_cpus ); |
---|
| 703 | |
---|
| 704 | $tpl->assignGlobal("total_nodes", $total_nodes ); |
---|
| 705 | $tpl->assignGlobal("total_jobs", $total_jobs ); |
---|
| 706 | $tpl->assignGlobal("total_cpus", $total_cpus ); |
---|
| 707 | |
---|
| 708 | $tpl->assignGlobal("running_nodes", $running_nodes ); |
---|
| 709 | $tpl->assignGlobal("running_jobs", $running_jobs ); |
---|
| 710 | $tpl->assignGlobal("running_cpus", $running_cpus ); |
---|
| 711 | |
---|
[135] | 712 | $tpl->assignGlobal("used_nodes", $used_nodes ); |
---|
| 713 | $tpl->assignGlobal("used_jobs", $used_jobs ); |
---|
| 714 | $tpl->assignGlobal("used_cpus", $used_cpus ); |
---|
| 715 | |
---|
[209] | 716 | $free_nodes = $avail_nodes - $running_nodes; |
---|
| 717 | $free_cpus = $avail_cpus - $running_cpus; |
---|
[208] | 718 | |
---|
| 719 | $tpl->assignGlobal("free_nodes", $free_nodes ); |
---|
| 720 | $tpl->assignGlobal("free_cpus", $free_cpus ); |
---|
| 721 | |
---|
[135] | 722 | $tpl->assignGlobal("view_nodes", $view_nodes ); |
---|
| 723 | $tpl->assignGlobal("view_jobs", $view_jobs ); |
---|
| 724 | $tpl->assignGlobal("view_cpus", $view_cpus ); |
---|
| 725 | |
---|
[124] | 726 | $tpl->assignGlobal("report_time", makeDate( $heartbeat)); |
---|
[126] | 727 | |
---|
[266] | 728 | if( intval($view_jobs) == 1 and $start_time ) |
---|
| 729 | if( $last_displayed_job != null ) |
---|
| 730 | $filter[id] = $last_displayed_job; |
---|
[263] | 731 | |
---|
[266] | 732 | makeHeader( 'overview' ); |
---|
[263] | 733 | setupFilterSettings(); |
---|
| 734 | |
---|
[188] | 735 | if( intval($view_jobs) == 1 and $start_time ) { |
---|
[263] | 736 | |
---|
[126] | 737 | $tpl->newBlock( "showhosts" ); |
---|
| 738 | |
---|
| 739 | # Present a width list |
---|
| 740 | $cols_menu = "<SELECT NAME=\"hc\" OnChange=\"toga_form.submit();\">\n"; |
---|
| 741 | |
---|
[263] | 742 | |
---|
[126] | 743 | $hostcols = ($hc) ? $hc : 4; |
---|
| 744 | |
---|
| 745 | foreach(range(1,25) as $cols) { |
---|
| 746 | $cols_menu .= "<OPTION VALUE=$cols "; |
---|
| 747 | if ($cols == $hostcols) |
---|
| 748 | $cols_menu .= "SELECTED"; |
---|
| 749 | $cols_menu .= ">$cols\n"; |
---|
| 750 | } |
---|
| 751 | $cols_menu .= "</SELECT>\n"; |
---|
| 752 | |
---|
| 753 | //$tpl->assign("cluster", $clustername); |
---|
| 754 | $tpl->assign("metric","$metricname $units"); |
---|
[127] | 755 | $tpl->assign("id", $filter[id]); |
---|
[126] | 756 | # Host columns menu defined in header.php |
---|
| 757 | $tpl->assign("cols_menu", $cols_menu); |
---|
| 758 | |
---|
[129] | 759 | $showhosts = isset($sh) ? $sh : $default_showhosts; |
---|
| 760 | //if( !$showhosts) $showhosts = $default_showhosts; |
---|
[126] | 761 | $tpl->assign("checked$showhosts", "checked"); |
---|
| 762 | |
---|
| 763 | if( $showhosts ) { |
---|
| 764 | //----- |
---|
| 765 | |
---|
| 766 | if( !isset($start) ) $start="jobstart"; |
---|
| 767 | if( !isset($stop) ) $stop="now"; |
---|
| 768 | //$tpl->assign("start", $start); |
---|
| 769 | //$tpl->assign("stop", $stop); |
---|
| 770 | |
---|
| 771 | $sorted_hosts = array(); |
---|
| 772 | $hosts_up = $jobs[$filter[id]][nodes]; |
---|
| 773 | |
---|
| 774 | $r = intval($job_runningtime * 1.25); |
---|
| 775 | |
---|
| 776 | $jobrange = ($job_runningtime < 3600) ? -3600 : -$r ; |
---|
| 777 | $jobstart = $report_time - $job_runningtime; |
---|
| 778 | |
---|
| 779 | if ($reports[$metricname]) |
---|
| 780 | $metricval = "g"; |
---|
| 781 | else |
---|
| 782 | $metricval = "m"; |
---|
[263] | 783 | |
---|
[126] | 784 | foreach ($hosts_up as $host ) { |
---|
[195] | 785 | |
---|
| 786 | $domain_len = 0 - strlen( $domain ); |
---|
| 787 | if( substr( $host, $domain_len ) != $domain ) { |
---|
| 788 | $host = $host. '.'.$domain; |
---|
| 789 | } |
---|
[126] | 790 | $cpus = $metrics[$host]["cpu_num"][VAL]; |
---|
| 791 | if (!$cpus) $cpus=1; |
---|
| 792 | $load_one = $metrics[$host]["load_one"][VAL]; |
---|
| 793 | $load = ((float) $load_one)/$cpus; |
---|
| 794 | $host_load[$host] = $load; |
---|
| 795 | $percent_hosts[load_color($load)] += 1; |
---|
| 796 | if ($metricname=="load_one") |
---|
| 797 | $sorted_hosts[$host] = $load; |
---|
| 798 | else |
---|
| 799 | $sorted_hosts[$host] = $metrics[$host][$metricname][VAL]; |
---|
| 800 | } |
---|
| 801 | switch ($sort) { |
---|
| 802 | case "descending": |
---|
| 803 | arsort($sorted_hosts); |
---|
| 804 | break; |
---|
| 805 | case "by hostname": |
---|
| 806 | ksort($sorted_hosts); |
---|
| 807 | break; |
---|
| 808 | default: |
---|
| 809 | case "ascending": |
---|
| 810 | asort($sorted_hosts); |
---|
| 811 | break; |
---|
| 812 | } |
---|
| 813 | |
---|
| 814 | //$sorted_hosts = array_merge($down_hosts, $sorted_hosts); |
---|
| 815 | |
---|
| 816 | # First pass to find the max value in all graphs for this |
---|
| 817 | # metric. The $start,$end variables comes from get_context.php, |
---|
| 818 | # included in index.php. |
---|
| 819 | list($min, $max) = find_limits($sorted_hosts, $metricname); |
---|
| 820 | |
---|
| 821 | # Second pass to output the graphs or metrics. |
---|
| 822 | $i = 1; |
---|
| 823 | foreach ( $sorted_hosts as $host=>$value ) { |
---|
| 824 | $tpl->newBlock ("sorted_list"); |
---|
| 825 | //$host = $host. '.'.$domain; |
---|
| 826 | $host_url = rawurlencode($host); |
---|
| 827 | $cluster_url = rawurlencode($clustername); |
---|
| 828 | |
---|
| 829 | $textval = ""; |
---|
| 830 | //printf("host = %s, value = %s", $host, $value); |
---|
| 831 | //echo "$host: $value, "; |
---|
| 832 | $val = $metrics[$host][$metricname]; |
---|
| 833 | $class = "metric"; |
---|
[148] | 834 | $host_link="\"../../?c=$cluster_url&h=$host_url&r=job&jr=$jobrange&js=$jobstart\""; |
---|
[126] | 835 | |
---|
| 836 | if ($val[TYPE]=="timestamp" or $always_timestamp[$metricname]) { |
---|
| 837 | $textval = date("r", $val[VAL]); |
---|
| 838 | } elseif ($val[TYPE]=="string" or $val[SLOPE]=="zero" or $always_constant[$metricname] or ($max_graphs > 0 and $i > $max_graphs )) { |
---|
| 839 | $textval = "$val[VAL] $val[UNITS]"; |
---|
| 840 | } else { |
---|
| 841 | $load_color = load_color($host_load[$host]); |
---|
| 842 | $graphargs = ($reports[$metricname]) ? "g=$metricname&" : "m=$metricname&"; |
---|
[193] | 843 | $graphargs .= "z=small&c=$cluster_url&h=$host_url&l=$load_color" ."&v=$val[VAL]&r=job&jr=$jobrange&js=$jobstart"; |
---|
| 844 | if( $max > 0 ) { |
---|
| 845 | |
---|
| 846 | $graphargs .= "&x=$max&n=$min"; |
---|
| 847 | } |
---|
[126] | 848 | } |
---|
| 849 | if ($textval) { |
---|
| 850 | $cell="<td class=$class>". "<b><a href=$host_link>$host</a></b><br>". "<i>$metricname:</i> <b>$textval</b></td>"; |
---|
| 851 | } else { |
---|
[239] | 852 | $cell="<td><a href=$host_link>". "<img src=\"../../graph.php?$graphargs\" ". "alt=\"$host\" border=0></a></td>"; |
---|
[126] | 853 | } |
---|
| 854 | |
---|
| 855 | $tpl->assign("metric_image", $cell); |
---|
| 856 | if (! ($i++ % $hostcols) ) |
---|
| 857 | $tpl->assign ("br", "</tr><tr>"); |
---|
| 858 | } |
---|
| 859 | } |
---|
| 860 | //--- |
---|
| 861 | } |
---|
[114] | 862 | } |
---|
[113] | 863 | ?> |
---|