[102] | 1 | <?php |
---|
[117] | 2 | // If php is compiled without globals |
---|
| 3 | // |
---|
| 4 | if ( !empty( $_GET ) ) { |
---|
| 5 | extract( $_GET ); |
---|
| 6 | } |
---|
| 7 | |
---|
[103] | 8 | class HTTPVariables { |
---|
| 9 | |
---|
| 10 | var $clustername, $metricname; |
---|
[112] | 11 | var $restvars, $httpvars; |
---|
[103] | 12 | |
---|
[117] | 13 | function HTTPVariables( $httpvars, $getvars ) { |
---|
[103] | 14 | |
---|
[110] | 15 | $this->restvars = array(); |
---|
| 16 | |
---|
[117] | 17 | $this->clustername = $httpvars["c"] ? $httpvars["c"] : null; |
---|
| 18 | $this->metricname = $httpvars["m"] ? $httpvars["m"] : null; |
---|
[103] | 19 | |
---|
[117] | 20 | foreach( $httpvars as $httpvar => $httpval ) { |
---|
[110] | 21 | |
---|
| 22 | if( $httpval ) { |
---|
| 23 | $this->restvars[$httpvar] = $httpval; |
---|
| 24 | } |
---|
| 25 | } |
---|
[117] | 26 | |
---|
| 27 | foreach( $getvars as $getvar => $getval ) { |
---|
| 28 | |
---|
| 29 | if( $getval ) { |
---|
| 30 | $this->restvars[$getvar] = $getval; |
---|
| 31 | } |
---|
| 32 | } |
---|
[103] | 33 | } |
---|
| 34 | |
---|
| 35 | function getClusterName() { |
---|
| 36 | return $this->clustername; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | function getMetricName() { |
---|
| 40 | return $this->metricname; |
---|
| 41 | } |
---|
[110] | 42 | |
---|
| 43 | function getHttpVar( $var ) { |
---|
| 44 | if( isset( $this->restvars[$var] ) ) |
---|
[112] | 45 | return $this->restvars[$var]; |
---|
[110] | 46 | else |
---|
| 47 | return null; |
---|
| 48 | } |
---|
[103] | 49 | } |
---|
| 50 | |
---|
[112] | 51 | // Toga's conf |
---|
| 52 | // |
---|
| 53 | include_once "./conf.php"; |
---|
| 54 | |
---|
[117] | 55 | global $GANGLIA_PATH; |
---|
[112] | 56 | |
---|
[117] | 57 | $my_dir = getcwd(); |
---|
[112] | 58 | |
---|
[117] | 59 | // Load Ganglia's PHP |
---|
| 60 | chdir( $GANGLIA_PATH ); |
---|
[112] | 61 | |
---|
[117] | 62 | include_once "./conf.php"; |
---|
| 63 | include_once "./functions.php"; |
---|
| 64 | include_once "./ganglia.php"; |
---|
| 65 | include_once "./get_context.php"; |
---|
| 66 | include_once "./get_ganglia.php"; |
---|
| 67 | |
---|
| 68 | // Back to our PHP |
---|
| 69 | chdir( $my_dir ); |
---|
| 70 | |
---|
| 71 | global $SMALL_CLUSTERIMAGE_MAXWIDTH, $SMALL_CLUSTERIMAGE_NODEWIDTH, $DATA_SOURCE, $HTTP_GET_VARS, $_GET; |
---|
| 72 | $httpvars = new HTTPVariables( $HTTP_GET_VARS, $_GET ); |
---|
| 73 | |
---|
[112] | 74 | // Set cluster context so that Ganglia will |
---|
| 75 | // provide us with the correct metrics array |
---|
| 76 | // |
---|
| 77 | global $context, $clustername; |
---|
[117] | 78 | //$clustername = $httpvars->getClusterName(); |
---|
| 79 | //$context = 'cluster'; |
---|
[112] | 80 | |
---|
| 81 | // Ganglia's array of host metrics |
---|
| 82 | // |
---|
| 83 | global $metrics; |
---|
| 84 | |
---|
| 85 | |
---|
[103] | 86 | class DataSource { |
---|
| 87 | |
---|
| 88 | var $data, $ip, $port; |
---|
| 89 | |
---|
| 90 | function DataSource( $ip = '127.0.0.1', $port = 8649 ) { |
---|
| 91 | $this->ip = $ip; |
---|
| 92 | $this->port = $port; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | function getData() { |
---|
| 96 | |
---|
| 97 | $errstr; |
---|
| 98 | $errno = 0; |
---|
| 99 | $timeout = 3; |
---|
| 100 | |
---|
| 101 | $fp = fsockopen( $this->ip, $this->port, &$errno, &$errstr, $timeout ); |
---|
| 102 | |
---|
[106] | 103 | if( !$fp ) { |
---|
[103] | 104 | echo 'Unable to connect to '.$this->ip.':'.$this->port; // printf( 'Unable to connect to [%s:%.0f]', $this->ip, $this->port ); |
---|
| 105 | return; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | while ( !feof( $fp ) ) { |
---|
| 109 | |
---|
| 110 | $data .= fread( $fp, 16384 ); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | fclose( $fp ); |
---|
| 114 | |
---|
| 115 | return $data; |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | class DataGatherer { |
---|
| 120 | |
---|
[105] | 121 | var $xmlhandler, $data, $httpvars; |
---|
[103] | 122 | |
---|
| 123 | function DataGatherer() { |
---|
| 124 | |
---|
[110] | 125 | global $DATA_SOURCE; |
---|
| 126 | |
---|
| 127 | $ds_fields = explode( ':', $DATA_SOURCE ); |
---|
| 128 | $ds_ip = $ds_fields[0]; |
---|
| 129 | $ds_port = $ds_fields[1]; |
---|
| 130 | |
---|
| 131 | $this->source = new DataSource( $ds_ip, $ds_port ); |
---|
| 132 | |
---|
[103] | 133 | $this->parser = xml_parser_create(); |
---|
[112] | 134 | $this->httpvars = $httpvars; |
---|
[103] | 135 | $this->xmlhandler = new TorqueXMLHandler(); |
---|
| 136 | xml_set_element_handler( $this->parser, array( &$this->xmlhandler, 'startElement' ), array( &$this->xmlhandler, 'stopElement' ) ); |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | function parseXML() { |
---|
| 140 | |
---|
| 141 | $src = &$this->source; |
---|
| 142 | $this->data = $src->getData(); |
---|
| 143 | |
---|
[112] | 144 | if ( !xml_parse( &$this->parser, $this->data ) ) |
---|
[103] | 145 | $error = sprintf( 'XML error: %s at %d', xml_error_string( xml_get_error_code( &$this->parser ) ), xml_get_current_line_number( &$this->parser ) ); |
---|
| 146 | } |
---|
| 147 | |
---|
[105] | 148 | function printInfo() { |
---|
| 149 | $handler = $this->xmlhandler; |
---|
| 150 | $handler->printInfo(); |
---|
| 151 | } |
---|
| 152 | |
---|
[106] | 153 | function getNodes() { |
---|
| 154 | $handler = $this->xmlhandler; |
---|
| 155 | return $handler->getNodes(); |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | function getJobs() { |
---|
| 159 | $handler = $this->xmlhandler; |
---|
| 160 | return $handler->getJobs(); |
---|
| 161 | } |
---|
| 162 | |
---|
[114] | 163 | function getHeartbeat() { |
---|
| 164 | $handler = $this->xmlhandler; |
---|
| 165 | return $handler->getHeartbeat(); |
---|
| 166 | } |
---|
[103] | 167 | } |
---|
| 168 | |
---|
| 169 | class TorqueXMLHandler { |
---|
| 170 | |
---|
[105] | 171 | var $clusters, $heartbeat, $nodes, $jobs; |
---|
[104] | 172 | |
---|
[103] | 173 | function TorqueXMLHandler() { |
---|
[105] | 174 | $jobs = array(); |
---|
[104] | 175 | $clusters = array(); |
---|
[105] | 176 | $nodes = array(); |
---|
[104] | 177 | $heartbeat = array(); |
---|
[103] | 178 | } |
---|
| 179 | |
---|
| 180 | function startElement( $parser, $name, $attrs ) { |
---|
| 181 | |
---|
[105] | 182 | $jobs = &$this->jobs; |
---|
[111] | 183 | $nodes = &$this->nodes; |
---|
[105] | 184 | |
---|
[103] | 185 | if ( $attrs[TN] ) { |
---|
| 186 | |
---|
| 187 | // Ignore dead metrics. Detect and mask failures. |
---|
| 188 | if ( $attrs[TN] > $attrs[TMAX] * 4 ) |
---|
| 189 | return; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | $jobid = null; |
---|
| 193 | |
---|
[104] | 194 | // printf( '%s=%s', $attrs[NAME], $attrs[VAL] ); |
---|
[103] | 195 | |
---|
[104] | 196 | if( $name == 'CLUSTER' ) { |
---|
[103] | 197 | |
---|
[104] | 198 | $clustername = $attrs[VAL]; |
---|
[103] | 199 | |
---|
[104] | 200 | if( !isset( $clusters[$clustername] ) ) |
---|
| 201 | $clusters[$clustername] = array(); |
---|
[103] | 202 | |
---|
[105] | 203 | } else if( $name == 'HOST' ) { |
---|
| 204 | |
---|
| 205 | $hostname = $attrs[NAME]; |
---|
| 206 | $location = $attrs[LOCATION]; |
---|
| 207 | |
---|
[111] | 208 | if( !isset( $this->nodes[$hostname] ) ) |
---|
| 209 | $this->nodes[$hostname] = new NodeImage( $hostname ); |
---|
[105] | 210 | |
---|
[104] | 211 | } else if( $name == 'METRIC' and strstr( $attrs[NAME], 'TOGA' ) ) { |
---|
[103] | 212 | |
---|
[104] | 213 | if( strstr( $attrs[NAME], 'TOGA-HEARTBEAT' ) ) { |
---|
[103] | 214 | |
---|
[114] | 215 | $this->heartbeat['time'] = $attrs[VAL]; |
---|
[106] | 216 | //printf( "heartbeat %s\n", $heartbeat['time'] ); |
---|
[104] | 217 | |
---|
| 218 | } else if( strstr( $attrs[NAME], 'TOGA-JOB' ) ) { |
---|
| 219 | |
---|
| 220 | sscanf( $attrs[NAME], 'TOGA-JOB-%d', $jobid ); |
---|
| 221 | |
---|
[106] | 222 | //printf( "jobid %s\n", $jobid ); |
---|
[104] | 223 | |
---|
| 224 | if( !isset( $jobs[$jobid] ) ) |
---|
| 225 | $jobs[$jobid] = array(); |
---|
| 226 | |
---|
| 227 | $fields = explode( ' ', $attrs[VAL] ); |
---|
| 228 | |
---|
| 229 | foreach( $fields as $f ) { |
---|
| 230 | $togavalues = explode( '=', $f ); |
---|
| 231 | |
---|
| 232 | $toganame = $togavalues[0]; |
---|
| 233 | $togavalue = $togavalues[1]; |
---|
| 234 | |
---|
[106] | 235 | //printf( "\t%s\t= %s\n", $toganame, $togavalue ); |
---|
[104] | 236 | |
---|
[103] | 237 | if( $toganame == 'nodes' ) { |
---|
| 238 | |
---|
[106] | 239 | if( !isset( $jobs[$jobid][$toganame] ) ) |
---|
[105] | 240 | $jobs[$jobid][$toganame] = array(); |
---|
[104] | 241 | |
---|
[111] | 242 | $mynodes = explode( ';', $togavalue ); |
---|
[103] | 243 | |
---|
[112] | 244 | foreach( $mynodes as $node ) |
---|
[103] | 245 | |
---|
[111] | 246 | $jobs[$jobid][$toganame][] = $node; |
---|
[104] | 247 | } else { |
---|
[103] | 248 | |
---|
[105] | 249 | $jobs[$jobid][$toganame] = $togavalue; |
---|
[104] | 250 | } |
---|
[103] | 251 | } |
---|
[111] | 252 | |
---|
| 253 | if( isset( $jobs[$jobid][domain] ) and isset( $jobs[$jobid][nodes] ) ) { |
---|
[112] | 254 | |
---|
| 255 | $nr_nodes = count( $jobs[$jobid][nodes] ); |
---|
| 256 | |
---|
[111] | 257 | foreach( $jobs[$jobid][nodes] as $node ) { |
---|
| 258 | |
---|
| 259 | $host = $node.'.'.$jobs[$jobid][domain]; |
---|
| 260 | |
---|
| 261 | if( !isset( $this->nodes[$host] ) ) |
---|
| 262 | $my_node = new NodeImage( $host ); |
---|
| 263 | else |
---|
| 264 | $my_node = $this->nodes[$host]; |
---|
| 265 | |
---|
| 266 | if( !$my_node->hasJob( $jobid ) ) |
---|
| 267 | |
---|
| 268 | if( isset( $jobs[$jobid][ppn] ) ) |
---|
| 269 | $my_node->addJob( $jobid, ((int) $jobs[$jobid][ppn]) ); |
---|
| 270 | else |
---|
| 271 | $my_node->addJob( $jobid, 1 ); |
---|
| 272 | |
---|
| 273 | $this->nodes[$host] = $my_node; |
---|
| 274 | } |
---|
| 275 | } |
---|
[103] | 276 | } |
---|
| 277 | } |
---|
[114] | 278 | $this->jobs = $jobs; |
---|
[103] | 279 | } |
---|
| 280 | |
---|
| 281 | function stopElement( $parser, $name ) { |
---|
| 282 | } |
---|
[105] | 283 | |
---|
| 284 | function printInfo() { |
---|
| 285 | |
---|
| 286 | $jobs = &$this->jobs; |
---|
| 287 | |
---|
| 288 | printf( "---jobs---\n" ); |
---|
| 289 | |
---|
| 290 | foreach( $jobs as $jobid => $job ) { |
---|
| 291 | |
---|
| 292 | printf( "job %s\n", $jobid ); |
---|
| 293 | |
---|
| 294 | if( isset( $job[nodes] ) ) { |
---|
| 295 | |
---|
| 296 | foreach( $job[nodes] as $node ) { |
---|
| 297 | |
---|
| 298 | $mynode = $this->nodes[$node]; |
---|
| 299 | $hostname = $mynode->getHostname(); |
---|
| 300 | $location = $mynode->getLocation(); |
---|
| 301 | |
---|
| 302 | printf( "\t- node %s\tlocation %s\n", $hostname, $location ); |
---|
| 303 | //$this->nodes[$hostname]->setLocation( "hier draait job ".$jobid ); |
---|
| 304 | } |
---|
| 305 | } |
---|
| 306 | } |
---|
| 307 | |
---|
| 308 | printf( "---nodes---\n" ); |
---|
| 309 | |
---|
| 310 | $nodes = &$this->nodes; |
---|
| 311 | |
---|
| 312 | foreach( $nodes as $node ) { |
---|
| 313 | |
---|
| 314 | $hostname = $node->getHostname(); |
---|
| 315 | $location = $node->getLocation(); |
---|
| 316 | $jobs = implode( ' ', $node->getJobs() ); |
---|
| 317 | printf( "* node %s\tlocation %s\tjobs %s\n", $hostname, $location, $jobs ); |
---|
| 318 | } |
---|
| 319 | } |
---|
[106] | 320 | |
---|
| 321 | function getNodes() { |
---|
| 322 | return $this->nodes; |
---|
| 323 | } |
---|
| 324 | |
---|
| 325 | function getJobs() { |
---|
| 326 | return $this->jobs; |
---|
| 327 | } |
---|
[114] | 328 | |
---|
| 329 | function getHeartbeat() { |
---|
| 330 | return $this->heartbeat['time']; |
---|
| 331 | } |
---|
[103] | 332 | } |
---|
| 333 | |
---|
[107] | 334 | class NodeImage { |
---|
[102] | 335 | |
---|
[111] | 336 | var $image, $x, $y, $hostname, $jobs, $tasks; |
---|
[102] | 337 | |
---|
[111] | 338 | function NodeImage( $hostname ) { |
---|
[102] | 339 | |
---|
[111] | 340 | $this->jobs = array(); |
---|
| 341 | //$this->image = $image; |
---|
| 342 | //$this->x = $x; |
---|
| 343 | //$this->y = $y; |
---|
| 344 | $this->tasks = 0; |
---|
[110] | 345 | $this->hostname = $hostname; |
---|
[111] | 346 | $this->cpus = $this->determineCpus(); |
---|
[102] | 347 | } |
---|
| 348 | |
---|
[111] | 349 | function addJob( $jobid, $cpus ) { |
---|
| 350 | $jobs = &$this->jobs; |
---|
| 351 | |
---|
| 352 | $jobs[] = $jobid; |
---|
| 353 | $this->jobs = $jobs; |
---|
| 354 | |
---|
| 355 | $this->addTask( $cpus ); |
---|
| 356 | } |
---|
| 357 | |
---|
| 358 | function hasJob( $jobid ) { |
---|
| 359 | |
---|
| 360 | $jobfound = 0; |
---|
| 361 | |
---|
| 362 | if( count( $this->jobs ) > 0 ) |
---|
| 363 | foreach( $this->jobs as $job ) |
---|
| 364 | |
---|
| 365 | if( $job == $jobid ) |
---|
| 366 | $jobfound = 1; |
---|
| 367 | |
---|
| 368 | return $jobfound; |
---|
| 369 | } |
---|
| 370 | |
---|
| 371 | function addTask( $cpus ) { |
---|
| 372 | |
---|
| 373 | $this->tasks = $this->tasks + $cpus; |
---|
| 374 | } |
---|
| 375 | |
---|
| 376 | function setImage( $image ) { |
---|
| 377 | |
---|
| 378 | $this->image = $image; |
---|
| 379 | } |
---|
| 380 | |
---|
[106] | 381 | function setCoords( $x, $y ) { |
---|
[107] | 382 | |
---|
[106] | 383 | $this->x = $x; |
---|
| 384 | $this->y = $y; |
---|
| 385 | } |
---|
| 386 | |
---|
[102] | 387 | function colorHex( $color ) { |
---|
| 388 | |
---|
[109] | 389 | $my_color = imageColorAllocate( $this->image, hexdec( substr( $color, 0, 2 )), hexdec( substr( $color, 2, 2 )), hexdec( substr( $color, 4, 2 )) ); |
---|
[102] | 390 | |
---|
| 391 | return $my_color; |
---|
| 392 | } |
---|
| 393 | |
---|
[106] | 394 | function setLoad( $load ) { |
---|
| 395 | $this->load = $load; |
---|
| 396 | } |
---|
| 397 | |
---|
[108] | 398 | function setHostname( $hostname ) { |
---|
| 399 | $this->hostname = $hostname; |
---|
| 400 | } |
---|
| 401 | |
---|
[114] | 402 | function getJobs() { |
---|
| 403 | return $this->jobs; |
---|
| 404 | } |
---|
| 405 | |
---|
[111] | 406 | function draw() { |
---|
[106] | 407 | |
---|
[111] | 408 | global $SMALL_CLUSTERIMAGE_NODEWIDTH, $JOB_NODE_MARKING_ALLCPUS, $JOB_NODE_MARKING_SINGLECPU; |
---|
[115] | 409 | global $JOB_NODE_MARKING; |
---|
[110] | 410 | |
---|
[111] | 411 | $this->load = $this->determineLoad(); |
---|
| 412 | |
---|
[112] | 413 | if( !isset( $this->image ) or !isset( $this->x ) or !isset( $this->y ) ) { |
---|
[107] | 414 | printf( "aborting\n" ); |
---|
| 415 | printf( "x %d y %d load %f\n", $this->x, $this->y, $load ); |
---|
[106] | 416 | return; |
---|
| 417 | } |
---|
| 418 | |
---|
[111] | 419 | $black_color = imageColorAllocate( $this->image, 0, 0, 0 ); |
---|
[106] | 420 | |
---|
[103] | 421 | // Convert Ganglias Hexadecimal load color to a Decimal one |
---|
[111] | 422 | // |
---|
| 423 | $load = $this->determineLoad(); |
---|
[102] | 424 | $my_loadcolor = $this->colorHex( load_color($load) ); |
---|
| 425 | |
---|
[110] | 426 | $size = $SMALL_CLUSTERIMAGE_NODEWIDTH; |
---|
[107] | 427 | |
---|
[110] | 428 | imageFilledRectangle( $this->image, $this->x, $this->y, $this->x+($size), $this->y+($size), $black_color ); |
---|
| 429 | imageFilledRectangle( $this->image, $this->x+1, $this->y+1, $this->x+($size-1), $this->y+($size-1), $my_loadcolor ); |
---|
| 430 | |
---|
[111] | 431 | $nr_jobs = count( $this->jobs ); |
---|
| 432 | |
---|
| 433 | $node_mark = null; |
---|
| 434 | |
---|
| 435 | if( count( $this->jobs ) > 0 ) |
---|
[115] | 436 | $node_mark = $JOB_NODE_MARKING; |
---|
[111] | 437 | |
---|
[115] | 438 | // if( $this->tasks < $this->cpus ) |
---|
| 439 | // $node_mark = $JOB_NODE_MARKING_SINGLECPU; |
---|
[111] | 440 | |
---|
[115] | 441 | // else if( $this->tasks == $this->cpus ) |
---|
| 442 | // $node_mark = $JOB_NODE_MARKING_ALLCPUS; |
---|
[111] | 443 | |
---|
| 444 | if( $node_mark ) |
---|
| 445 | imageString( $this->image, 1, $this->x+(($size/2)-2), $this->y+(($size/2)-3), $node_mark, $black_color ); |
---|
[102] | 446 | } |
---|
| 447 | |
---|
[111] | 448 | function determineCpus() { |
---|
[102] | 449 | |
---|
[108] | 450 | global $metrics; |
---|
| 451 | |
---|
| 452 | $cpus = $metrics[$this->hostname][cpu_num][VAL]; |
---|
[107] | 453 | if (!$cpus) $cpus=1; |
---|
[111] | 454 | |
---|
| 455 | return $cpus; |
---|
| 456 | } |
---|
| 457 | |
---|
| 458 | function determineLoad() { |
---|
| 459 | |
---|
| 460 | global $metrics; |
---|
| 461 | |
---|
[108] | 462 | $load_one = $metrics[$this->hostname][load_one][VAL]; |
---|
[111] | 463 | $load = ((float) $load_one)/$this->cpus; |
---|
[102] | 464 | |
---|
[111] | 465 | return $load; |
---|
[106] | 466 | } |
---|
| 467 | } |
---|
| 468 | |
---|
[107] | 469 | class ClusterImage { |
---|
[106] | 470 | |
---|
[111] | 471 | var $dataget, $image, $clustername; |
---|
[106] | 472 | |
---|
[114] | 473 | function ClusterImage( $clustername, $data_gather ) { |
---|
| 474 | |
---|
| 475 | if( !isset( $data_gather ) ) |
---|
| 476 | $this->dataget = new DataGatherer(); |
---|
| 477 | else |
---|
| 478 | $this->dataget = $data_gather; |
---|
| 479 | |
---|
[111] | 480 | $this->clustername = $clustername; |
---|
[106] | 481 | } |
---|
| 482 | |
---|
| 483 | function draw() { |
---|
[110] | 484 | |
---|
| 485 | global $SMALL_CLUSTERIMAGE_MAXWIDTH, $SMALL_CLUSTERIMAGE_NODEWIDTH; |
---|
| 486 | |
---|
[107] | 487 | $mydatag = $this->dataget; |
---|
[106] | 488 | $mydatag->parseXML(); |
---|
| 489 | |
---|
[110] | 490 | //$max_width = 250; |
---|
| 491 | //$node_width = 11; |
---|
[106] | 492 | |
---|
[110] | 493 | $max_width = $SMALL_CLUSTERIMAGE_MAXWIDTH; |
---|
| 494 | $node_width = $SMALL_CLUSTERIMAGE_NODEWIDTH; |
---|
| 495 | |
---|
| 496 | //printf( "cmaxw %s nmaxw %s", $SMALL_CLUSTERIMAGE_MAXWIDTH, $SMALL_CLUSTERIMAGE_NODEWIDTH ); |
---|
| 497 | |
---|
[106] | 498 | $nodes = $mydatag->getNodes(); |
---|
[111] | 499 | $nodes_hosts = array_keys( $nodes ); |
---|
[106] | 500 | |
---|
| 501 | $nodes_nr = count( $nodes ); |
---|
| 502 | |
---|
| 503 | $nodes_size = $nodes_nr*$node_width; |
---|
| 504 | $node_rows = 0; |
---|
| 505 | |
---|
| 506 | if( $nodes_size > $max_width ) { |
---|
[107] | 507 | $nodes_per_row = ( (int) ($max_width/$node_width) ); |
---|
[106] | 508 | } else { |
---|
| 509 | $nodes_per_row = $nodes_size; |
---|
| 510 | $node_rows = 1; |
---|
| 511 | } |
---|
| 512 | |
---|
| 513 | if( $nodes_per_row < $nodes_nr ) { |
---|
[107] | 514 | $node_rows = ( (int) ($nodes_nr/$nodes_per_row) ); |
---|
| 515 | $node_rest = fmod( $nodes_nr, $nodes_per_row ); |
---|
| 516 | //printf( "nodesnr %d noderest %f\n", $nodes_nr, $node_rest ); |
---|
| 517 | if( $node_rest > 0 ) { |
---|
[106] | 518 | $node_rows++; |
---|
[107] | 519 | //printf( "noderows %d\n", $node_rows ); |
---|
[106] | 520 | } |
---|
| 521 | } |
---|
| 522 | |
---|
[107] | 523 | //printf( "imagecreate: %dx%d", ($nodes_per_row*$node_width), ($node_rows*$node_width) ); |
---|
[109] | 524 | $image = imageCreateTrueColor( ($nodes_per_row*$node_width)+1, ($node_rows*$node_width)+1 ); |
---|
[107] | 525 | $colorwhite = imageColorAllocate( $image, 255, 255, 255 ); |
---|
| 526 | imageFill( $image, 0, 0, $colorwhite ); |
---|
[106] | 527 | |
---|
| 528 | for( $n = 0; $n < $node_rows; $n++ ) { |
---|
| 529 | |
---|
| 530 | for( $m = 0; $m < $nodes_per_row; $m++ ) { |
---|
[107] | 531 | |
---|
| 532 | $x = ($m * $node_width); |
---|
| 533 | $y = ($n * $node_width); |
---|
| 534 | |
---|
[109] | 535 | $cur_node = ($n * $nodes_per_row) + ($m); |
---|
[111] | 536 | $host = $nodes_hosts[$cur_node]; |
---|
[107] | 537 | |
---|
[111] | 538 | if( isset( $nodes[$host] ) ) { |
---|
| 539 | |
---|
| 540 | $nodes[$host]->setCoords( $x, $y ); |
---|
| 541 | $nodes[$host]->setImage( $image ); |
---|
| 542 | $nodes[$host]->draw(); |
---|
| 543 | } |
---|
[106] | 544 | } |
---|
| 545 | } |
---|
| 546 | |
---|
[103] | 547 | header( 'Content-type: image/png' ); |
---|
[106] | 548 | imagePNG( $image ); |
---|
| 549 | imageDestroy( $image ); |
---|
[102] | 550 | } |
---|
| 551 | } |
---|
| 552 | |
---|
[106] | 553 | //$my_data = new DataGatherer(); |
---|
| 554 | //$my_data->parseXML(); |
---|
| 555 | //$my_data->printInfo(); |
---|
| 556 | |
---|
[112] | 557 | //$ic = new ClusterImage( "LISA Cluster" ); |
---|
| 558 | //$ic->draw(); |
---|
[102] | 559 | ?> |
---|