Ignore:
Timestamp:
05/25/05 09:09:29 (19 years ago)
Author:
bastiaans
Message:

toga/libtoga.php:

  • Code cleanup
  • Http vars fix

toga/image.php:

  • Http vars fix
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/web/addons/toga/libtoga.php

    r111 r112  
    11<?php
    2 //$GANGLIA_PATH = "/var/www/ganglia";
     2class 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}
    337
    438// Toga's conf
     
    842global $GANGLIA_PATH, $SMALL_CLUSTERIMAGE_MAXWIDTH, $SMALL_CLUSTERIMAGE_NODEWIDTH, $DATA_SOURCE;
    943
    10 //printf("gpath %s clmaxw %s ndmaxw %s ds %s",$GANGLIA_PATH, $SMALL_CLUSTERIMAGE_MAXWIDTH, $SMALL_CLUSTERIMAGE_NODEWIDTH, $DATA_SOURCE);
    11 
    1244include_once "$GANGLIA_PATH/conf.php";
    1345include_once "$GANGLIA_PATH/functions.php";
    1446include_once "$GANGLIA_PATH/ganglia.php";
    1547
     48global $HTTP_GET_VARS;
     49$httpvars = new HTTPVariables( $HTTP_GET_VARS );
     50
    1651// Set cluster context so that Ganglia will
    1752// provide us with the correct metrics array
    1853//
    19 global $context;
     54global $context, $clustername;
     55$clustername = $httpvars->getClusterName();
    2056$context = 'cluster';
    2157
    2258include_once "$GANGLIA_PATH/get_ganglia.php";
     59
     60// Ganglia's array of host metrics
     61//
     62global $metrics;
    2363
    2464// If php is compiled without globals
     
    2666if ( !empty( $_GET ) ) {
    2767        extract( $_GET );
    28 }
    29 
    30 // Ganglia's array of host metrics
    31 //
    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                 else
    70                         return null;
    71         }
    7268}
    7369
     
    120116
    121117                $this->parser = xml_parser_create();
    122                 $this->httpvars = new HTTPVariables();
     118                $this->httpvars = $httpvars;
    123119                $this->xmlhandler = new TorqueXMLHandler();
    124120                xml_set_element_handler( $this->parser, array( &$this->xmlhandler, 'startElement' ), array( &$this->xmlhandler, 'stopElement' ) );
     
    130126                $this->data = $src->getData();
    131127
    132                 if ( !xml_parse( &$this->parser, $this->data ) ) {
     128                if ( !xml_parse( &$this->parser, $this->data ) )
    133129                        $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                 }
    136130        }
    137131
     
    164158        }
    165159
    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 
    186160        function startElement( $parser, $name, $attrs ) {
    187161
     
    215189                                $this->nodes[$hostname] = new NodeImage( $hostname );
    216190
    217                         //$this->gotNode( $hostname, $location, null );
    218 
    219191                } else if( $name == 'METRIC' and strstr( $attrs[NAME], 'TOGA' ) ) {
    220192
     
    250222                                                $mynodes = explode( ';', $togavalue );
    251223
    252                                                 foreach( $mynodes as $node ) {
    253 
    254                                                         //$hostname = $node.'.'.$jobs[$jobid][domain];
     224                                                foreach( $mynodes as $node )
     225
    255226                                                        $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 
    266227                                        } else {
    267228
     
    271232
    272233                                if( isset( $jobs[$jobid][domain] ) and isset( $jobs[$jobid][nodes] ) ) {
    273                                
     234                       
     235                                        $nr_nodes = count( $jobs[$jobid][nodes] );
     236                       
    274237                                        foreach( $jobs[$jobid][nodes] as $node ) {
    275238
     
    290253                                                $this->nodes[$host] = $my_node;
    291254                                        }
    292                                 } else {
    293 
    294                                         printf( "no domain or nodes set for %s\n", $jobid );
    295255                                }
    296256                        }
     
    344304        function getJobs() {
    345305                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();
    421306        }
    422307}
     
    496381                $this->load = $this->determineLoad();
    497382
    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 ) ) {
    499384                        printf( "aborting\n" );
    500385                        printf( "x %d y %d load %f\n", $this->x, $this->y, $load );
     
    579464
    580465                $nodes_nr = count( $nodes );
    581                 //printf( "%d nodes\n", $nodes_nr );
    582466
    583467                $nodes_size = $nodes_nr*$node_width;
     
    622506                                        $nodes[$host]->draw();
    623507                                }
    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                         //      }
    654508                        }
    655509                }
     
    665519//$my_data->printInfo();
    666520
    667 $ic = new ClusterImage( "LISA Cluster" );
    668 $ic->draw();
     521//$ic = new ClusterImage( "LISA Cluster" );
     522//$ic->draw();
    669523?>
Note: See TracChangeset for help on using the changeset viewer.