Changeset 328
- Timestamp:
- 04/21/07 21:10:48 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/web/addons/job_monarch/overview.php
r326 r328 26 26 global $hosts_up, $m, $start, $end, $filterorder, $COLUMN_REQUESTED_MEMORY, $COLUMN_QUEUED, $COLUMN_NODES, $hostname, $piefilter; 27 27 28 $tpl->assign( "clustername", $clustername ); 29 30 if( $JOB_ARCHIVE ) 31 { 32 $tpl->assign( "cluster_url", rawurlencode($clustername) ); 33 } 34 28 35 $ds = new DataSource(); 29 36 $myxml_data = $ds->getData(); 30 37 31 $data_gatherer = new DataGatherer( $clustername ); 32 33 $tpl->assign( "clustername", $clustername ); 34 35 if( $JOB_ARCHIVE ) 36 $tpl->assign( "cluster_url", rawurlencode($clustername) ); 37 38 $data_gatherer = new DataGatherer( $clustername ); 38 39 $data_gatherer->parseXML( $myxml_data ); 39 40 40 $heartbeat = $data_gatherer->getHeartbeat(); 41 $jobs = $data_gatherer->getJobs(); 42 $gnodes = $data_gatherer->getNodes(); 43 $cpus = $data_gatherer->getCpus(); 44 45 function setupFilterSettings() { 41 $heartbeat = $data_gatherer->getHeartbeat(); 42 $jobs = $data_gatherer->getJobs(); 43 $gnodes = $data_gatherer->getNodes(); 44 $cpus = $data_gatherer->getCpus(); 45 46 function setupFilterSettings() 47 { 48 46 49 global $tpl, $filter, $clustername, $piefilter, $data_gatherer, $myxml_data; 47 50 … … 50 53 $tpl->gotoBlock( "_ROOT" ); 51 54 52 foreach( $filter as $filtername => $filtervalue ) { 55 foreach( $filter as $filtername => $filtervalue ) 56 { 53 57 $tpl->assign( "f_".$filtername, $filtervalue ); 54 $filter_image_url .= "&$filtername=$filtervalue"; 55 }56 57 //include( "./ci_test.php" ); 58 59 $filter_image_url .= "&$filtername=$filtervalue"; 60 } 61 58 62 session_start(); 59 //printf("data %s\n", strval( $myxml_data ) ); 60 $_SESSION["data"] = &$myxml_data; 61 62 $ic = new ClusterImage( $myxml_data, $clustername ); 63 64 $_SESSION["data"] = &$myxml_data; 65 66 $ic = new ClusterImage( $myxml_data, $clustername ); 67 63 68 $ic->setBig(); 64 69 $ic->setNoimage(); 65 70 $ic->draw(); 66 71 67 //$tpl->assign( "clusterimage", "./image.php?c=".rawurlencode($clustername)."&view=big-clusterimage".$filter_image_url );68 72 $tpl->assign( "clusterimage", "./image.php?". session_name() . "=" . session_id() ."&c=".rawurlencode($clustername)."&view=big-clusterimage".$filter_image_url ); 69 73 … … 77 81 $tpl->assign( "f_order", $filterorder ); 78 82 79 if( array_key_exists( "id", $filter ) ) 83 if( array_key_exists( "id", $filter ) ) 84 { 80 85 $piefilter = 'id'; 81 else if( array_key_exists( "user", $filter ) ) 86 } 87 else if( array_key_exists( "user", $filter ) ) 88 { 82 89 $piefilter = 'user'; 83 else if( array_key_exists( "queue", $filter ) ) 90 } 91 else if( array_key_exists( "queue", $filter ) ) 92 { 84 93 $piefilter = 'queue'; 85 86 $pie = drawPie(); 94 } 95 96 $pie = drawPie(); 97 87 98 $tpl->assign("pie", $pie ); 88 99 } 89 100 90 function timeToEpoch( $time ) { 91 92 $time_fields = explode( ':', $time ); 93 94 if( count($time_fields) == 3 ) { 95 96 $hours = $time_fields[0]; 97 $minutes = $time_fields[1]; 98 $seconds = $time_fields[2]; 99 100 } else if( count($time_fields) == 2 ) { 101 102 $hours = 0; 103 $minutes = $time_fields[0]; 104 $seconds = $time_fields[1]; 105 106 } else if( count($time_fields) == 1 ) { 107 108 $hours = 0; 109 $minutes = 0; 110 $seconds = $time_fields[0]; 111 } 112 113 $myepoch = intval( $seconds + (intval( $minutes * 60 )) + (intval( $hours * 3600 )) ); 101 function timeToEpoch( $time ) 102 { 103 $time_fields = explode( ':', $time ); 104 105 if( count( $time_fields ) == 3 ) 106 { 107 $hours = $time_fields[0]; 108 $minutes = $time_fields[1]; 109 $seconds = $time_fields[2]; 110 111 } 112 else if( count( $time_fields ) == 2 ) 113 { 114 $hours = 0; 115 $minutes = $time_fields[0]; 116 $seconds = $time_fields[1]; 117 118 } 119 else if( count( $time_fields ) == 1 ) 120 { 121 $hours = 0; 122 $minutes = 0; 123 $seconds = $time_fields[0]; 124 } 125 126 $myepoch = intval( $seconds + (intval( $minutes * 60 )) + (intval( $hours * 3600 )) ); 114 127 115 128 return $myepoch; 116 129 } 117 130 118 //function makeDate( $time ) { 119 // return strftime( "%a %d %b %Y %H:%M:%S", $time ); 120 //} 121 122 function colorRed( $color ) { 131 function colorRed( $color ) 132 { 123 133 return substr( $color, 0, 2 ); 124 134 } 125 function colorGreen( $color ) { 135 136 function colorGreen( $color ) 137 { 126 138 return substr( $color, 2, 2 ); 127 139 } 128 function colorBlue( $color ) { 140 141 function colorBlue( $color ) 142 { 129 143 return substr( $color, 4, 2 ); 130 144 } 131 145 132 function colorDiffer( $first, $second ) {133 146 function colorDiffer( $first, $second ) 147 { 134 148 // Make sure these two colors differ atleast 50 R/G/B 135 149 $min_diff = 50; 136 150 137 $c1r = hexDec( colorRed( $first ) ); 138 $c1g = hexDec( colorGreen( $first ) ); 139 $c1b = hexDec( colorBlue( $first ) ); 140 141 $c2r = hexDec( colorRed( $second ) ); 142 $c2g = hexDec( colorGreen( $second ) ); 143 $c2b = hexDec( colorBlue( $second ) ); 144 145 $rdiff = ($c1r >= $c2r) ? $c1r - $c2r : $c2r - $c1r; 146 $gdiff = ($c1g >= $c2g) ? $c1g - $c2g : $c2g - $c1g; 147 $bdiff = ($c1b >= $c2b) ? $c1b - $c2b : $c2b - $c1b; 148 149 if( $rdiff >= $min_diff or $gdiff >= $min_diff or $bdiff >= $min_diff ) 151 $c1r = hexDec( colorRed( $first ) ); 152 $c1g = hexDec( colorGreen( $first ) ); 153 $c1b = hexDec( colorBlue( $first ) ); 154 155 $c2r = hexDec( colorRed( $second ) ); 156 $c2g = hexDec( colorGreen( $second ) ); 157 $c2b = hexDec( colorBlue( $second ) ); 158 159 $rdiff = ($c1r >= $c2r) ? $c1r - $c2r : $c2r - $c1r; 160 $gdiff = ($c1g >= $c2g) ? $c1g - $c2g : $c2g - $c1g; 161 $bdiff = ($c1b >= $c2b) ? $c1b - $c2b : $c2b - $c1b; 162 163 if( $rdiff >= $min_diff or $gdiff >= $min_diff or $bdiff >= $min_diff ) 164 { 150 165 return TRUE; 151 else 166 167 } 168 else 169 { 152 170 return FALSE; 171 } 153 172 } 154 173 155 function randomColor( $known_colors ) { 156 157 $start = "004E00"; 174 function randomColor( $known_colors ) 175 { 176 // White (000000) would be invisible 177 $start = "004E00"; 158 178 159 $start_red 160 $start_green 161 $start_blue 179 $start_red = colorRed( $start ); 180 $start_green = colorGreen( $start ); 181 $start_blue = colorBlue( $start ); 162 182 163 $end 164 165 $end_red 166 $end_green 167 $end_blue 168 169 $change_color = TRUE;170 171 while( $change_color ) {172 173 $change_color 174 175 $new_red = rand( hexDec( $start_red ), hexDec( $end_red ) );176 $new_green = rand( hexDec( $start_green ), hexDec( $end_green ) );177 $new_blue = rand( hexDec( $start_blue ), hexDec( $end_blue ) );178 179 $new = decHex( $new_red ) . decHex( $new_green ) . decHex( $new_blue );183 $end = "FFFFFF"; 184 185 $end_red = colorRed( $end ); 186 $end_green = colorGreen( $end ); 187 $end_blue = colorBlue( $end ); 188 189 $change_color = TRUE; 190 191 while( $change_color ) 192 { 193 $change_color = FALSE; 194 195 $new_red = rand( hexDec( $start_red ), hexDec( $end_red ) ); 196 $new_green = rand( hexDec( $start_green ), hexDec( $end_green ) ); 197 $new_blue = rand( hexDec( $start_blue ), hexDec( $end_blue ) ); 198 199 $new = decHex( $new_red ) . decHex( $new_green ) . decHex( $new_blue ); 180 200 181 201 foreach( $known_colors as $old ) 182 202 { 183 203 if( !colorDiffer( $new, $old ) ) 184 204 { 185 205 $change_color = TRUE; 206 } 207 } 186 208 } 187 209 … … 190 212 } 191 213 192 function drawJobPie() { 193 } 194 195 function drawUserPie() { 196 197 } 198 199 function drawQueuePie() { 200 201 } 202 203 204 function drawPie() { 205 214 // Code these some day 215 function drawJobPie() { } 216 217 function drawUserPie() { } 218 219 function drawQueuePie() { } 220 221 222 function drawPie() 223 { 206 224 global $jobs, $gnodes, $piefilter, $filter, $metrics; 207 225 … … 209 227 210 228 if( isset($piefilter) ) 229 { 211 230 $pie_args = "title=" . rawurlencode("Cluster ".$piefilter." usage"); 212 else 231 } 232 else 233 { 213 234 $pie_args = "title=" . rawurlencode("Cluster queue usage"); 214 235 } 236 215 237 $pie_args .= "&size=250x150"; 216 238 … … 226 248 $job_weight = array(); 227 249 228 foreach( $nodes as $node ) {229 250 foreach( $nodes as $node ) 251 { 230 252 $myjobs = $node->getJobs(); 231 253 $myhost = $node->getHostname(); … … 233 255 $job_cpu = 0; 234 256 235 foreach( $myjobs as $myjob ) {236 257 foreach( $myjobs as $myjob ) 258 { 237 259 $job_cpu += (int) $jobs[$myjob][ppn] ? $jobs[$myjob][ppn] : 1; 238 260 } … … 253 275 254 276 if( isset( $piefilter ) ) 277 { 255 278 $filterpie = array(); 256 257 foreach( $nodes as $node ) { 258 279 } 280 281 foreach( $nodes as $node ) 282 { 259 283 $node_jobs = $node->getJobs(); 260 284 $nr_node_jobs = count( $node_jobs ); … … 262 286 $node_cpus = $metrics[$myhost]["cpu_num"][VAL]; 263 287 264 foreach( $node_jobs as $myjob ) {265 288 foreach( $node_jobs as $myjob ) 289 { 266 290 $job_cpu = (int) $jobs[$myjob][ppn] ? $jobs[$myjob][ppn] : 1; 267 291 … … 272 296 273 297 274 if( isset($piefilter) ) { 298 if( isset( $piefilter ) ) { 299 275 300 $countjob = 1; 276 if( $piefilter == 'id' ) { 301 302 if( $piefilter == 'id' ) 303 { 277 304 if( $myjob != $filter[$piefilter] ) 305 { 278 306 $countjob = 0; 279 } else if( $piefilter == 'user' ) { 307 } 308 } 309 else if( $piefilter == 'user' ) 310 { 280 311 if( $jobs[$myjob][owner] != $filter[$piefilter] ) 312 { 281 313 $countjob = 0; 282 } else { 314 } 315 } 316 else 317 { 283 318 if( $jobs[$myjob][$piefilter] != $filter[$piefilter] ) 319 { 284 320 $countjob = 0; 285 } 286 287 if( $countjob ) { 321 } 322 } 323 324 if( $countjob ) 325 { 288 326 289 327 if( !isset( $filterpie[$filter[$piefilter]] ) ) 328 { 290 329 $filterpie[$filter[$piefilter]] = $job_weight[$myjob]; 330 } 291 331 else 332 { 333 292 334 $filterpie[$filter[$piefilter]] = $filterpie[$filter[$piefilter]] + $job_weight[$myjob]; 293 } else { 335 } 336 } 337 else 338 { 294 339 if( !isset( $filterpie["other"] ) ) 340 { 295 341 $filterpie["other"] = $job_weight[$myjob]; 342 } 296 343 else 344 { 297 345 $filterpie["other"] = $filterpie["other"] + $job_weight[$myjob]; 346 } 298 347 299 348 } 300 349 301 } else { 350 } 351 else 352 { 302 353 303 354 $qname = $jobs[$myjob][queue]; 304 355 305 356 if( !isset( $queues[$qname] ) ) 357 { 306 358 $queues[$qname] = $job_weight[$myjob]; 359 } 307 360 else 361 { 308 362 $queues[$qname] = $queues[$qname] + $job_weight[$myjob]; 363 } 309 364 } 310 365 } … … 312 367 313 368 if( isset( $piefilter ) ) 369 { 314 370 $graphvals = $filterpie; 371 } 315 372 else 373 { 316 374 $graphvals = $queues; 317 318 foreach( $graphvals as $name => $totalweight) { 319 375 } 376 377 foreach( $graphvals as $name => $totalweight) 378 { 320 379 $percentage = ( $totalweight * 100 ); 321 380 … … 330 389 331 390 332 function sortJobs( $jobs, $sortby, $sortorder ) {333 334 $sorted 335 336 $cmp 391 function sortJobs( $jobs, $sortby, $sortorder ) 392 { 393 $sorted = array(); 394 395 $cmp = create_function( '$a, $b', 337 396 "global \$sortby, \$sortorder;". 338 397 … … 344 403 "return ( \$a > \$b ) ? 1 : -1;" ); 345 404 346 if( isset( $jobs ) && count( $jobs ) > 0 ) {347 348 foreach( $jobs as $jobid => $jobattrs ) {349 350 $state 351 $user = $jobattrs[owner];352 $queue = $jobattrs[queue];353 $name = $jobattrs[name];354 $req_cpu = $jobattrs[requested_time];355 $req_memory = $jobattrs[requested_memory];405 if( isset( $jobs ) && count( $jobs ) > 0 ) 406 { 407 foreach( $jobs as $jobid => $jobattrs ) 408 { 409 $state = $jobattrs[status]; 410 $user = $jobattrs[owner]; 411 $queue = $jobattrs[queue]; 412 $name = $jobattrs[name]; 413 $req_cpu = $jobattrs[requested_time]; 414 $req_memory = $jobattrs[requested_memory]; 356 415 357 416 if( $state == 'R' ) 417 { 358 418 $nodes = count( $jobattrs[nodes] ); 419 } 359 420 else 421 { 360 422 $nodes = $jobattrs[nodes]; 361 362 $ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1; 363 $cpus = $nodes * $ppn; 364 $queued_time = (int) $jobattrs[queued_timestamp]; 365 $start_time = (int) $jobattrs[start_timestamp]; 366 $runningtime = $report_time - $start_time; 367 368 switch( $sortby ) { 423 } 424 425 $ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1; 426 $cpus = $nodes * $ppn; 427 $queued_time = (int) $jobattrs[queued_timestamp]; 428 $start_time = (int) $jobattrs[start_timestamp]; 429 $runningtime = $report_time - $start_time; 430 431 switch( $sortby ) 432 { 369 433 case "id": 370 434 $sorted[$jobid] = $jobid; … … 417 481 default: 418 482 break; 419 420 483 } 421 484 } 422 485 } 423 486 424 //uasort( $sorted, $cmp );425 487 if( $sortorder == "asc" ) 488 { 426 489 arsort( $sorted ); 490 } 427 491 else if( $sortorder == "desc" ) 492 { 428 493 asort( $sorted ); 494 } 429 495 430 496 return $sorted; 431 497 } 432 498 433 function makeOverview() {434 499 function makeOverview() 500 { 435 501 global $jobs, $nodes, $heartbeat, $clustername, $tpl; 436 502 global $sortorder, $sortby, $filter, $sh, $hc, $m; … … 438 504 global $start, $end, $reports, $gnodes, $default_showhosts; 439 505 global $COLUMN_QUEUED, $COLUMN_REQUESTED_MEMORY, $COLUMN_NODES, $hostname; 440 $metricname = $m; 506 507 $metricname = $m; 441 508 442 509 $tpl->assign("sortorder", $sortorder ); 443 510 $tpl->assign("sortby", $sortby ); 444 511 445 $sorted_jobs = sortJobs( $jobs, $sortby, $sortorder ); 446 447 $even = 1; 448 449 $used_jobs = 0; 450 $used_cpus = 0; 451 $used_nodes = 0; 452 453 $queued_jobs = 0; 454 $queued_nodes = 0; 455 $queued_cpus = 0; 456 457 $total_nodes = 0; 458 $total_cpus = 0; 459 $total_jobs = 0; 460 461 $all_used_nodes = array(); 462 $total_used_nodes = array(); 463 464 $running_name_nodes = array(); 465 466 $running_nodes = 0; 467 $running_jobs = 0; 468 $running_cpus = 0; 469 470 $avail_nodes = count( $gnodes ); 471 $avail_cpus = cluster_sum("cpu_num", $metrics); 472 473 $view_cpus = 0; 474 $view_jobs = 0; 475 $view_nodes = 0; 476 477 $all_nodes = 0; 478 $all_jobs = 0; 479 $all_cpus = 0; 480 481 $view_name_nodes = array(); 482 483 if( $COLUMN_REQUESTED_MEMORY ) { 512 $sorted_jobs = sortJobs( $jobs, $sortby, $sortorder ); 513 514 $even = 1; 515 516 $used_jobs = 0; 517 $used_cpus = 0; 518 $used_nodes = 0; 519 520 $queued_jobs = 0; 521 $queued_nodes = 0; 522 $queued_cpus = 0; 523 524 $total_nodes = 0; 525 $total_cpus = 0; 526 $total_jobs = 0; 527 528 $all_used_nodes = array(); 529 $total_used_nodes = array(); 530 531 $running_name_nodes = array(); 532 533 $running_nodes = 0; 534 $running_jobs = 0; 535 $running_cpus = 0; 536 537 $avail_nodes = count( $gnodes ); 538 $avail_cpus = cluster_sum("cpu_num", $metrics); 539 540 $view_cpus = 0; 541 $view_jobs = 0; 542 $view_nodes = 0; 543 544 $all_nodes = 0; 545 $all_jobs = 0; 546 $all_cpus = 0; 547 548 $view_name_nodes = array(); 549 550 if( $COLUMN_REQUESTED_MEMORY ) 551 { 484 552 $tpl->newBlock( "column_header_req_mem" ); 485 553 } 486 554 487 if( $COLUMN_NODES ) { 555 if( $COLUMN_NODES ) 556 { 488 557 $tpl->newBlock( "column_header_nodes" ); 489 558 } 490 559 491 if( $COLUMN_QUEUED ) { 560 if( $COLUMN_QUEUED ) 561 { 492 562 $tpl->newBlock( "column_header_queued" ); 493 563 } 494 564 495 $last_displayed_job = null;496 497 foreach( $sorted_jobs as $jobid => $sortdec ) {498 499 $report_time = $jobs[$jobid][reported];565 $last_displayed_job = null; 566 567 foreach( $sorted_jobs as $jobid => $sortdec ) 568 { 569 $report_time = $jobs[$jobid][reported]; 500 570 501 571 if( $jobs[$jobid][status] == 'R' ) 572 { 502 573 $nodes = count( $jobs[$jobid][nodes] ); 574 } 503 575 else if( $jobs[$jobid][status] == 'Q' ) 576 { 504 577 $nodes = $jobs[$jobid][nodes]; 505 506 $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1; 507 $cpus = $nodes * $ppn; 508 509 if( $report_time == $heartbeat ) { 510 511 $display_job = 1; 512 513 if( $jobs[$jobid][status] == 'R' ) { 514 foreach( $jobs[$jobid][nodes] as $tempnode ) { 578 } 579 580 $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1; 581 $cpus = $nodes * $ppn; 582 583 if( $report_time == $heartbeat ) 584 { 585 $display_job = 1; 586 587 if( $jobs[$jobid][status] == 'R' ) 588 { 589 foreach( $jobs[$jobid][nodes] as $tempnode ) 590 { 515 591 $all_used_nodes[] = $tempnode; 516 592 } … … 519 595 $used_cpus += $cpus; 520 596 521 if( $jobs[$jobid][status] == 'R' ) { 522 $running_cpus += $cpus; 597 if( $jobs[$jobid][status] == 'R' ) 598 { 599 $running_cpus += $cpus; 600 523 601 $running_jobs++; 524 602 525 $found_node_job = 0; 526 527 foreach( $jobs[$jobid][nodes] as $tempnode ) { 603 $found_node_job = 0; 604 605 foreach( $jobs[$jobid][nodes] as $tempnode ) 606 { 528 607 $running_name_nodes[] = $tempnode; 529 608 530 if( isset( $hostname ) && $hostname != '' ) { 609 if( isset( $hostname ) && $hostname != '' ) 610 { 531 611 //$filter[host] = $hostname; 532 612 533 $domain_len = 0 - strlen( $jobs[$jobid][domain] ); 534 $hostnode = $tempnode; 535 if( substr( $hostnode, $domain_len ) != $jobs[$jobid][domain] ) { 613 $domain_len = 0 - strlen( $jobs[$jobid][domain] ); 614 $hostnode = $tempnode; 615 616 if( substr( $hostnode, $domain_len ) != $jobs[$jobid][domain] ) 617 { 536 618 $hostnode = $hostnode. '.'. $jobs[$jobid][domain]; 537 619 } 538 620 539 if( $hostname == $hostnode ) { 621 if( $hostname == $hostnode ) 622 { 540 623 $found_node_job = 1; 541 624 $display_job = 1; 542 } else if( !$found_node_job ) { 625 } 626 else if( !$found_node_job ) 627 { 543 628 $display_job = 0; 544 629 } … … 547 632 } 548 633 549 if( $jobs[$jobid][status] == 'Q' ) { 634 if( $jobs[$jobid][status] == 'Q' ) 635 { 550 636 if( isset( $hostname ) && $hostname != '' ) 637 { 551 638 $display_job = 0; 552 553 $queued_cpus += $cpus; 554 $queued_nodes += $nodes; 639 } 640 641 $queued_cpus += $cpus; 642 $queued_nodes += $nodes; 643 555 644 $queued_jobs++; 556 645 } 557 646 558 foreach( $filter as $filtername=>$filtervalue ) {559 647 foreach( $filter as $filtername=>$filtervalue ) 648 { 560 649 if( $filtername == 'id' && $jobid != $filtervalue ) 650 { 561 651 $display_job = 0; 652 } 562 653 else if( $filtername == 'state' && $jobs[$jobid][status] != $filtervalue ) 654 { 563 655 $display_job = 0; 656 } 564 657 else if( $filtername == 'queue' && $jobs[$jobid][queue] != $filtervalue ) 658 { 565 659 $display_job = 0; 660 } 566 661 else if( $filtername == 'user' && $jobs[$jobid][owner] != $filtervalue ) 662 { 567 663 $display_job = 0; 568 } 569 570 if( $display_job ) { 571 572 $tpl->newBlock("node"); 664 } 665 } 666 667 if( $display_job ) 668 { 669 $tpl->newBlock( "node" ); 573 670 $tpl->assign( "clustername", $clustername ); 574 $tpl->assign("id", $jobid ); 575 576 $last_displayed_job = $jobid; 577 578 $tpl->assign("state", $jobs[$jobid][status] ); 579 580 $fullstate = ''; 581 if( $jobs[$jobid][status] == 'R' ) { 582 $fullstate = "Running"; 583 } else if( $jobs[$jobid][status] == 'Q' ) { 584 $fullstate = "Queued"; 585 } 586 587 $tpl->assign("fullstate", $fullstate ); 671 $tpl->assign( "id", $jobid ); 672 673 $last_displayed_job = $jobid; 674 675 $tpl->assign( "state", $jobs[$jobid][status] ); 676 677 $fullstate = ''; 678 679 if( $jobs[$jobid][status] == 'R' ) 680 { 681 $fullstate = "Running"; 682 } 683 else if( $jobs[$jobid][status] == 'Q' ) 684 { 685 $fullstate = "Queued"; 686 } 687 688 $tpl->assign( "fullstate", $fullstate ); 588 689 589 $tpl->assign( "user", $jobs[$jobid][owner] );590 $tpl->assign( "queue", $jobs[$jobid][queue] );591 592 $fulljobname = $jobs[$jobid][name];593 $shortjobname = '';594 595 $tpl->assign( "fulljobname", $fulljobname );690 $tpl->assign( "user", $jobs[$jobid][owner] ); 691 $tpl->assign( "queue", $jobs[$jobid][queue] ); 692 693 $fulljobname = $jobs[$jobid][name]; 694 $shortjobname = ''; 695 696 $tpl->assign( "fulljobname", $fulljobname ); 596 697 597 698 $fulljobname_fields = explode( ' ', $fulljobname ); 598 699 599 $capjobname = 0;700 $capjobname = 0; 600 701 601 702 if( strlen( $fulljobname_fields[0] ) > 10 ) 703 { 602 704 $capjobname = 1; 603 604 if( $capjobname ) { 605 $tpl->newBlock("jobname_hint_start"); 606 $tpl->gotoBlock("node"); 607 608 $shortjobname = substr( $fulljobname, 0, 10 ) . '..'; 609 } else { 610 $shortjobname = $fulljobname; 705 } 706 707 if( $capjobname ) 708 { 709 $tpl->newBlock( "jobname_hint_start" ); 710 $tpl->gotoBlock( "node" ); 711 712 $shortjobname = substr( $fulljobname, 0, 10 ) . '..'; 713 } 714 else 715 { 716 $shortjobname = $fulljobname; 611 717 } 612 718 613 $tpl->assign("name", $shortjobname ); 614 615 if( $capjobname ) { 616 $tpl->newBlock("jobname_hint_end"); 617 $tpl->gotoBlock("node"); 618 } 619 620 $domain = $jobs[$jobid][domain]; 621 $tpl->assign("req_cpu", makeTime( timeToEpoch( $jobs[$jobid][requested_time] ) ) ); 622 623 if( $COLUMN_REQUESTED_MEMORY ) { 719 $tpl->assign( "name", $shortjobname ); 720 721 if( $capjobname ) 722 { 723 $tpl->newBlock( "jobname_hint_end" ); 724 $tpl->gotoBlock( "node" ); 725 } 726 727 $domain = $jobs[$jobid][domain]; 728 729 $tpl->assign( "req_cpu", makeTime( timeToEpoch( $jobs[$jobid][requested_time] ) ) ); 730 731 if( $COLUMN_REQUESTED_MEMORY ) 732 { 624 733 $tpl->newBlock( "column_req_mem" ); 625 734 $tpl->assign( "req_memory", $jobs[$jobid][requested_memory] ); … … 628 737 629 738 630 if( $COLUMN_QUEUED ) { 739 if( $COLUMN_QUEUED ) 740 { 631 741 $tpl->newBlock( "column_queued" ); 632 742 $tpl->assign( "queued", makeDate( $jobs[$jobid][queued_timestamp] ) ); 633 743 $tpl->gotoBlock( "node" ); 634 744 } 635 if( $COLUMN_NODES ) { 745 if( $COLUMN_NODES ) 746 { 636 747 $tpl->newBlock( "column_nodes" ); 637 748 $tpl->gotoBlock( "node" ); 638 749 } 639 750 640 $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1; 641 $cpus = $nodes * $ppn; 642 $tpl->assign("nodes", $nodes ); 643 $tpl->assign("cpus", $cpus ); 644 $start_time = (int) $jobs[$jobid][start_timestamp]; 645 $job_start = $start_time; 646 647 $view_cpus += $cpus; 751 $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1; 752 $cpus = $nodes * $ppn; 753 754 $tpl->assign( "nodes", $nodes ); 755 $tpl->assign( "cpus", $cpus ); 756 757 $start_time = (int) $jobs[$jobid][start_timestamp]; 758 $job_start = $start_time; 759 760 $view_cpus += $cpus; 761 648 762 $view_jobs++; 649 763 650 if( $jobs[$jobid][status] == 'R' ) { 764 if( $jobs[$jobid][status] == 'R' ) 765 { 651 766 foreach( $jobs[$jobid][nodes] as $tempnode ) 652 $view_name_nodes[] = $tempnode; 653 654 if( $COLUMN_NODES ) { 767 { 768 $view_name_nodes[] = $tempnode; 769 } 770 771 if( $COLUMN_NODES ) 772 { 655 773 $tpl->gotoBlock( "column_nodes" ); 656 $mynodehosts = array(); 657 foreach( $jobs[$jobid][nodes] as $mynode ) { 658 $myhost_href = "./?c=".$clustername."&h=".$mynode.".".$jobs[$jobid][domain]; 659 $mynodehosts[] = "<A HREF=\"".$myhost_href."\">".$mynode."</A>"; 774 775 $mynodehosts = array(); 776 777 foreach( $jobs[$jobid][nodes] as $mynode ) 778 { 779 $myhost_href = "./?c=".$clustername."&h=".$mynode.".".$jobs[$jobid][domain]; 780 $mynodehosts[] = "<A HREF=\"".$myhost_href."\">".$mynode."</A>"; 660 781 } 661 $nodes_hostnames = implode( " ", $mynodehosts ); 782 783 $nodes_hostnames = implode( " ", $mynodehosts ); 784 662 785 $tpl->assign( "nodes_hostnames", $nodes_hostnames ); 663 786 $tpl->gotoBlock( "node" ); 664 787 } 665 } else if( $jobs[$jobid][status] == 'Q' ) { 666 $view_nodes += (int) $jobs[$jobid][nodes]; 667 } 668 669 if( $even ) { 670 671 $tpl->assign("nodeclass", "even"); 672 $even = 0; 788 } 789 else if( $jobs[$jobid][status] == 'Q' ) 790 { 791 $view_nodes += (int) $jobs[$jobid][nodes]; 792 } 793 794 if( $even ) 795 { 796 $tpl->assign( "nodeclass", "even" ); 797 798 $even = 0; 799 } 800 else 801 { 802 $tpl->assign( "nodeclass", "odd" ); 803 804 $even = 1; 805 } 806 807 if( $start_time ) 808 { 809 $runningtime = makeTime( $report_time - $start_time ); 810 $job_runningtime = $report_time - $start_time; 811 812 $tpl->assign( "started", makeDate( $start_time ) ); 813 $tpl->assign( "runningtime", $runningtime ); 814 } 815 } 816 } 817 } 818 819 $all_used_nodes = array_unique( $all_used_nodes ); 820 $view_name_nodes = array_unique( $view_name_nodes ); 821 $running_name_nodes = array_unique( $running_name_nodes ); 822 823 $used_nodes = count( $all_used_nodes ); 824 $view_nodes += count( $view_name_nodes ); 825 $running_nodes += count( $running_name_nodes ); 826 827 $total_nodes = $queued_nodes + $running_nodes; 828 $total_cpus = $queued_cpus + $running_cpus; 829 $total_jobs = $queued_jobs + $running_jobs; 830 831 $free_nodes = $avail_nodes - $running_nodes; 832 $free_cpus = $avail_cpus - $running_cpus; 833 834 $tpl->assignGlobal( "avail_nodes", $avail_nodes ); 835 $tpl->assignGlobal( "avail_cpus", $avail_cpus ); 836 837 $tpl->assignGlobal( "queued_nodes", $queued_nodes ); 838 $tpl->assignGlobal( "queued_jobs", $queued_jobs ); 839 $tpl->assignGlobal( "queued_cpus", $queued_cpus ); 840 841 $tpl->assignGlobal( "total_nodes", $total_nodes ); 842 $tpl->assignGlobal( "total_jobs", $total_jobs ); 843 $tpl->assignGlobal( "total_cpus", $total_cpus ); 844 845 $tpl->assignGlobal( "running_nodes", $running_nodes ); 846 $tpl->assignGlobal( "running_jobs", $running_jobs ); 847 $tpl->assignGlobal( "running_cpus", $running_cpus ); 848 849 $tpl->assignGlobal( "used_nodes", $used_nodes ); 850 $tpl->assignGlobal( "used_jobs", $used_jobs ); 851 $tpl->assignGlobal( "used_cpus", $used_cpus ); 852 853 $tpl->assignGlobal( "free_nodes", $free_nodes ); 854 $tpl->assignGlobal( "free_cpus", $free_cpus ); 855 856 $tpl->assignGlobal( "view_nodes", $view_nodes ); 857 $tpl->assignGlobal( "view_jobs", $view_jobs ); 858 $tpl->assignGlobal( "view_cpus", $view_cpus ); 859 860 $tpl->assignGlobal( "report_time", makeDate( $heartbeat) ); 861 862 if( intval($view_jobs) == 1 and $start_time ) 863 { 864 if( $last_displayed_job != null ) 865 { 866 $filter[id] = $last_displayed_job; 867 } 868 } 869 870 makeHeader( 'overview' ); 871 872 setupFilterSettings(); 873 874 if( intval($view_jobs) == 1 and $start_time ) 875 { 876 $tpl->newBlock( "showhosts" ); 877 878 # Present a width list 879 $cols_menu = "<SELECT NAME=\"hc\" OnChange=\"toga_form.submit();\">\n"; 880 881 $hostcols = ($hc) ? $hc : 4; 882 883 foreach( range( 1, 25 ) as $cols ) 884 { 885 $cols_menu .= "<OPTION VALUE=$cols "; 886 887 if ($cols == $hostcols) 888 { 889 $cols_menu .= "SELECTED"; 890 } 891 $cols_menu .= ">$cols\n"; 892 } 893 $cols_menu .= "</SELECT>\n"; 894 895 $tpl->assign( "metric","$metricname $units" ); 896 $tpl->assign( "id", $filter[id] ); 897 898 # Host columns menu defined in header.php 899 $tpl->assign( "cols_menu", $cols_menu ); 900 901 $showhosts = isset($sh) ? $sh : $default_showhosts; 902 903 $tpl->assign( "checked$showhosts", "checked" ); 904 905 if( $showhosts ) 906 { 907 if( !isset( $start ) ) 908 { 909 $start ="jobstart"; 910 } 911 if( !isset( $stop ) ) 912 { 913 $stop ="now"; 914 } 915 916 $sorted_hosts = array(); 917 $hosts_up = $jobs[$filter[id]][nodes]; 918 919 $r = intval($job_runningtime * 1.25); 920 921 $jobrange = ($job_runningtime < 3600) ? -3600 : -$r ; 922 $jobstart = $report_time - $job_runningtime; 923 924 if ( $reports[$metricname] ) 925 { 926 $metricval = "g"; 927 } 928 else 929 { 930 $metricval = "m"; 931 } 932 933 foreach ( $hosts_up as $host ) 934 { 935 $domain_len = 0 - strlen( $domain ); 936 937 if( substr( $host, $domain_len ) != $domain ) 938 { 939 $host = $host . '.' . $domain; 940 } 941 942 $cpus = $metrics[$host]["cpu_num"]["VAL"]; 943 944 if ( !$cpus ) 945 { 946 $cpus = 1; 947 } 948 949 $load_one = $metrics[$host]["load_one"][VAL]; 950 $load = ((float) $load_one) / $cpus; 951 $host_load[$host] = $load; 952 953 $percent_hosts[load_color($load)] ++; 954 955 if ($metricname=="load_one") 956 { 957 $sorted_hosts[$host] = $load; 958 } 959 else 960 { 961 $sorted_hosts[$host] = $metrics[$host][$metricname][VAL]; 962 } 963 } 964 switch ( $sort ) 965 { 966 case "descending": 967 arsort( $sorted_hosts ); 968 break; 969 970 case "by hostname": 971 ksort( $sorted_hosts ); 972 break; 973 974 case "ascending": 975 asort( $sorted_hosts ); 976 break; 977 978 default: 979 break; 980 } 981 982 // First pass to find the max value in all graphs for this 983 // metric. The $start,$end variables comes from get_context.php, 984 // included in index.php. 985 // 986 list($min, $max) = find_limits($sorted_hosts, $metricname); 987 988 // Second pass to output the graphs or metrics. 989 $i = 1; 990 991 foreach ( $sorted_hosts as $host=>$value ) 992 { 993 $tpl->newBlock( "sorted_list" ); 994 995 $host_url = rawurlencode( $host ); 996 $cluster_url = rawurlencode( $clustername ); 997 998 $textval = ""; 999 1000 $val = $metrics[$host][$metricname]; 1001 $class = "metric"; 1002 $host_link = "\"../../?c=$cluster_url&h=$host_url&r=job&jr=$jobrange&js=$jobstart\""; 1003 1004 if ( $val["TYPE"] == "timestamp" || $always_timestamp[$metricname] ) 1005 { 1006 $textval = date( "r", $val["VAL"] ); 1007 } 1008 elseif ( $val["TYPE"] == "string" || $val["SLOPE"] == "zero" || $always_constant[$metricname] || ($max_graphs > 0 and $i > $max_graphs )) 1009 { 1010 $textval = $val["VAL"] . " " . $val["UNITS"]; 1011 } 1012 else 1013 { 1014 $load_color = load_color($host_load[$host]); 1015 $graphargs = ($reports[$metricname]) ? "g=$metricname&" : "m=$metricname&"; 1016 $graphargs .= "z=small&c=$cluster_url&h=$host_url&l=$load_color" . "&v=$val[VAL]&r=job&jr=$jobrange&js=$jobstart"; 1017 if( $max > 0 ) 1018 { 1019 $graphargs .= "&x=$max&n=$min"; 1020 } 1021 } 1022 if ($textval) 1023 { 1024 $cell = "<td class=$class>". "<b><a href=$host_link>$host</a></b><br>". "<i>$metricname:</i> <b>$textval</b></td>"; 673 1025 } else { 674 675 $tpl->assign("nodeclass", "odd"); 676 $even = 1; 677 } 678 679 if( $start_time ) { 680 681 $runningtime = makeTime( $report_time - $start_time ); 682 $job_runningtime = $report_time - $start_time; 683 $tpl->assign("started", makeDate( $start_time ) ); 684 $tpl->assign("runningtime", $runningtime ); 1026 $cell = "<td><a href=$host_link>" . "<img src=\"../../graph.php?$graphargs\" " . "alt=\"$host\" border=0></a></td>"; 1027 } 1028 1029 $tpl->assign( "metric_image", $cell ); 1030 1031 if(! ($i++ % $hostcols) ) 1032 { 1033 $tpl->assign( "br", "</tr><tr>" ); 685 1034 } 686 1035 } 687 1036 } 688 }689 $all_used_nodes = array_unique( $all_used_nodes );690 $view_name_nodes = array_unique( $view_name_nodes );691 $running_name_nodes = array_unique( $running_name_nodes );692 693 $used_nodes = count( $all_used_nodes );694 $view_nodes += count( $view_name_nodes );695 $running_nodes += count( $running_name_nodes );696 697 $total_nodes = $queued_nodes + $running_nodes;698 $total_cpus = $queued_cpus + $running_cpus;699 $total_jobs = $queued_jobs + $running_jobs;700 701 $tpl->assignGlobal("avail_nodes", $avail_nodes );702 $tpl->assignGlobal("avail_cpus", $avail_cpus );703 704 $tpl->assignGlobal("queued_nodes", $queued_nodes );705 $tpl->assignGlobal("queued_jobs", $queued_jobs );706 $tpl->assignGlobal("queued_cpus", $queued_cpus );707 708 $tpl->assignGlobal("total_nodes", $total_nodes );709 $tpl->assignGlobal("total_jobs", $total_jobs );710 $tpl->assignGlobal("total_cpus", $total_cpus );711 712 $tpl->assignGlobal("running_nodes", $running_nodes );713 $tpl->assignGlobal("running_jobs", $running_jobs );714 $tpl->assignGlobal("running_cpus", $running_cpus );715 716 $tpl->assignGlobal("used_nodes", $used_nodes );717 $tpl->assignGlobal("used_jobs", $used_jobs );718 $tpl->assignGlobal("used_cpus", $used_cpus );719 720 $free_nodes = $avail_nodes - $running_nodes;721 $free_cpus = $avail_cpus - $running_cpus;722 723 $tpl->assignGlobal("free_nodes", $free_nodes );724 $tpl->assignGlobal("free_cpus", $free_cpus );725 726 $tpl->assignGlobal("view_nodes", $view_nodes );727 $tpl->assignGlobal("view_jobs", $view_jobs );728 $tpl->assignGlobal("view_cpus", $view_cpus );729 730 $tpl->assignGlobal("report_time", makeDate( $heartbeat));731 732 if( intval($view_jobs) == 1 and $start_time )733 if( $last_displayed_job != null )734 $filter[id] = $last_displayed_job;735 736 makeHeader( 'overview' );737 setupFilterSettings();738 739 if( intval($view_jobs) == 1 and $start_time ) {740 741 $tpl->newBlock( "showhosts" );742 743 # Present a width list744 $cols_menu = "<SELECT NAME=\"hc\" OnChange=\"toga_form.submit();\">\n";745 746 747 $hostcols = ($hc) ? $hc : 4;748 749 foreach(range(1,25) as $cols) {750 $cols_menu .= "<OPTION VALUE=$cols ";751 if ($cols == $hostcols)752 $cols_menu .= "SELECTED";753 $cols_menu .= ">$cols\n";754 }755 $cols_menu .= "</SELECT>\n";756 757 //$tpl->assign("cluster", $clustername);758 $tpl->assign("metric","$metricname $units");759 $tpl->assign("id", $filter[id]);760 # Host columns menu defined in header.php761 $tpl->assign("cols_menu", $cols_menu);762 763 $showhosts = isset($sh) ? $sh : $default_showhosts;764 //if( !$showhosts) $showhosts = $default_showhosts;765 $tpl->assign("checked$showhosts", "checked");766 767 if( $showhosts ) {768 //-----769 770 if( !isset($start) ) $start="jobstart";771 if( !isset($stop) ) $stop="now";772 //$tpl->assign("start", $start);773 //$tpl->assign("stop", $stop);774 775 $sorted_hosts = array();776 $hosts_up = $jobs[$filter[id]][nodes];777 778 $r = intval($job_runningtime * 1.25);779 780 $jobrange = ($job_runningtime < 3600) ? -3600 : -$r ;781 $jobstart = $report_time - $job_runningtime;782 783 if ($reports[$metricname])784 $metricval = "g";785 else786 $metricval = "m";787 788 foreach ($hosts_up as $host ) {789 790 $domain_len = 0 - strlen( $domain );791 if( substr( $host, $domain_len ) != $domain ) {792 $host = $host. '.'.$domain;793 }794 $cpus = $metrics[$host]["cpu_num"][VAL];795 if (!$cpus) $cpus=1;796 $load_one = $metrics[$host]["load_one"][VAL];797 $load = ((float) $load_one)/$cpus;798 $host_load[$host] = $load;799 $percent_hosts[load_color($load)] += 1;800 if ($metricname=="load_one")801 $sorted_hosts[$host] = $load;802 else803 $sorted_hosts[$host] = $metrics[$host][$metricname][VAL];804 }805 switch ($sort) {806 case "descending":807 arsort($sorted_hosts);808 break;809 case "by hostname":810 ksort($sorted_hosts);811 break;812 default:813 case "ascending":814 asort($sorted_hosts);815 break;816 }817 818 //$sorted_hosts = array_merge($down_hosts, $sorted_hosts);819 820 # First pass to find the max value in all graphs for this821 # metric. The $start,$end variables comes from get_context.php,822 # included in index.php.823 list($min, $max) = find_limits($sorted_hosts, $metricname);824 825 # Second pass to output the graphs or metrics.826 $i = 1;827 foreach ( $sorted_hosts as $host=>$value ) {828 $tpl->newBlock ("sorted_list");829 //$host = $host. '.'.$domain;830 $host_url = rawurlencode($host);831 $cluster_url = rawurlencode($clustername);832 833 $textval = "";834 //printf("host = %s, value = %s", $host, $value);835 //echo "$host: $value, ";836 $val = $metrics[$host][$metricname];837 $class = "metric";838 $host_link="\"../../?c=$cluster_url&h=$host_url&r=job&jr=$jobrange&js=$jobstart\"";839 840 if ($val[TYPE]=="timestamp" or $always_timestamp[$metricname]) {841 $textval = date("r", $val[VAL]);842 } elseif ($val[TYPE]=="string" or $val[SLOPE]=="zero" or $always_constant[$metricname] or ($max_graphs > 0 and $i > $max_graphs )) {843 $textval = "$val[VAL] $val[UNITS]";844 } else {845 $load_color = load_color($host_load[$host]);846 $graphargs = ($reports[$metricname]) ? "g=$metricname&" : "m=$metricname&";847 $graphargs .= "z=small&c=$cluster_url&h=$host_url&l=$load_color" ."&v=$val[VAL]&r=job&jr=$jobrange&js=$jobstart";848 if( $max > 0 ) {849 850 $graphargs .= "&x=$max&n=$min";851 }852 }853 if ($textval) {854 $cell="<td class=$class>". "<b><a href=$host_link>$host</a></b><br>". "<i>$metricname:</i> <b>$textval</b></td>";855 } else {856 $cell="<td><a href=$host_link>". "<img src=\"../../graph.php?$graphargs\" ". "alt=\"$host\" border=0></a></td>";857 }858 859 $tpl->assign("metric_image", $cell);860 if (! ($i++ % $hostcols) )861 $tpl->assign ("br", "</tr><tr>");862 }863 }864 //---865 1037 } 866 1038 }
Note: See TracChangeset
for help on using the changeset viewer.