Changeset 519
- Timestamp:
- 03/09/08 13:42:01 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/web/addons/job_monarch/libtoga.php
r518 r519 25 25 26 26 27 class HTTPVariables {28 27 class HTTPVariables 28 { 29 29 var $clustername, $metricname; 30 30 var $restvars, $httpvars; 31 31 32 function HTTPVariables( $httpvars, $getvars ) { 33 34 $this->restvars = array(); 35 36 $this->clustername = $httpvars["c"] ? $httpvars["c"] : $getvars["c"]; 37 $this->metricname = $httpvars["m"] ? $httpvars["m"] : $getvars["m"]; 38 39 foreach( $httpvars as $httpvar => $httpval ) { 40 41 if( $httpval ) { 32 function HTTPVariables( $httpvars, $getvars ) 33 { 34 $this->restvars = array(); 35 36 $this->clustername = $httpvars["c"] ? $httpvars["c"] : $getvars["c"]; 37 $this->metricname = $httpvars["m"] ? $httpvars["m"] : $getvars["m"]; 38 39 foreach( $httpvars as $httpvar => $httpval ) 40 { 41 if( $httpval ) 42 { 42 43 $this->restvars[$httpvar] = $httpval; 43 44 } 44 45 } 45 46 46 foreach( $getvars as $getvar => $getval ) { 47 48 if( $getval ) { 47 foreach( $getvars as $getvar => $getval ) 48 { 49 if( $getval ) 50 { 49 51 $this->restvars[$getvar] = $getval; 50 52 } … … 52 54 } 53 55 54 function getClusterName() { 56 function getClusterName() 57 { 55 58 return $this->clustername; 56 59 } 57 60 58 function getMetricName() { 61 function getMetricName() 62 { 59 63 return $this->metricname; 60 64 } 61 65 62 function getHttpVar( $var ) { 66 function getHttpVar( $var ) 67 { 63 68 if( isset( $this->restvars[$var] ) ) 69 { 64 70 return $this->restvars[$var]; 71 } 65 72 else 73 { 66 74 return null; 75 } 67 76 } 68 77 } … … 70 79 $CLUSTER_CONFS = array(); 71 80 72 // Toga's conf81 // Monarch's conf 73 82 // 74 83 include_once "./conf.php"; … … 79 88 global $JOB_ARCHIVE_DIR; 80 89 global $JOB_ARCHIVE_DBASE; 81 //global $SORTBY_HOSTNAME;82 //global $SORT_ORDER;83 90 global $skan_str; 84 91 global $x_first, $y_first; 85 //global $SORT_XLABEL, $SORT_YLABEL;86 92 global $CLUSTER_CONFS; 87 93 … … 95 101 include_once "./ganglia.php"; 96 102 include_once "./get_context.php"; 97 //unset( $start ); 103 98 104 $context = 'cluster'; 99 105 include_once "./get_ganglia.php"; … … 110 116 global $context, $clustername, $reports; 111 117 112 //$clustername = $httpvars->getClusterName();113 114 118 global $default_metric; 115 119 … … 121 125 global $DATETIME_FORMAT; 122 126 123 function makeDate( $time ) { 127 function makeDate( $time ) 128 { 124 129 global $DATETIME_FORMAT; 125 130 return strftime( $DATETIME_FORMAT, $time ); … … 127 132 128 133 129 class TarchDbase {130 134 class TarchDbase 135 { 131 136 var $ip, $dbase, $conn; 132 137 133 function TarchDbase( $ip = null, $dbase = null ) {134 138 function TarchDbase( $ip = null, $dbase = null ) 139 { 135 140 global $CLUSTER_CONFS, $clustername; 136 141 global $JOB_ARCHIVE_DBASE; … … 153 158 } 154 159 155 function connect() {156 160 function connect() 161 { 157 162 if( $this->ip == null ) 158 163 $this->conn = pg_connect( "dbname=".$this->dbase ); … … 161 166 } 162 167 163 function searchDbase( $id = null, $queue = null, $user = null, $name = null, $start_from_time = null, $start_to_time = null, $end_from_time = null, $end_to_time = null ) {164 168 function searchDbase( $id = null, $queue = null, $user = null, $name = null, $start_from_time = null, $start_to_time = null, $end_from_time = null, $end_to_time = null ) 169 { 165 170 global $SEARCH_RESULT_LIMIT; 166 171 167 if( $id ) { 172 if( $id ) 173 { 168 174 $select_query = "SELECT job_id FROM jobs WHERE job_id = '$id' AND job_status = 'F'"; 169 175 $this->resultcount = 1; 170 } else { 176 } 177 else 178 { 171 179 $query_args = array(); 172 180 173 181 if( $queue ) 182 { 174 183 $query_args[] = "job_queue ='$queue'"; 184 } 175 185 if( $user ) 186 { 176 187 $query_args[] = "job_owner ='$user'"; 188 } 177 189 if( $name ) 190 { 178 191 $query_args[] = "job_name = '$name'"; 192 } 179 193 if( $start_from_time ) 194 { 180 195 $query_args[] = "job_start_timestamp >= $start_from_time"; 196 } 181 197 if( $start_to_time ) 198 { 182 199 $query_args[] = "job_start_timestamp <= $start_to_time"; 200 } 183 201 if( $end_from_time ) 202 { 184 203 $query_args[] = "job_stop_timestamp >= $end_from_time"; 204 } 185 205 if( $end_to_time ) 206 { 186 207 $query_args[] = "job_stop_timestamp <= $end_to_time"; 208 } 187 209 188 210 $query = "FROM jobs WHERE job_status = 'F' AND "; 189 211 $extra_query_args = ''; 190 212 191 foreach( $query_args as $myquery ) {192 213 foreach( $query_args as $myquery ) 214 { 193 215 if( $extra_query_args == '' ) 216 { 194 217 $extra_query_args = $myquery; 218 } 195 219 else 220 { 196 221 $extra_query_args .= " AND ".$myquery; 222 } 197 223 } 198 224 $query .= $extra_query_args; … … 214 240 215 241 foreach( $ids as $crow) 242 { 216 243 $ret[] = $crow[job_id]; 244 } 217 245 218 246 return $ret; 219 247 } 220 248 221 function getNodesForJob( $jobid ) {222 249 function getNodesForJob( $jobid ) 250 { 223 251 $result = $this->queryDbase( "SELECT node_id FROM job_nodes WHERE job_id = '$jobid'" ); 224 252 … … 226 254 227 255 foreach( $result as $result_row ) 228 256 { 229 257 $nodes[] = $this->getNodeArray( $result_row[node_id] ); 258 } 230 259 231 260 return $nodes; 232 261 } 233 262 234 function getJobsForNode( $nodeid ) {235 263 function getJobsForNode( $nodeid ) 264 { 236 265 $result = $this->queryDbase( "SELECT job_id FROM job_nodes WHERE node_id = '$nodeid'" ); 237 266 … … 239 268 240 269 foreach( $result as $result_row ) 241 270 { 242 271 $jobs[] = $this->getJobArray( $result_row[job_id] ); 243 272 } 244 273 return $jobs; 245 274 } 246 275 247 function getJobArray( $id ) { 276 function getJobArray( $id ) 277 { 248 278 $result = $this->queryDbase( "SELECT * FROM jobs WHERE job_id = '$id'" ); 249 279 … … 251 281 } 252 282 253 function getNodeArray( $id ) {254 283 function getNodeArray( $id ) 284 { 255 285 $result = $this->queryDbase( "SELECT * FROM nodes WHERE node_id = '$id'" ); 256 286 … … 258 288 } 259 289 260 function makeArray( $result_row ) {261 290 function makeArray( $result_row ) 291 { 262 292 $myar = array(); 263 293 264 foreach( $result_row as $mykey => $myval ) {265 294 foreach( $result_row as $mykey => $myval ) 295 { 266 296 $map_key = explode( '_', $mykey ); 267 297 … … 278 308 } 279 309 280 function queryDbase( $query ) {281 310 function queryDbase( $query ) 311 { 282 312 $result_rows = array(); 283 313 284 314 if( !$this->conn ) 315 { 285 316 $this->connect(); 286 287 //printf( "query = [%s]\n", $query ); 317 } 318 288 319 $result = pg_query( $this->conn, $query ); 289 320 290 321 while ($row = pg_fetch_assoc($result)) 322 { 291 323 $result_rows[] = $row; 324 } 292 325 293 326 return $result_rows; … … 295 328 } 296 329 297 class TarchRrdGraph { 330 class TarchRrdGraph 331 { 298 332 var $rrdbin, $rrdvalues, $clustername, $hostname, $tempdir, $tarchdir, $metrics; 299 333 300 function TarchRrdGraph( $clustername, $hostname ) {301 334 function TarchRrdGraph( $clustername, $hostname ) 335 { 302 336 global $RRDTOOL; 303 337 global $JOB_ARCHIVE_DIR; 304 338 305 $this->rrdbin = $RRDTOOL; 306 $this->rrdvalues = array(); 307 $this->tarchdir = $JOB_ARCHIVE_DIR; 308 $this->clustername = $clustername; 309 $this->hostname = $hostname; 310 } 311 312 function doCmd( $command ) { 313 314 printf( "command = %s\n", $command ); 339 $this->rrdbin = $RRDTOOL; 340 $this->rrdvalues = array(); 341 $this->tarchdir = $JOB_ARCHIVE_DIR; 342 $this->clustername = $clustername; 343 $this->hostname = $hostname; 344 } 345 346 function doCmd( $command ) 347 { 315 348 $pipe = popen( $command . ' 2>&1', 'r' ); 316 349 317 if (!$pipe) { 350 if (!$pipe) 351 { 318 352 print "pipe failed."; 319 353 return ""; … … 321 355 322 356 $output = ''; 357 323 358 while(!feof($pipe)) 359 { 324 360 $output .= fread($pipe, 1024); 361 } 325 362 326 363 pclose($pipe); 327 364 328 365 $output = explode( "\n", $output ); 329 //print_r( $output ); 366 330 367 return $output; 331 368 } 332 369 333 function dirList( $dir ) {334 370 function dirList( $dir ) 371 { 335 372 $dirlist = array(); 336 373 337 if ($handle = opendir( $dir )) { 338 while (false !== ($file = readdir($handle))) { 339 if ($file != "." && $file != "..") { 374 if ($handle = opendir( $dir )) 375 { 376 while (false !== ($file = readdir($handle))) 377 { 378 if ($file != "." && $file != "..") 379 { 340 380 $dirlist[] = $file; 341 381 } … … 347 387 } 348 388 349 function getTimePeriods( $start, $end ) { 350 351 //printf("start = %s end = %s\n", $start, $end ); 389 function getTimePeriods( $start, $end ) 390 { 352 391 $times = array(); 353 392 $dirlist = $this->dirList( $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname ); 354 393 355 //print_r( $dirlist );356 357 394 $first = 0; 358 395 $last = 9999999999999; 359 396 360 foreach( $dirlist as $dir ) {361 397 foreach( $dirlist as $dir ) 398 { 362 399 if( $dir > $first and $dir <= $start ) 400 { 363 401 $first = $dir; 402 } 364 403 if( $dir < $last and $dir >= $end ) 404 { 365 405 $last = $dir; 366 } 367 368 //printf( "first = %s last = %s\n", $first, $last ); 369 370 foreach( $dirlist as $dir ) { 371 372 //printf( "dir %s ", $dir ); 373 374 if( $dir >= $first and $dir <= $last and !array_key_exists( $dir, $times ) ) { 375 406 } 407 } 408 409 foreach( $dirlist as $dir ) 410 { 411 if( $dir >= $first and $dir <= $last and !array_key_exists( $dir, $times ) ) 412 { 376 413 $times[] = $dir; 377 //printf("newtime %s ", $dir ); 378 379 } 380 } 381 382 //print_r( $times ); 414 } 415 } 383 416 384 417 sort( $times ); 385 418 386 //print_r( $times );387 388 419 return $times; 389 420 } 390 421 391 function getRrdDirs( $start, $stop ) { 392 393 //printf( "tarchdir = %s\n", $this->tarchdir ); 422 function getRrdDirs( $start, $stop ) 423 { 394 424 $timess = $this->getTimePeriods( $start, $stop ); 395 //print_r( $timess );396 425 397 426 $rrd_files = array(); 398 427 399 foreach( $timess as $time ) {400 428 foreach( $timess as $time ) 429 { 401 430 $rrd_files[] = $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname. '/'.$time; 402 431 } … … 405 434 } 406 435 407 function getRrdFiles( $metric, $start, $stop ) {408 436 function getRrdFiles( $metric, $start, $stop ) 437 { 409 438 $times = $this->getTimePeriods( $start, $stop ); 410 439 411 440 $rrd_files = array(); 412 441 413 foreach( $times as $time ) {414 442 foreach( $times as $time ) 443 { 415 444 $rrd_files[] = $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname . '/' .$time. '/' . $metric. '.rrd'; 416 445 } … … 418 447 return $rrd_files; 419 448 } 420 421 function graph( $descr ) {422 // monitor2:/data/toga/rrds/LISA Cluster/gb-r15n11.irc.sara.nl# rrdtool graph /var/www/ganglia/test1.png --start 1118683231 --end 1118750431 --width 300 --height 400 DEF:'1'='./1118647515/load_one.rrd':'sum':AVERAGE DEF:'2'='./1118690723/load_one.rrd':'sum':AVERAGE DEF:'3'='./1118733925/load_one.rrd':'sum':AVERAGE AREA:1#555555:"load_one" AREA:2#555555 AREA:3#555555423 // 380x461424 // monitor2:/data/toga/rrds/LISA Cluster/gb-r15n11.irc.sara.nl#425 //$command = $this->rrdbin . " graph - --start $start --end $end ".426 "--width $width --height $height $upper_limit $lower_limit ".427 "--title '$title' $vertical_label $extras $background ". $series;428 429 //$graph = $this->doCmd( $command );430 431 //return $graph;432 return 0;433 }434 449 } 435 450 436 class DataSource {437 451 class DataSource 452 { 438 453 var $data, $ip, $port; 439 454 440 //function DataSource( $ip = '127.0.0.1', $port = 8649 ) { 441 function DataSource() { 442 455 function DataSource() 456 { 443 457 global $DATA_SOURCE; 444 458 … … 453 467 } 454 468 455 function getData() {456 469 function getData() 470 { 457 471 $errstr; 458 472 $errno = 0; … … 461 475 $fp = fsockopen( $this->ip, $this->port, $errno, $errstr, $timeout ); 462 476 463 if( !$fp ) { 477 if( !$fp ) 478 { 464 479 echo 'Unable to connect to '.$this->ip.':'.$this->port; // printf( 'Unable to connect to [%s:%.0f]', $this->ip, $this->port ); 465 480 return; … … 468 483 stream_set_timeout( $fp, 30 ); 469 484 470 while ( !feof( $fp ) ) {471 485 while ( !feof( $fp ) ) 486 { 472 487 $data .= fread( $fp, 16384 ); 473 488 } … … 479 494 } 480 495 481 class DataGatherer {482 496 class DataGatherer 497 { 483 498 var $xmlhandler, $data, $httpvars; 484 499 485 function DataGatherer( $cluster ) { 486 487 //global $DATA_SOURCE; 488 489 //printf("dg cluster = %s\n", $cluster ); 490 //$ds_fields = explode( ':', $DATA_SOURCE ); 491 //$ds_ip = $ds_fields[0]; 492 //$ds_port = $ds_fields[1]; 493 494 //$this->source = new DataSource( $ds_ip, $ds_port ); 495 500 function DataGatherer( $cluster ) 501 { 496 502 $this->cluster = $cluster; 497 503 $this->httpvars = $httpvars; 498 504 } 499 505 500 function parseXML( $data ) { 501 502 //$src = &$this->source; 503 //$this->data = $src->getData(); 504 506 function parseXML( $data ) 507 { 505 508 $this->parser = xml_parser_create(); 506 509 $this->xmlhandler = new TorqueXMLHandler( $this->cluster ); 507 510 508 511 xml_set_element_handler( $this->parser, array( &$this->xmlhandler, 'startElement' ), array( &$this->xmlhandler, 'stopElement' ) ); 509 //if ( !xml_parse( $this->parser, $this->data ) ) 512 510 513 if ( !xml_parse( $this->parser, $data ) ) 514 { 511 515 $error = sprintf( 'XML error: %s at %d', xml_error_string( xml_get_error_code( $this->parser ) ), xml_get_current_line_number( $this->parser ) ); 512 } 513 514 function printInfo() { 516 } 517 } 518 519 function printInfo() 520 { 515 521 $handler = $this->xmlhandler; 516 522 $handler->printInfo(); 517 523 } 518 524 519 function getUsingFQDN() { 525 function getUsingFQDN() 526 { 520 527 $handler = $this->xmlhandler; 521 528 return $handler->getUsingFQDN(); 522 529 } 523 530 524 function getNodes() { 531 function getNodes() 532 { 525 533 $handler = $this->xmlhandler; 526 534 return $handler->getNodes(); 527 535 } 528 536 529 function getNode( $node ) { 537 function getNode( $node ) 538 { 530 539 $handler = $this->xmlhandler; 531 540 return $handler->getNode( $node ); 532 541 } 533 542 534 function getCpus() { 543 function getCpus() 544 { 535 545 $handler = $this->xmlhandler; 536 546 return $handler->getCpus(); 537 547 } 538 548 539 function getJobs() { 549 function getJobs() 550 { 540 551 $handler = $this->xmlhandler; 541 552 return $handler->getJobs(); 542 553 } 543 554 544 function getJob( $job ) { 555 function getJob( $job ) 556 { 545 557 $handler = $this->xmlhandler; 546 558 return $handler->getJob( $job ); 547 559 } 548 560 549 function getHeartbeat() { 561 function getHeartbeat() 562 { 550 563 $handler = $this->xmlhandler; 551 564 return $handler->getHeartbeat(); 552 565 } 553 566 554 function isJobmonRunning() { 567 function isJobmonRunning() 568 { 555 569 $handler = $this->xmlhandler; 556 570 return $handler->isJobmonRunning(); … … 558 572 } 559 573 560 class TorqueXMLHandler {561 574 class TorqueXMLHandler 575 { 562 576 var $clusters, $heartbeat, $nodes, $jobs, $clustername, $proc_cluster; 563 577 564 function TorqueXMLHandler( $clustername ) { 578 function TorqueXMLHandler( $clustername ) 579 { 565 580 $jobs = array(); 566 581 $clusters = array(); … … 573 588 } 574 589 575 function getUsingFQDN() {576 590 function getUsingFQDN() 591 { 577 592 return $this->fqdn; 578 579 580 } 581 582 function getCpus() { 583 593 } 594 595 function getCpus() 596 { 584 597 $cpus = 0; 585 598 586 if( isset( $this->jobs ) && count( $this->jobs ) > 0 ) {587 588 foreach( $this->jobs as $jobid=>$jobattrs ) {589 590 $nodes 591 $ppn 592 $mycpus 593 594 $cpus 595 } 596 } 597 } 598 599 function isJobmonRunning() {600 599 if( isset( $this->jobs ) && count( $this->jobs ) > 0 ) 600 { 601 foreach( $this->jobs as $jobid=>$jobattrs ) 602 { 603 $nodes = count( $jobattrs[nodes] ); 604 $ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1; 605 $mycpus = $nodes * $ppn; 606 607 $cpus = $cpus + $mycpus; 608 } 609 } 610 } 611 612 function isJobmonRunning() 613 { 601 614 if (isset( $this->heartbeat['time'] )) 615 { 602 616 return 1; 617 } 603 618 else 619 { 604 620 return 0; 621 } 605 622 } 606 623 … … 614 631 615 632 //$tdomain = explode( '.', $thostname ); 616 // TODO: domain van hostname afhalen: parameter weghalen 633 // 634 // TODO?: extract domain from hostname or something? 617 635 618 636 if( $tdomain ) … … 624 642 foreach( $nodes as $hostname => $nimage ) 625 643 { 626 627 644 if( substr( $hostname, $domain_len ) != $tdomain ) 628 645 { … … 651 668 } 652 669 653 function startElement( $parser, $name, $attrs ) {654 670 function startElement( $parser, $name, $attrs ) 671 { 655 672 $jobs = $this->jobs; 656 673 $nodes = $this->nodes; 657 674 658 if ( $attrs[TN] ) {659 675 if ( $attrs[TN] ) 676 { 660 677 // Ignore dead metrics. Detect and mask failures. 661 678 if ( $attrs[TN] > $attrs[TMAX] * 4 ) 679 { 662 680 return; 681 } 663 682 } 664 683 665 684 $jobid = null; 666 685 667 //printf( '%s=%s', $attrs[NAME], $attrs[VAL] ); 668 669 //printf( "clustername = %s proc_cluster = %s\n", $this->clustername, $this->proc_cluster ); 670 671 if( $name == 'CLUSTER' ) { 672 686 if( $name == 'CLUSTER' ) 687 { 673 688 $this->proc_cluster = $attrs[NAME]; 674 //printf( "Found cluster %s\n", $attrs[NAME] ); 675 //print_r( $attrs ); 676 677 //if( !isset( $clusters[$clustername] ) ) 678 // $clusters[$clustername] = array(); 679 680 } else if( $name == 'HOST' and $this->proc_cluster == $this->clustername) { 681 689 } 690 else if( $name == 'HOST' and $this->proc_cluster == $this->clustername) 691 { 682 692 $hostname = $attrs[NAME]; 683 693 684 685 694 $location = $attrs[LOCATION]; 686 //printf( "Found node %s\n", $hostname );687 695 688 696 if( !isset( $nodes[$hostname] ) ) 697 { 689 698 $nodes[$hostname] = new NodeImage( $this->proc_cluster, $hostname ); 690 691 } else if( $name == 'METRIC' and strstr( $attrs[NAME], 'MONARCH' ) and $this->proc_cluster == $this->clustername ) { 692 699 } 700 } 701 else if( $name == 'METRIC' and strstr( $attrs[NAME], 'MONARCH' ) and $this->proc_cluster == $this->clustername ) 702 { 693 703 if( strstr( $attrs[NAME], 'MONARCH-HEARTBEAT' ) ) 694 704 { … … 730 740 } 731 741 } 732 733 } else if( strstr( $attrs[NAME], 'MONARCH-OFFLINE' ) ) {734 742 } 743 else if( strstr( $attrs[NAME], 'MONARCH-OFFLINE' ) ) 744 { 735 745 $fields = explode( ' ', $attrs[VAL] ); 736 746 … … 766 776 } 767 777 } 768 769 } else if( strstr( $attrs[NAME], 'MONARCH-JOB' ) ) {770 778 } 779 else if( strstr( $attrs[NAME], 'MONARCH-JOB' ) ) 780 { 771 781 sscanf( $attrs[NAME], 'MONARCH-JOB-%d-%d', $jobid, $monincr ); 772 782 773 783 if( !isset( $jobs[$jobid] ) ) 784 { 774 785 $jobs[$jobid] = array(); 786 } 775 787 776 788 $fields = explode( ' ', $attrs[VAL] ); 777 789 778 foreach( $fields as $f ) { 790 foreach( $fields as $f ) 791 { 779 792 $togavalues = explode( '=', $f ); 780 793 … … 782 795 $togavalue = $togavalues[1]; 783 796 784 if( $toganame == 'nodes' ) {785 786 if( $jobs[$jobid][status] == 'R' ) {787 797 if( $toganame == 'nodes' ) 798 { 799 if( $jobs[$jobid][status] == 'R' ) 800 { 788 801 if( !isset( $jobs[$jobid][$toganame] ) ) 802 { 789 803 $jobs[$jobid][$toganame] = array(); 804 } 790 805 791 806 $mynodes = explode( ';', $togavalue ); 792 807 793 //print_r($mynodes); 794 795 foreach( $mynodes as $node ) { 796 797 if( !in_array( $node, $jobs[$jobid][$toganame] ) ) { 808 foreach( $mynodes as $node ) 809 { 810 if( !in_array( $node, $jobs[$jobid][$toganame] ) ) 811 { 798 812 $jobs[$jobid][$toganame][] = $node; 799 813 } 800 814 } 801 815 802 } else if( $jobs[$jobid][status] == 'Q' ) { 803 816 } 817 else if( $jobs[$jobid][status] == 'Q' ) 818 { 804 819 $jobs[$jobid][$toganame] = $togavalue; 805 820 } 806 807 } else {808 821 } 822 else 823 { 809 824 $jobs[$jobid][$toganame] = $togavalue; 810 825 } 811 826 } 812 827 813 if( isset( $jobs[$jobid][nodes] ) ) {814 828 if( isset( $jobs[$jobid][nodes] ) ) 829 { 815 830 $nr_nodes = count( $jobs[$jobid][nodes] ); 816 831 … … 860 875 861 876 if( !isset( $nodes[$host] ) ) 877 { 862 878 $my_node = new NodeImage( $this->proc_cluster, $host ); 879 } 863 880 else 881 { 864 882 $my_node = $nodes[$host]; 883 } 865 884 866 885 if( !$my_node->hasJob( $jobid ) ) 867 886 { 868 887 if( isset( $jobs[$jobid][ppn] ) ) 888 { 869 889 $my_node->addJob( $jobid, ((int) $jobs[$jobid][ppn]) ); 890 } 870 891 else 892 { 871 893 $my_node->addJob( $jobid, 1 ); 894 } 895 } 872 896 873 897 $nodes[$host] = $my_node; … … 877 901 } 878 902 } 879 $this->jobs = $jobs; 880 //print_r( $nodes ); 881 $this->nodes = $nodes; 882 //print_r( $this->nodes ); 883 } 884 885 function stopElement( $parser, $name ) { 886 903 $this->jobs = $jobs; 904 $this->nodes = $nodes; 905 } 906 907 function stopElement( $parser, $name ) 908 { 887 909 $nodes = $this->nodes; 888 910 … … 893 915 foreach( $this->down_nodes as $reported => $dnodes ) 894 916 { 895 896 917 if( $reported == $this->heartbeat['time'] ) 897 918 { … … 946 967 } 947 968 948 function printInfo() {949 969 function printInfo() 970 { 950 971 $jobs = &$this->jobs; 951 972 952 973 printf( "---jobs---\n" ); 953 974 954 foreach( $jobs as $jobid => $job ) {955 975 foreach( $jobs as $jobid => $job ) 976 { 956 977 printf( "job %s\n", $jobid ); 957 978 958 if( isset( $job[nodes] ) ) {959 960 foreach( $job[nodes] as $node ) {961 979 if( isset( $job[nodes] ) ) 980 { 981 foreach( $job[nodes] as $node ) 982 { 962 983 $mynode = $this->nodes[$node]; 963 984 $hostname = $mynode->getHostname(); … … 965 986 966 987 printf( "\t- node %s\tlocation %s\n", $hostname, $location ); 967 //$this->nodes[$hostname]->setLocation( "hier draait job ".$jobid );968 988 } 969 989 } … … 974 994 $nodes = &$this->nodes; 975 995 976 foreach( $nodes as $node ) {977 996 foreach( $nodes as $node ) 997 { 978 998 $hostname = $node->getHostname(); 979 999 $location = $node->getLocation(); … … 983 1003 } 984 1004 985 function getNodes() {986 //print_r( $this->nodes );1005 function getNodes() 1006 { 987 1007 return $this->nodes; 988 1008 } 989 1009 990 function getNode( $node ) {991 1010 function getNode( $node ) 1011 { 992 1012 $nodes = &$this->nodes; 1013 993 1014 if( isset( $nodes[$node] ) ) 1015 { 994 1016 return $nodes[$node]; 1017 } 995 1018 else 1019 { 996 1020 return NULL; 997 } 998 999 function getJobs() { 1021 } 1022 } 1023 1024 function getJobs() 1025 { 1000 1026 return $this->jobs; 1001 1027 } 1002 1028 1003 function getJob( $job ) {1004 1029 function getJob( $job ) 1030 { 1005 1031 $jobs = &$this->jobs; 1032 1006 1033 if( isset( $jobs[$job] ) ) 1034 { 1007 1035 return $jobs[$job]; 1036 } 1008 1037 else 1038 { 1009 1039 return NULL; 1010 } 1011 1012 function getHeartbeat() { 1040 } 1041 } 1042 1043 function getHeartbeat() 1044 { 1013 1045 return $this->heartbeat['time']; 1014 1046 } 1015 1047 } 1016 1048 1017 class NodeImage {1018 1049 class NodeImage 1050 { 1019 1051 var $image, $x, $y, $hostname, $jobs, $tasks, $showinfo; 1020 1052 1021 function NodeImage( $cluster, $hostname ) {1022 1053 function NodeImage( $cluster, $hostname ) 1054 { 1023 1055 global $SMALL_CLUSTERIMAGE_NODEWIDTH; 1024 1056 1025 $this->jobs = array(); 1026 //$this->image = $image; 1027 //$this->x = $x; 1028 //$this->y = $y; 1029 $this->tasks = 0; 1030 $this->hostname = $hostname; 1031 $this->cpus = $this->determineCpus(); 1032 $this->clustername = $cluster; 1033 $this->showinfo = 1; 1034 $this->size = $SMALL_CLUSTERIMAGE_NODEWIDTH; 1035 $this->down = 0; 1036 $this->offline = 0; 1037 } 1038 1039 function addJob( $jobid, $cpus ) { 1040 $jobs = &$this->jobs; 1041 1042 $jobs[] = $jobid; 1043 $this->jobs = $jobs; 1057 $this->jobs = array(); 1058 $this->tasks = 0; 1059 $this->hostname = $hostname; 1060 $this->cpus = $this->determineCpus(); 1061 $this->clustername = $cluster; 1062 $this->showinfo = 1; 1063 $this->size = $SMALL_CLUSTERIMAGE_NODEWIDTH; 1064 $this->down = 0; 1065 $this->offline = 0; 1066 } 1067 1068 function addJob( $jobid, $cpus ) 1069 { 1070 $jobs = &$this->jobs; 1071 $jobs[] = $jobid; 1072 $this->jobs = $jobs; 1044 1073 1045 1074 $this->addTask( $cpus ); 1046 1075 } 1047 1076 1048 function hasJob( $jobid ) {1049 1077 function hasJob( $jobid ) 1078 { 1050 1079 $jobfound = 0; 1051 1080 1052 1081 if( count( $this->jobs ) > 0 ) 1082 { 1053 1083 foreach( $this->jobs as $job ) 1054 1084 { 1055 1085 if( $job == $jobid ) 1086 { 1056 1087 $jobfound = 1; 1088 } 1089 } 1090 } 1057 1091 1058 1092 return $jobfound; 1059 1093 } 1060 1094 1061 function addTask( $cpus ) {1062 1095 function addTask( $cpus ) 1096 { 1063 1097 $this->tasks = $this->tasks + $cpus; 1064 1098 } 1065 1099 1066 function setDown( $down ) {1067 1100 function setDown( $down ) 1101 { 1068 1102 $this->down = $down; 1069 1103 } 1070 1104 1071 function isDown() {1072 1105 function isDown() 1106 { 1073 1107 return $this->down; 1074 1108 } 1075 function setOffline( $offline ) {1076 1109 function setOffline( $offline ) 1110 { 1077 1111 $this->offline = $offline; 1078 1112 } 1079 1113 1080 function isOffline() {1081 1114 function isOffline() 1115 { 1082 1116 return $this->offline; 1083 1117 } 1084 1118 1085 function setImage( $image ) {1086 1119 function setImage( $image ) 1120 { 1087 1121 $this->image = $image; 1088 1122 } 1089 1123 1090 function setCoords( $x, $y ) {1091 1124 function setCoords( $x, $y ) 1125 { 1092 1126 $this->x = $x; 1093 1127 $this->y = $y; 1094 1128 } 1095 1129 1096 function getImagemapArea() {1097 1130 function getImagemapArea() 1131 { 1098 1132 $area_topleft = $this->x . "," . $this->y; 1099 1133 $area_bottomright = ($this->x + $this->size) . "," . ($this->y + $this->size); … … 1123 1157 } 1124 1158 1125 function colorHex( $color ) {1126 1159 function colorHex( $color ) 1160 { 1127 1161 $my_color = imageColorAllocate( $this->image, hexdec( substr( $color, 0, 2 )), hexdec( substr( $color, 2, 2 )), hexdec( substr( $color, 4, 2 )) ); 1128 1162 … … 1130 1164 } 1131 1165 1132 function setLoad( $load ) { 1166 function setLoad( $load ) 1167 { 1133 1168 $this->load = $load; 1134 1169 } 1135 1170 1136 function setHostname( $hostname ) { 1171 function setHostname( $hostname ) 1172 { 1137 1173 $this->hostname = $hostname; 1138 1174 } 1139 1175 1140 function getHostname() { 1176 function getHostname() 1177 { 1141 1178 return $this->hostname; 1142 1179 } 1143 1180 1144 function getJobs() { 1181 function getJobs() 1182 { 1145 1183 return $this->jobs; 1146 1184 } 1147 1185 1148 function setShowinfo( $showinfo ) { 1186 function setShowinfo( $showinfo ) 1187 { 1149 1188 $this->showinfo = $showinfo; 1150 1189 } 1151 1190 1152 function drawSmall() {1153 1191 function drawSmall() 1192 { 1154 1193 global $SMALL_CLUSTERIMAGE_NODEWIDTH; 1155 1194 … … 1159 1198 } 1160 1199 1161 function drawBig() {1162 1200 function drawBig() 1201 { 1163 1202 global $BIG_CLUSTERIMAGE_NODEWIDTH; 1164 1203 … … 1168 1207 } 1169 1208 1170 function draw() {1171 1209 function draw() 1210 { 1172 1211 global $JOB_NODE_MARKING, $NODE_DOWN_MARKING, $NODE_OFFLINE_MARKING; 1173 1212 … … 1177 1216 imageFilledRectangle( $this->image, $this->x, $this->y, $this->x+($size), $this->y+($size), $black_color ); 1178 1217 1179 if( $this->showinfo) {1180 1218 if( $this->showinfo) 1219 { 1181 1220 $this->load = $this->determineLoad(); 1182 1221 1183 if( !isset( $this->image ) or !isset( $this->x ) or !isset( $this->y ) ) { 1222 if( !isset( $this->image ) or !isset( $this->x ) or !isset( $this->y ) ) 1223 { 1184 1224 printf( "aborting\n" ); 1185 1225 printf( "x %d y %d load %f\n", $this->x, $this->y, $load ); 1186 1226 return; 1187 1227 } 1188 1189 1228 1190 1229 // Convert Ganglias Hexadecimal load color to a Decimal one … … 1205 1244 imageString( $this->image, 1, $this->x+(($size/2)-1), $this->y+(($size/2)-4), $JOB_NODE_MARKING, $black_color ); 1206 1245 } 1207 1208 } else {1209 1246 } 1247 else 1248 { 1210 1249 // White 1211 1250 $usecolor = imageColorAllocate( $this->image, 255, 255, 255 ); 1212 1251 imageFilledRectangle( $this->image, $this->x+1, $this->y+1, $this->x+($size-1), $this->y+($size-1), $usecolor ); 1213 1252 } 1214 1215 1216 } 1217 1218 function determineCpus() { 1219 1253 } 1254 1255 function determineCpus() 1256 { 1220 1257 global $metrics; 1221 1258 1222 1259 $cpus = $metrics[$this->hostname][cpu_num][VAL]; 1223 if (!$cpus) $cpus=1; 1260 1261 if (!$cpus) 1262 { 1263 $cpus=1; 1264 } 1224 1265 1225 1266 return $cpus; 1226 1267 } 1227 1268 1228 function determineLoad() {1229 1269 function determineLoad() 1270 { 1230 1271 global $metrics; 1231 1272 1232 $load_one 1233 $load 1273 $load_one = $metrics[$this->hostname][load_one][VAL]; 1274 $load = ((float) $load_one)/$this->cpus; 1234 1275 1235 1276 return $load; … … 1237 1278 } 1238 1279 1239 class ClusterImage {1240 1280 class ClusterImage 1281 { 1241 1282 var $dataget, $image, $clustername; 1242 1283 var $filtername, $filters; 1243 1284 1244 //function ClusterImage( $clustername ) { 1245 function ClusterImage( $data, $clustername ) { 1246 1247 //$this->dataget = $dataget; 1285 function ClusterImage( $data, $clustername ) 1286 { 1248 1287 $this->dataget = new DataGatherer( $clustername ); 1249 1288 $this->data = $data; … … 1256 1295 } 1257 1296 1258 function getWidth() { 1297 function getWidth() 1298 { 1259 1299 return $this->width; 1260 1300 } 1261 function getHeight() { 1301 function getHeight() 1302 { 1262 1303 return $this->height; 1263 1304 } 1264 1265 function setSmall(){1305 function setSmall() 1306 { 1266 1307 $this->size = 's'; 1267 1308 } 1268 1269 function setBig(){1309 function setBig() 1310 { 1270 1311 $this->size = 'b'; 1271 1312 } 1272 1273 function setNoimage(){1313 function setNoimage() 1314 { 1274 1315 $this->output = 0; 1275 1316 } 1276 1277 function isSmall(){1317 function isSmall() 1318 { 1278 1319 return ($this->size == 's'); 1279 1320 } 1280 1281 function isBig(){1321 function isBig() 1322 { 1282 1323 return ($this->size == 'b'); 1283 1324 } 1284 1285 function setFilter( $filtername, $filtervalue ) { 1286 1325 function setFilter( $filtername, $filtervalue ) 1326 { 1287 1327 $this->filters[$filtername] = $filtervalue; 1288 1328 } 1289 1329 1290 function filterNodes( $jobs, $nodes ) {1291 1330 function filterNodes( $jobs, $nodes ) 1331 { 1292 1332 $filtered_nodes = array(); 1293 1333 1294 foreach( $nodes as $node ) {1295 1334 foreach( $nodes as $node ) 1335 { 1296 1336 $hostname = $node->getHostname(); 1297 1337 1298 1338 $addhost = 1; 1299 1339 1300 if( count( $this->filters ) > 0 ) {1301 1340 if( count( $this->filters ) > 0 ) 1341 { 1302 1342 $mynjobs = $node->getJobs(); 1303 1343 1304 if( count( $mynjobs ) > 0 ) { 1305 1306 foreach( $mynjobs as $myjob ) { 1307 1308 foreach( $this->filters as $filtername => $filtervalue ) { 1309 1310 if( $filtername!=null && $filtername!='' ) { 1311 1312 if( $filtername == 'jobid' && !$node->hasJob( $filtervalue) ) { 1344 if( count( $mynjobs ) > 0 ) 1345 { 1346 foreach( $mynjobs as $myjob ) 1347 { 1348 foreach( $this->filters as $filtername => $filtervalue ) 1349 { 1350 if( $filtername!=null && $filtername!='' ) 1351 { 1352 if( $filtername == 'jobid' && !$node->hasJob( $filtervalue) ) 1353 { 1313 1354 $addhost = 0; 1314 } else if( $filtername != 'jobid' ) { 1315 if( $jobs[$myjob][$filtername] != $filtervalue ) { 1355 } 1356 else if( $filtername != 'jobid' ) 1357 { 1358 if( $jobs[$myjob][$filtername] != $filtervalue ) 1359 { 1316 1360 $addhost = 0; 1317 1361 } … … 1320 1364 } 1321 1365 } 1322 } else 1366 } 1367 else 1368 { 1323 1369 $addhost = 0; 1370 } 1324 1371 } 1325 1372 1326 1373 if( $addhost ) 1374 { 1327 1375 $filtered_nodes[] = $hostname; 1376 } 1328 1377 } 1329 1378 … … 1331 1380 } 1332 1381 1333 function draw() {1334 1382 function draw() 1383 { 1335 1384 global $SMALL_CLUSTERIMAGE_MAXWIDTH, $SMALL_CLUSTERIMAGE_NODEWIDTH; 1336 1385 global $BIG_CLUSTERIMAGE_MAXWIDTH, $BIG_CLUSTERIMAGE_NODEWIDTH; … … 1348 1397 } 1349 1398 1350 //global $SORTBY_HOSTNAME, $SORT_ORDER;1351 //global $SORT_XLABEL, $SORT_YLABEL;1352 1353 //printf( "SORTBY_HOSTNAME %s SORT_YLABEL %s\n", $SORTBY_HOSTNAME, $SORT_YLABEL );1354 1355 1399 $mydatag = $this->dataget; 1356 1400 $mydatag->parseXML( $this->data ); 1357 1401 1358 if( $this->isSmall() ) { 1359 $max_width = $SMALL_CLUSTERIMAGE_MAXWIDTH; 1360 $node_width = $SMALL_CLUSTERIMAGE_NODEWIDTH; 1361 } else if( $this->isBig() ) { 1362 $max_width = $BIG_CLUSTERIMAGE_MAXWIDTH; 1363 $node_width = $BIG_CLUSTERIMAGE_NODEWIDTH; 1364 } 1365 1366 $nodes = $mydatag->getNodes(); 1367 $nodes_hosts = array_keys( $nodes ); 1368 1369 $nodes_nr = count( $nodes ); 1370 1371 $nodes_size = $nodes_nr*$node_width; 1372 $node_rows = 0; 1373 1374 if( $nodes_size > $max_width ) { 1402 if( $this->isSmall() ) 1403 { 1404 $max_width = $SMALL_CLUSTERIMAGE_MAXWIDTH; 1405 $node_width = $SMALL_CLUSTERIMAGE_NODEWIDTH; 1406 } 1407 else if( $this->isBig() ) 1408 { 1409 $max_width = $BIG_CLUSTERIMAGE_MAXWIDTH; 1410 $node_width = $BIG_CLUSTERIMAGE_NODEWIDTH; 1411 } 1412 1413 $nodes = $mydatag->getNodes(); 1414 $nodes_hosts = array_keys( $nodes ); 1415 1416 $nodes_nr = count( $nodes ); 1417 1418 $nodes_size = $nodes_nr*$node_width; 1419 $node_rows = 0; 1420 1421 if( $nodes_size > $max_width ) 1422 { 1375 1423 $nodes_per_row = ( (int) ($max_width/$node_width) ); 1376 } else { 1424 } 1425 else 1426 { 1377 1427 $nodes_per_row = $nodes_size; 1378 1428 $node_rows = 1; 1379 1429 } 1380 1430 1381 if( $nodes_per_row < $nodes_nr ) { 1431 if( $nodes_per_row < $nodes_nr ) 1432 { 1382 1433 $node_rows = ( (int) ($nodes_nr/$nodes_per_row) ); 1383 1434 $node_rest = fmod( $nodes_nr, $nodes_per_row ); 1384 //printf( "nodesnr %d noderest %f\n", $nodes_nr, $node_rest ); 1385 if( $node_rest > 0 ) { 1435 1436 if( $node_rest > 0 ) 1437 { 1386 1438 $node_rows++; 1387 //printf( "noderows %d\n", $node_rows );1388 1439 } 1389 1440 } … … 1399 1450 $this->height = ($y_offset + (($node_rows*$node_width)+1) ); 1400 1451 1401 //$image = imageCreateTrueColor( $max_width, ($y_offset + (($node_rows*$node_width)+1) ) );1402 //$colorwhite = imageColorAllocate( $image, 255, 255, 255 );1403 //imageFill( $image, 0, 0, $colorwhite );1404 1405 //if( $this->isSmall() ) {1406 1407 // $colorblue = imageColorAllocate( $image, 0, 0, 255 );1408 1409 // imageString( $image, $font, 2, 2, "Monarch Joblist - cluster: ".$this->clustername, $colorblue );1410 //}1411 1412 1452 $jobs = $mydatag->getJobs(); 1413 //printf("filtername = %s\n", $filtername );1414 1453 $filtered_nodes = $this->filterNodes( $jobs, $nodes ); 1415 1416 //print_r($filtered_nodes);1417 1454 1418 1455 if( $SORTBY_HOSTNAME != "" ) … … 1622 1659 1623 1660 } 1624 //$x_offset = ($fontwidth * 3) + (5 * $fontspaceing);1625 1626 //printf( "xmin %s xmax %s\n", $x_min, $x_max );1627 //printf( "ymin %s ymax %s\n", $y_min, $y_max );1628 1629 // werkt1630 //print_r( $nodes );1631 1661 1632 1662 $image_width = $x_offset + ($node_width * ($x_max-$x_min+2)); … … 1635 1665 { 1636 1666 $image_width = $max_width; 1637 } else if( $this->isBig() ) 1667 } 1668 else if( $this->isBig() ) 1638 1669 { 1639 1670 $image_width = ($image_width < $max_width) ? $image_width : $max_width; 1640 1671 } 1641 //else if( $this->isSmall() )1642 //{1643 // $image_width = $this->width;1644 //}1645 1672 $image_height = $y_offset + ($node_width * ($y_max-$y_min+2)); 1646 1673 … … 1653 1680 imageFill( $image, 0, 0, $colorwhite ); 1654 1681 1655 if( $this->isSmall() ) {1656 1682 if( $this->isSmall() ) 1683 { 1657 1684 // Draw a fancy little header text to explain what it is 1658 1685 // … … 1779 1806 $nodes[$cur_node]->setImage( $image ); 1780 1807 1781 //print_r( $nodes[$cur_node] );1782 1783 1808 if( $this->isSmall() ) 1809 { 1784 1810 $nodes[$cur_node]->drawSmall(); 1811 } 1785 1812 else if( $this->isBig() ) 1813 { 1786 1814 $nodes[$cur_node]->drawBig(); 1815 } 1787 1816 1788 1817 $cur_node++; … … 1794 1823 else 1795 1824 { 1796 if( $this->isSmall() ) { 1825 if( $this->isSmall() ) 1826 { 1797 1827 $image = imageCreateTrueColor( $max_width, ($y_offset + (($node_rows*$node_width)+1) ) ); 1798 } else if( $this->isBig() ) { 1828 } 1829 else if( $this->isBig() ) 1830 { 1799 1831 $image_width = ($node_width * $nodes_nr) + 2; 1800 1832 $image_width = ($image_width < $max_width) ? $image_width : $max_width; … … 1805 1837 imageFill( $image, 0, 0, $colorwhite ); 1806 1838 1807 if( $this->isSmall() ) {1808 1839 if( $this->isSmall() ) 1840 { 1809 1841 $colorblue = imageColorAllocate( $image, 0, 0, 255 ); 1810 1842 … … 1812 1844 } 1813 1845 1814 for( $n = 0; $n < $node_rows; $n++ ) {1815 1816 for( $m = 0; $m < $nodes_per_row; $m++ ) {1817 1846 for( $n = 0; $n < $node_rows; $n++ ) 1847 { 1848 for( $m = 0; $m < $nodes_per_row; $m++ ) 1849 { 1818 1850 $x = ($m * $node_width); 1819 1851 $y = $y_offset + ($n * $node_width); … … 1822 1854 $host = $nodes_hosts[$cur_node]; 1823 1855 1824 if( isset( $nodes[$host] ) ) {1825 1856 if( isset( $nodes[$host] ) ) 1857 { 1826 1858 $nodes[$host]->setCoords( $x, $y ); 1827 1859 $nodes[$host]->setImage( $image ); … … 1833 1865 1834 1866 if( $this->isSmall() ) 1867 { 1835 1868 $nodes[$host]->drawSmall(); 1869 } 1836 1870 else if( $this->isBig() ) 1871 { 1837 1872 $nodes[$host]->drawBig(); 1873 } 1838 1874 } 1839 1875 } … … 1843 1879 $this->nodes = &$nodes; 1844 1880 1845 if ($this->output) { 1881 if ($this->output) 1882 { 1846 1883 header( 'Content-type: image/png' ); 1847 1884 imagePNG( $image ); … … 1850 1887 } 1851 1888 1852 function getImagemapArea() {1853 1889 function getImagemapArea() 1890 { 1854 1891 $clusterimage_map = ""; 1855 1892 1856 foreach( $this->nodes as $hostname => $node ) {1857 1893 foreach( $this->nodes as $hostname => $node ) 1894 { 1858 1895 $node_map = $node->getImagemapArea(); 1859 1896 $clusterimage_map .= $node_map; … … 1864 1901 } 1865 1902 1866 class EmptyImage { 1867 1868 function draw() { 1903 class EmptyImage 1904 { 1905 function draw() 1906 { 1869 1907 $image = imageCreateTrueColor( 1, 1 ); 1870 1908 $colorwhite = imageColorAllocate( $image, 255, 255, 255 ); … … 1877 1915 } 1878 1916 1879 class HostImage {1880 1917 class HostImage 1918 { 1881 1919 var $data_gather, $cluster, $host, $node, $image; 1882 1920 var $headerstrlen; 1883 1921 1884 function HostImage( $data_gather, $cluster, $host ) {1885 1922 function HostImage( $data_gather, $cluster, $host ) 1923 { 1886 1924 $this->data_gather = $data_gather; 1887 1925 $this->cluster = $cluster; … … 1901 1939 } 1902 1940 1903 function drawJobs() {1904 1941 function drawJobs() 1942 { 1905 1943 $dg = &$this->data_gather; 1906 1944 $colorblack = imageColorAllocate( $this->image, 0, 0, 0 ); 1907 1945 1908 for( $n = 0; $n < count( $this->njobs ); $n++ ) {1909 1946 for( $n = 0; $n < count( $this->njobs ); $n++ ) 1947 { 1910 1948 $jobid = $this->njobs[$n]; 1911 1949 $jobinfo = $dg->getJob( $jobid ); … … 1914 1952 imageString( $this->image, $this->font, $xoffset, $this->y_offset, strval( $jobid ), $colorblack ); 1915 1953 1916 foreach( $this->headerstrlen as $headername => $headerlen ) { 1917 1918 if( $headername == 'nodes' ) { 1954 foreach( $this->headerstrlen as $headername => $headerlen ) 1955 { 1956 if( $headername == 'nodes' ) 1957 { 1919 1958 $attrval = strval( count( $jobinfo[nodes] ) ); 1920 } else if( $headername == 'cpus' ) { 1921 1959 } 1960 else if( $headername == 'cpus' ) 1961 { 1922 1962 if( !isset( $jobinfo[ppn] ) ) 1963 { 1923 1964 $jobinfo[ppn] = 1; 1965 } 1924 1966 1925 1967 $attrval = strval( count( $jobinfo[nodes] ) * intval( $jobinfo[ppn] ) ); 1926 1927 } else if( $headername == 'runningtime' ) { 1968 } 1969 else if( $headername == 'runningtime' ) 1970 { 1928 1971 $attrval = makeTime( intval( $jobinfo[reported] ) - intval( $jobinfo[start_timestamp] ) ); 1929 } else { 1972 } 1973 else 1974 { 1930 1975 $attrval = strval( $jobinfo[$headername] ); 1931 1976 } … … 1934 1979 1935 1980 $xoffset = $xoffset + ($this->fontwidth * ( $headerlen + 1 ) ); 1936 1937 1981 } 1938 1982 … … 1941 1985 } 1942 1986 1943 function drawHeader() {1944 1987 function drawHeader() 1988 { 1945 1989 $dg = &$this->data_gather; 1946 1990 1947 for( $n = 0; $n < count( $this->njobs ); $n++ ) {1948 1991 for( $n = 0; $n < count( $this->njobs ); $n++ ) 1992 { 1949 1993 $jobid = $this->njobs[$n]; 1950 1994 $jobinfo = $dg->getJob( $jobid ); 1951 1995 1952 1996 if( !isset( $this->headerstrlen[id] ) ) 1997 { 1953 1998 $this->headerstrlen[id] = strlen( strval( $jobid ) ); 1954 else 1955 if( strlen( strval( $jobid ) ) > $this->headerstrlen[id] ) 1956 $this->headerstrlen[id] = strlen( strval( $jobid ) ); 1999 } 2000 else if( strlen( strval( $jobid ) ) > $this->headerstrlen[id] ) 2001 { 2002 $this->headerstrlen[id] = strlen( strval( $jobid ) ); 2003 } 1957 2004 1958 2005 if( !isset( $this->headerstrlen[owner] ) ) 2006 { 1959 2007 $this->headerstrlen[owner] = strlen( strval( $jobinfo[owner] ) ); 1960 else 1961 if( strlen( strval( $jobinfo[owner] ) ) > $this->headerstrlen[owner] ) 1962 $this->headerstrlen[owner] = strlen( strval( $jobinfo[owner] ) ); 2008 } 2009 else if( strlen( strval( $jobinfo[owner] ) ) > $this->headerstrlen[owner] ) 2010 { 2011 $this->headerstrlen[owner] = strlen( strval( $jobinfo[owner] ) ); 2012 } 1963 2013 1964 2014 if( !isset( $this->headerstrlen[queue] ) ) 2015 { 1965 2016 $this->headerstrlen[queue] = strlen( strval( $jobinfo[queue] ) ); 1966 else 1967 if( strlen( strval( $jobinfo[queue] ) ) > $this->headerstrlen[queue] ) 1968 $this->headerstrlen[queue] = strlen( strval( $jobinfo[queue] ) ); 2017 } 2018 else if( strlen( strval( $jobinfo[queue] ) ) > $this->headerstrlen[queue] ) 2019 { 2020 $this->headerstrlen[queue] = strlen( strval( $jobinfo[queue] ) ); 2021 } 1969 2022 1970 2023 if( !isset( $jobinfo[ppn] ) ) 2024 { 1971 2025 $jobinfo[ppn] = 1; 2026 } 1972 2027 1973 2028 $cpus = count( $jobinfo[nodes] ) * intval( $jobinfo[ppn] ); 1974 2029 1975 2030 if( !isset( $this->headerstrlen[cpus] ) ) 2031 { 1976 2032 $this->headerstrlen[cpus] = strlen( strval( $cpus ) ); 1977 else 1978 if( strlen( strval( $cpus ) ) > $this->headerstrlen[cpus] ) 1979 $this->headerstrlen[cpus] = strlen( strval( $cpus ) ); 2033 } 2034 else if( strlen( strval( $cpus ) ) > $this->headerstrlen[cpus] ) 2035 { 2036 $this->headerstrlen[cpus] = strlen( strval( $cpus ) ); 2037 } 1980 2038 1981 2039 $nodes = count( $jobinfo[nodes] ); 1982 2040 1983 2041 if( !isset( $this->headerstrlen[nodes] ) ) 2042 { 1984 2043 $this->headerstrlen[nodes] = strlen( strval( $nodes ) ); 1985 else 1986 if( strlen( strval( $nodes) ) > $this->headerstrlen[nodes] ) 1987 $this->headerstrlen[nodes] = strlen( strval( $nodes ) ); 2044 } 2045 else if( strlen( strval( $nodes) ) > $this->headerstrlen[nodes] ) 2046 { 2047 $this->headerstrlen[nodes] = strlen( strval( $nodes ) ); 2048 } 1988 2049 1989 2050 $runningtime = makeTime( intval( $jobinfo[reported] ) - intval( $jobinfo[start_timestamp] ) ); 1990 2051 1991 2052 if( !isset( $this->headerstrlen[runningtime] ) ) 2053 { 1992 2054 $this->headerstrlen[runningtime] = strlen( strval( $runningtime) ); 1993 else 1994 if( strlen( strval( $runningtime) ) > $this->headerstrlen[runningtime] ) 1995 $this->headerstrlen[runningtime] = strlen( strval( $runningtime) ); 2055 } 2056 else if( strlen( strval( $runningtime) ) > $this->headerstrlen[runningtime] ) 2057 { 2058 $this->headerstrlen[runningtime] = strlen( strval( $runningtime) ); 2059 } 1996 2060 1997 2061 if( !isset( $this->headerstrlen[name] ) ) 2062 { 1998 2063 $this->headerstrlen[name] = strlen( strval( $jobinfo[name] ) ); 1999 else 2000 if( strlen( strval( $jobinfo[name] ) ) > $this->headerstrlen[name] ) 2001 $this->headerstrlen[name] = strlen( strval( $jobinfo[name] ) ); 2002 2064 } 2065 else if( strlen( strval( $jobinfo[name] ) ) > $this->headerstrlen[name] ) 2066 { 2067 $this->headerstrlen[name] = strlen( strval( $jobinfo[name] ) ); 2068 } 2003 2069 } 2004 2070 2005 2071 $xoffset = 5; 2006 2072 2007 foreach( $this->headerstrlen as $headername => $headerlen ) {2008 2073 foreach( $this->headerstrlen as $headername => $headerlen ) 2074 { 2009 2075 $colorgreen = imageColorAllocate( $this->image, 0, 200, 0 ); 2010 2076 2011 2077 if( $headerlen < strlen( $headername ) ) 2078 { 2012 2079 $this->headerstrlen[$headername] = strlen( $headername ); 2080 } 2013 2081 2014 2082 imageString( $this->image, $this->font, $xoffset, $this->y_offset, ucfirst( $headername ), $colorgreen ); 2015 2083 2016 2084 $xoffset = $xoffset + ($this->fontwidth * ( $this->headerstrlen[$headername] + 1 ) ); 2017 2018 2085 } 2019 2086 $this->newLineOffset(); 2020 2087 } 2021 2088 2022 function newLineOffset() {2023 2089 function newLineOffset() 2090 { 2024 2091 $this->y_offset = $this->y_offset + $this->fontheight + $this->fontspaceing; 2025 2092 } 2026 2093 2027 function draw() {2028 2094 function draw() 2095 { 2029 2096 $xlen = 450; 2030 2097 $ylen = ( count( $this->njobs ) * ( $this->fontheight + $this->fontspaceing ) ) + (3 * $this->fontheight); … … 2088 2155 global $x_present, $y_present; 2089 2156 2090 //printf("ppoep = %s\n", $skan_str);2091 2157 $a_node = $a; 2092 2158 $b_node = $b; … … 2228 2294 } 2229 2295 } 2230 function makeTime( $time ) {2231 2296 function makeTime( $time ) 2297 { 2232 2298 $days = intval( $time / 86400 ); 2233 2299 $time = ($days>0) ? $time % ($days * 86400) : $time; 2234 2300 2235 //printf( "time = %s, days = %s\n", $time, $days );2236 2237 2301 $date_str = ''; 2238 2302 $day_str = ''; 2239 2303 2240 if( $days > 0 ) { 2304 if( $days > 0 ) 2305 { 2241 2306 if( $days > 1 ) 2307 { 2242 2308 $day_str .= $days . ' days'; 2309 } 2243 2310 else 2311 { 2244 2312 $day_str .= $days . ' day'; 2313 } 2245 2314 } 2246 2315 … … 2248 2317 $time = $hours ? $time % ($hours * 3600) : $time; 2249 2318 2250 //printf( "time = %s, days = %s, hours = %s\n", $time, $days, $hours );2251 if( $hours > 0 ){2319 if( $hours > 0 ) 2320 { 2252 2321 $date_str .= $hours . ':'; 2253 2322 $date_unit = 'hours'; … … 2257 2326 $seconds = $minutes ? $time % ($minutes * 60) : $time; 2258 2327 2259 if( $minutes > 0 ) {2260 2328 if( $minutes > 0 ) 2329 { 2261 2330 if( $minutes >= 10 ) 2331 { 2262 2332 $date_str .= $minutes . ':'; 2333 } 2263 2334 else 2335 { 2264 2336 $date_str .= '0' . $minutes . ':'; 2337 } 2265 2338 2266 2339 $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit; 2267 } else { 2268 if($hours > 0 ) { 2340 } 2341 else 2342 { 2343 if($hours > 0 ) 2344 { 2269 2345 $date_str .= '00:'; 2270 2346 $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit; … … 2272 2348 } 2273 2349 2274 2275 2350 $date_unit = (!isset($date_unit)) ? 'seconds' : $date_unit; 2276 2351 2277 if( $seconds > 0 ) {2278 2352 if( $seconds > 0 ) 2353 { 2279 2354 if( $seconds >= 10 ) 2355 { 2280 2356 $date_str .= $seconds . ' ' . $date_unit; 2357 } 2281 2358 else 2359 { 2282 2360 $date_str .= '0' . $seconds . ' ' . $date_unit; 2283 2284 } else if ( $hours > 0 or $minutes > 0 ) 2285 2361 } 2362 } 2363 else if ( $hours > 0 or $minutes > 0 ) 2364 { 2286 2365 $date_str .= '00 ' . $date_unit; 2287 2288 if( $days > 0) { 2289 2366 } 2367 2368 if( $days > 0) 2369 { 2290 2370 if( $hours > 0 or $minutes > 0 or $seconds > 0 ) 2371 { 2291 2372 $date_str = $day_str . ' - ' . $date_str; 2373 } 2292 2374 else 2375 { 2293 2376 $date_str = $day_str; 2377 } 2294 2378 } 2295 2296 2379 return $date_str; 2297 2380 }
Note: See TracChangeset
for help on using the changeset viewer.