- Timestamp:
- 05/17/05 17:01:38 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/web/addons/toga/toga-functions.php
r105 r106 1 <PRE>2 1 <?php 3 2 $GANGLIA_PATH = "/var/www/ganglia"; … … 48 47 $fp = fsockopen( $this->ip, $this->port, &$errno, &$errstr, $timeout ); 49 48 50 if( ! 49 if( !$fp ) { 51 50 echo 'Unable to connect to '.$this->ip.':'.$this->port; // printf( 'Unable to connect to [%s:%.0f]', $this->ip, $this->port ); 52 51 return; … … 93 92 } 94 93 94 function getNodes() { 95 $handler = $this->xmlhandler; 96 return $handler->getNodes(); 97 } 98 99 function getJobs() { 100 $handler = $this->xmlhandler; 101 return $handler->getJobs(); 102 } 103 95 104 } 96 105 … … 106 115 } 107 116 108 function gotNode( $hostname, $ jobid = null, $location = 'unspecified') {117 function gotNode( $hostname, $location = 'unspecified', $jobid = null ) { 109 118 110 119 $nodes = &$this->nodes; … … 115 124 } 116 125 117 if( $location != 'unspecified') {126 if( $location ) { 118 127 119 128 $nodes[$hostname]->setLocation( $location ); 120 //} else {121 122 // Return pointer to this node if location was not set123 // Which means that this is for a jobinfo124 //$mynode = &$nodes[$hostname];125 //return $mynode;126 129 } 127 130 … … 158 161 $location = $attrs[LOCATION]; 159 162 160 $this->gotNode( $hostname, null,$location);163 $this->gotNode( $hostname, $location, null ); 161 164 162 165 } else if( $name == 'METRIC' and strstr( $attrs[NAME], 'TOGA' ) ) { … … 165 168 166 169 $heartbeat['time'] = $attrs[VAL]; 167 printf( "heartbeat %s\n", $heartbeat['time'] );170 //printf( "heartbeat %s\n", $heartbeat['time'] ); 168 171 169 172 } else if( strstr( $attrs[NAME], 'TOGA-JOB' ) ) { … … 171 174 sscanf( $attrs[NAME], 'TOGA-JOB-%d', $jobid ); 172 175 173 printf( "jobid %s\n", $jobid );176 //printf( "jobid %s\n", $jobid ); 174 177 175 178 if( !isset( $jobs[$jobid] ) ) … … 184 187 $togavalue = $togavalues[1]; 185 188 186 printf( "\t%s\t= %s\n", $toganame, $togavalue );189 //printf( "\t%s\t= %s\n", $toganame, $togavalue ); 187 190 188 191 if( $toganame == 'nodes' ) { 189 192 190 if( !isset( $jobs[$ toganame] ) )193 if( !isset( $jobs[$jobid][$toganame] ) ) 191 194 $jobs[$jobid][$toganame] = array(); 192 195 … … 194 197 195 198 foreach( $nodes as $node ) { 196 197 // printf( "node %s\n", $node );198 199 199 200 $hostname = $node.'.'.$jobs[$jobid][domain]; 200 201 $jobs[$jobid][$toganame][] = $hostname; 201 $this->gotNode( $hostname, $jobid ); 202 203 //$jobs[$jobid][$toganame][$hostname] = $this->gotNode( $hostname ); 204 // $jobs[$toganame][$node] = new Node( $node ); 202 $this->gotNode( $hostname, null, $jobid ); 205 203 } 206 204 … … 208 206 209 207 $jobs[$jobid][$toganame] = $togavalue; 210 211 208 } 212 209 } … … 254 251 } 255 252 } 253 254 function getNodes() { 255 return $this->nodes; 256 } 257 258 function getJobs() { 259 return $this->jobs; 260 } 256 261 } 257 262 … … 259 264 260 265 var $img, $hostname, $location, $jobs; 266 var $x, $y; 261 267 262 268 function Node( $hostname ) { … … 300 306 return $this->jobs; 301 307 } 308 309 function setCoords( $x, $y ) { 310 $myimg = $this->img; 311 $myimg->setCoords( $x, $y ); 312 } 313 314 function setImage( $image ) { 315 $myimg = $this->img; 316 $myimg->setImage( &$image ); 317 } 318 319 function draw() { 320 $myimg = $this->img; 321 322 $cpus = $metrics[$this->hostname]["cpu_num"][VAL]; 323 if (!$cpus) $cpus=1; 324 $load_one = $metrics[$this->hostname]["load_one"][VAL]; 325 $load = ((float) $load_one)/$cpus; 326 327 $myimg->setLoad( $load ); 328 $myimg->draw(); 329 } 302 330 } 303 331 304 332 class NodeImg { 305 333 306 var $image ;334 var $image, $x, $y; 307 335 308 336 function NodeImg( $image = null ) { … … 321 349 $black_color = imageColorAllocate( $this->image, 0, 0, 0 ); 322 350 imageRectangle( $this->image, 0, 0, $imageWidth-1, $imageHeight-1, $black_color ); 351 $this->x = null; 352 $this->y = null; 353 } 354 355 function setCoords( $x, $y ) { 356 $this->x = $x; 357 $this->y = $y; 323 358 } 324 359 … … 330 365 } 331 366 332 function drawNode( $x, $y, &$queuecolor, $load, &$jobcolor ) { 367 function setImage( $image ) { 368 $this->image = $image; 369 } 370 371 function setLoad( $load ) { 372 $this->load = $load; 373 } 374 375 function drawNode( &$queuecolor, $load, &$jobcolor ) { 376 377 if( !$this->x or !$this->y or !$this->load ) { 378 return; 379 } 380 333 381 334 382 // Convert Ganglias Hexadecimal load color to a Decimal one 335 383 $my_loadcolor = $this->colorHex( load_color($load) ); 336 384 337 imageFilledRectangle( $this->image, $x, $y, $x+12, $y+12, $queuecolor ); 338 imageFilledRectangle( $this->image, $x+2, $y+2, $x+10, $y+10, $my_loadcolor ); 339 //imageFilledEllipse( $this->image, ($x+9)/2, ($y+9)/2, 6, 6, $jobcolor ); 340 } 341 342 function drawImage() { 385 imageFilledRectangle( $this->image, $this->x, $this->y, $this->x+12, $this->y+12, $queuecolor ); 386 imageFilledRectangle( $this->image, $this->x+2, $this->y+2, $this->x+10, $this->y+10, $my_loadcolor ); 387 // Een job markering? 388 //imageFilledEllipse( $this->image, ($this->x+9)/2, ($this->y+9)/2, 6, 6, $jobcolor ); 389 } 390 391 function draw() { 343 392 344 393 $queue_color = imageColorAllocate( $this->image, 0, 102, 304 ); 345 394 $job_color = imageColorAllocate( $this->image, 204, 204, 0 ); 346 395 347 $this->drawNode( 1, 1, $queue_color, 0.1, $job_color ); 396 $this->drawNode( $queue_color, 0.1, $job_color ); 397 } 398 } 399 400 class ImageCreator { 401 402 var $dataget, $image; 403 404 function ImageCreator() { 405 $this->dataget = new DataGatherer(); 406 } 407 408 function draw() { 409 $mydatag = &$this->dataget; 410 $mydatag->parseXML(); 411 412 $max_width = 150; 413 $node_width = 12; 414 415 $nodes = $mydatag->getNodes(); 416 417 $nodes_nr = count( $nodes ); 418 $node_keys = array_keys( $nodes ); 419 420 $nodes_size = $nodes_nr*$node_width; 421 $node_rows = 0; 422 423 if( $nodes_size > $max_width ) { 424 $nodes_per_row = (int) $max_width/$node_width; 425 } else { 426 $nodes_per_row = $nodes_size; 427 $node_rows = 1; 428 } 429 430 if( $nodes_per_row < $nodes_nr ) { 431 $node_rows = (int) $nodes_nr/$nodes_per_row; 432 if( ((int) fmod( $node_nr, ($nodes_nr*$nodes_per_row) )) > 0 ) { 433 $node_rows++; 434 } 435 } 436 437 $image = imageCreate( ($nodes_per_row*$node_width), ($node_rows*$node_width) ); 438 439 $cur_node = 0; 440 441 for( $n = 0; $n < $node_rows; $n++ ) { 442 443 for( $m = 0; $m < $nodes_per_row; $m++ ) { 444 445 $x = ($m*$node_width); 446 $y = ($m*$node_width)+($n*$node_width); 447 $host = $node_keys[$cur_node]; 448 //printf( "cur_node %d, host %s\n", $cur_node, $host ); 449 if( isset( $nodes[$host] ) and ($cur_node < $nodes_nr) ) { 450 $nodes[$host]->setCoords( $x, $y ); 451 $nodes[$host]->setImage( &$image ); 452 $nodes[$host]->draw(); 453 $cur_node++; 454 } 455 } 456 } 457 348 458 header( 'Content-type: image/png' ); 349 imagePNG( $ this->image );350 imageDestroy( $ this->image );459 imagePNG( $image ); 460 imageDestroy( $image ); 351 461 } 352 462 } … … 355 465 //$my_node->drawImage(); 356 466 357 $my_data = new DataGatherer(); 358 $my_data->parseXML(); 359 $my_data->printInfo(); 360 $my_data->printInfo(); 467 //$my_data = new DataGatherer(); 468 //$my_data->parseXML(); 469 //$my_data->printInfo(); 470 471 $ic = new ImageCreator(); 472 $ic->draw(); 361 473 ?> 362 </PRE>
Note: See TracChangeset
for help on using the changeset viewer.