Changeset 112
- Timestamp:
- 05/25/05 09:09:29 (19 years ago)
- Location:
- trunk/web/addons/toga
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/web/addons/toga/image.php
r111 r112 1 1 <?php 2 3 2 include_once "./libtoga.php"; 4 3 5 $httpvars = new HTTPVariables(); 6 4 $httpvars = new HTTPVariables( $HTTP_GET_VARS ); 7 5 $view = $httpvars->getHttpVar( "view" ); 8 6 $clustername = $httpvars->getClusterName(); -
trunk/web/addons/toga/libtoga.php
r111 r112 1 1 <?php 2 //$GANGLIA_PATH = "/var/www/ganglia"; 2 class HTTPVariables { 3 4 var $clustername, $metricname; 5 var $restvars, $httpvars; 6 7 function HTTPVariables( $vars ) { 8 9 $this->restvars = array(); 10 11 $this->clustername = $vars["c"] ? $vars["c"] : null; 12 $this->metricname = $vars["m"] ? $vars["m"] : null; 13 14 foreach( $vars as $httpvar => $httpval ) { 15 16 if( $httpval ) { 17 $this->restvars[$httpvar] = $httpval; 18 } 19 } 20 } 21 22 function getClusterName() { 23 return $this->clustername; 24 } 25 26 function getMetricName() { 27 return $this->metricname; 28 } 29 30 function getHttpVar( $var ) { 31 if( isset( $this->restvars[$var] ) ) 32 return $this->restvars[$var]; 33 else 34 return null; 35 } 36 } 3 37 4 38 // Toga's conf … … 8 42 global $GANGLIA_PATH, $SMALL_CLUSTERIMAGE_MAXWIDTH, $SMALL_CLUSTERIMAGE_NODEWIDTH, $DATA_SOURCE; 9 43 10 //printf("gpath %s clmaxw %s ndmaxw %s ds %s",$GANGLIA_PATH, $SMALL_CLUSTERIMAGE_MAXWIDTH, $SMALL_CLUSTERIMAGE_NODEWIDTH, $DATA_SOURCE);11 12 44 include_once "$GANGLIA_PATH/conf.php"; 13 45 include_once "$GANGLIA_PATH/functions.php"; 14 46 include_once "$GANGLIA_PATH/ganglia.php"; 15 47 48 global $HTTP_GET_VARS; 49 $httpvars = new HTTPVariables( $HTTP_GET_VARS ); 50 16 51 // Set cluster context so that Ganglia will 17 52 // provide us with the correct metrics array 18 53 // 19 global $context; 54 global $context, $clustername; 55 $clustername = $httpvars->getClusterName(); 20 56 $context = 'cluster'; 21 57 22 58 include_once "$GANGLIA_PATH/get_ganglia.php"; 59 60 // Ganglia's array of host metrics 61 // 62 global $metrics; 23 63 24 64 // If php is compiled without globals … … 26 66 if ( !empty( $_GET ) ) { 27 67 extract( $_GET ); 28 }29 30 // Ganglia's array of host metrics31 //32 global $metrics;33 34 //print_r($metrics);35 36 class HTTPVariables {37 38 var $clustername, $metricname;39 var $restvars;40 41 function HTTPVariables() {42 43 $this->restvars = array();44 45 global $HTTP_GET_VARS;46 47 $this->clustername = $HTTP_GET_VARS["c"] ? $HTTP_GET_VARS["c"] : null;48 $this->metricname = $HTTP_GET_VARS["m"] ? $HTTP_GET_VARS["m"] : null;49 50 foreach( $HTTP_GET_VARS as $httpvar => $httpval ) {51 52 if( $httpval ) {53 $this->restvars[$httpvar] = $httpval;54 }55 }56 }57 58 function getClusterName() {59 return $this->clustername;60 }61 62 function getMetricName() {63 return $this->metricname;64 }65 66 function getHttpVar( $var ) {67 if( isset( $this->restvars[$var] ) )68 return $retval;69 else70 return null;71 }72 68 } 73 69 … … 120 116 121 117 $this->parser = xml_parser_create(); 122 $this->httpvars = new HTTPVariables();118 $this->httpvars = $httpvars; 123 119 $this->xmlhandler = new TorqueXMLHandler(); 124 120 xml_set_element_handler( $this->parser, array( &$this->xmlhandler, 'startElement' ), array( &$this->xmlhandler, 'stopElement' ) ); … … 130 126 $this->data = $src->getData(); 131 127 132 if ( !xml_parse( &$this->parser, $this->data ) ) {128 if ( !xml_parse( &$this->parser, $this->data ) ) 133 129 $error = sprintf( 'XML error: %s at %d', xml_error_string( xml_get_error_code( &$this->parser ) ), xml_get_current_line_number( &$this->parser ) ); 134 // die( $error );135 }136 130 } 137 131 … … 164 158 } 165 159 166 function gotNode( $hostname, $location = 'unspecified', $jobid ) {167 168 $nodes = &$this->nodes;169 170 if( !isset( $nodes[$hostname] ) ) {171 172 $nodes[$hostname] = new Node( $hostname );173 }174 175 if( $location ) {176 177 $nodes[$hostname]->setLocation( $location );178 }179 180 if( $jobid ) {181 $nodes[$hostname]->addJob( $jobid );182 //printf("add job %s to node %s", $jobid, $hostname );183 }184 }185 186 160 function startElement( $parser, $name, $attrs ) { 187 161 … … 215 189 $this->nodes[$hostname] = new NodeImage( $hostname ); 216 190 217 //$this->gotNode( $hostname, $location, null );218 219 191 } else if( $name == 'METRIC' and strstr( $attrs[NAME], 'TOGA' ) ) { 220 192 … … 250 222 $mynodes = explode( ';', $togavalue ); 251 223 252 foreach( $mynodes as $node ) { 253 254 //$hostname = $node.'.'.$jobs[$jobid][domain]; 224 foreach( $mynodes as $node ) 225 255 226 $jobs[$jobid][$toganame][] = $node; 256 257 //if( !isset( $this->nodes[$hostname] ) )258 //$mynode = new NodeImage( $hostname );259 260 //$the_node = $this->nodes[$hostname];261 //$the_node->addJob( $jobid,262 //$this->gotNode( $hostname, null, $jobid );263 //printf( "got node %s\n", $node );264 }265 266 227 } else { 267 228 … … 271 232 272 233 if( isset( $jobs[$jobid][domain] ) and isset( $jobs[$jobid][nodes] ) ) { 273 234 235 $nr_nodes = count( $jobs[$jobid][nodes] ); 236 274 237 foreach( $jobs[$jobid][nodes] as $node ) { 275 238 … … 290 253 $this->nodes[$host] = $my_node; 291 254 } 292 } else {293 294 printf( "no domain or nodes set for %s\n", $jobid );295 255 } 296 256 } … … 344 304 function getJobs() { 345 305 return $this->jobs; 346 }347 }348 349 class Node {350 351 var $img, $hostname, $location, $jobs;352 var $x, $y;353 354 function Node( $hostname ) {355 356 $this->hostname = $hostname;357 //$this->img = new NodeImg();358 $this->jobs = array();359 }360 361 function addJob( $jobid ) {362 $jobs = &$this->jobs;363 364 $jobs[] = $jobid;365 //print_r( $jobs );366 $this->jobs = $jobs;367 }368 369 370 function setLocation( $location ) {371 $this->location = $location;372 }373 374 function setHostname( $hostname ) {375 $this->hostname = $hostname;376 }377 378 function setCpus( $cpus ) {379 $this->cpus = $cpus;380 }381 382 function getHostname() {383 return $this->hostname;384 }385 386 function getLocation() {387 return $this->location;388 }389 390 function getCpus() {391 return $this->cpus;392 }393 394 function getJobs() {395 //print_r( $this->jobs );396 return $this->jobs;397 }398 399 //function setCoords( $x, $y ) {400 //$myimg = $this->img;401 //$myimg->setCoords( $x, $y );402 //}403 404 function setImage( $image ) {405 $myimg = $this->img;406 $myimg->setImage( &$image );407 }408 409 function draw() {410 global $metrics;411 412 $myimg = $this->img;413 414 $cpus = $metrics[$this->hostname]["cpu_num"][VAL];415 if (!$cpus) $cpus=1;416 $load_one = $metrics[$this->hostname]["load_one"][VAL];417 $load = ((float) $load_one)/$cpus;418 419 $myimg->setLoad( $load );420 $myimg->draw();421 306 } 422 307 } … … 496 381 $this->load = $this->determineLoad(); 497 382 498 if( !isset( $this-> x ) or !isset( $this->y ) or !isset( $this->load) ) {383 if( !isset( $this->image ) or !isset( $this->x ) or !isset( $this->y ) ) { 499 384 printf( "aborting\n" ); 500 385 printf( "x %d y %d load %f\n", $this->x, $this->y, $load ); … … 579 464 580 465 $nodes_nr = count( $nodes ); 581 //printf( "%d nodes\n", $nodes_nr );582 466 583 467 $nodes_size = $nodes_nr*$node_width; … … 622 506 $nodes[$host]->draw(); 623 507 } 624 625 626 //printf( "host %s curnode %s ", $host, $cur_node );627 628 // if( isset( $nodes[$host] ) and ($cur_node < $nodes_nr) ) {629 // //printf( "image %s\n", $host );630 // $nodejobs = $nodes[$host]->getJobs();631 // $jobs = $mydatag->getJobs();632 633 // $multiproc_job = 0;634 635 // if( count( $nodejobs ) > 0 ) {636 // $multiproc_job = 1;637 638 // foreach( $nodejobs as $myjob ){639 // if( isset($jobs[$myjob]['ppn']) and $jobs[$myjob]['ppn'] > 1 )640 // $multiproc_job = 2;641 // break;642 // }643 // }644 645 //printf( "jobs %s node %s", $nrjobs, $host );646 // $node = new NodeImage( $image, $x, $y, $host, $multiproc_job );647 //$node->setHostname( $host );648 // $node->draw();649 //$nodes[$host]->setCoords( $x, $y );650 //$nodes[$host]->setImage( &$image );651 //$nodes[$host]->draw();652 //$cur_node++;653 // }654 508 } 655 509 } … … 665 519 //$my_data->printInfo(); 666 520 667 $ic = new ClusterImage( "LISA Cluster" );668 $ic->draw();521 //$ic = new ClusterImage( "LISA Cluster" ); 522 //$ic->draw(); 669 523 ?>
Note: See TracChangeset
for help on using the changeset viewer.