1 | <?php |
---|
2 | |
---|
3 | $GANGLIA_PATH = "/var/www/ganglia"; |
---|
4 | |
---|
5 | include_once "$GANGLIA_PATH/conf.php"; |
---|
6 | include_once "$GANGLIA_PATH/functions.php"; |
---|
7 | |
---|
8 | class NodeImg { |
---|
9 | |
---|
10 | var $image; |
---|
11 | |
---|
12 | function NodeImg( $image = null ) { |
---|
13 | |
---|
14 | $imageWidth = 100; |
---|
15 | $imageHeight = 100; |
---|
16 | |
---|
17 | if( ! $image ) { |
---|
18 | $this->$image = @imageCreate( $imageWidth, $imageHeight ) |
---|
19 | or die( "Cannot initialize new image stream: is GD installed?" ); |
---|
20 | } else { |
---|
21 | $this->$image = $image; |
---|
22 | } |
---|
23 | |
---|
24 | $background_color = imageColorAllocate( $this->$image, 255, 255, 255 ); |
---|
25 | $black_color = imageColorAllocate( $this->$image, 0, 0, 0); |
---|
26 | imageRectangle( $this->$image, 0, 0, $imageWidth-1, $imageHeight-1, $black_color ); |
---|
27 | } |
---|
28 | |
---|
29 | function colorHex( $color ) { |
---|
30 | |
---|
31 | $my_color = imageColorAllocate( $this->$image, hexdec( substr( $color, 0, 2 )), hexdec( substr( $color, 2, 4 )), hexdec( substr( $color, 4, 6 ) ) ); |
---|
32 | |
---|
33 | return $my_color; |
---|
34 | } |
---|
35 | |
---|
36 | function drawNode( $x, $y, &$queuecolor, $load, &$jobcolor ) { |
---|
37 | |
---|
38 | // Convert Ganglia's Hexadecimal load color to a Decimal one |
---|
39 | $my_loadcolor = $this->colorHex( load_color($load) ); |
---|
40 | |
---|
41 | imageFilledRectangle( $this->$image, $x, $y, $x+12, $y+12, $queuecolor ); |
---|
42 | imageFilledRectangle( $this->$image, $x+2, $y+2, $x+10, $y+10, $my_loadcolor ); |
---|
43 | //imageFilledEllipse( $this->$image, ($x+9)/2, ($y+9)/2, 6, 6, $jobcolor ); |
---|
44 | } |
---|
45 | |
---|
46 | function drawImage() { |
---|
47 | |
---|
48 | $queue_color = imageColorAllocate( $this->$image, 0, 102, 304 ); |
---|
49 | $job_color = imageColorAllocate( $this->$image, 204, 204, 0 ); |
---|
50 | |
---|
51 | $this->drawNode( 1, 1, $queue_color, 0.1, $job_color ); |
---|
52 | header( "Content-type: image/png" ); |
---|
53 | imagePNG( $this->$image ); |
---|
54 | imageDestroy( $this->$image ); |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | $my_node = new NodeImg(); |
---|
59 | $my_node->drawImage(); |
---|
60 | |
---|
61 | ?> |
---|