source: trunk/web/addons/toga/overview.php @ 115

Last change on this file since 115 was 115, checked in by bastiaans, 19 years ago

toga/conf.php, toga/libtoga.php:

  • Will now use a 'J' marking for all nodes with a running job Not depending on number of cpus in use anymore

toga/overview.php:

  • Fixed makeTime()
File size: 5.2 KB
RevLine 
[113]1<?php
[114]2
3$my_dir = getcwd();
4
5include_once "./libtoga.php";
6
7global $GANGLIA_PATH;
8chdir( $GANGLIA_PATH );
9include_once "./class.TemplatePower.inc.php";
10chdir( $my_dir );
11
12$httpvars = new HTTPVariables( $HTTP_GET_VARS );
13$clustername = $httpvars->getClusterName();
14
15$data_gatherer = new DataGatherer();
16
17$tpl = new TemplatePower("templates/overview.tpl");
18$tpl->prepare();
19
20$tpl->assign( "clusterimage", "./image.php?c=".$clustername."&view=big-clusterimage" );
21
22$data_gatherer->parseXML();
23$heartbeat = $data_gatherer->getHeartbeat();
24$jobs = $data_gatherer->getJobs();
25$nodes = $data_gatherer->getNodes();
26
27$tpl->assign("heartbeat", makeDate( $heartbeat ) );
28
29$pie = drawPie();
30$tpl->assign("pie", $pie );
31
32function makeTime( $time ) {
33
34        $days = intval( $time / 86400 );
[115]35        $time = $days ? $time % ($days * 86400) : $time;
36
[114]37        if( $days > 0 ) {
38                if( $days > 1 )
39                        $date_str .= $days . 'days - ';
40                else
41                        $date_str .= $days . 'day - ';
42        }
[115]43
[114]44        $hours = intval( $time / 3600 );
[115]45        $time = $hours ? $time % ($hours * 3600) : $time;
46
[114]47        if( $hours > 0 ) {
48                $date_str .= $hours . ':';
49                $date_unit = ' hours';
50        }
[115]51               
[114]52        $minutes = intval( $time / 60 );
[115]53        $seconds = $minutes ? $time % ($minutes * 60) : $time;
54
[114]55        if( $minutes > 0 ) {
[115]56
57                if( $minutes >= 10 )
58                        $date_str .= $minutes . ':';
59                else
60                        $date_str .= '0' . $minutes . ':';
61
[114]62                $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit;
[115]63        } else if( $days > 0 or $hours > 0 ) {
64                $date_str .= '00:';
65                $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit;
[114]66        }
[115]67
[114]68        $date_unit = (!isset($date_unit)) ? 'seconds' : $date_unit;
69
[115]70        if( $seconds > 0 ) {
71
72                if( $seconds >= 10 )
73                        $date_str .= $seconds . ' ' . $date_unit;
74                else
75                        $date_str .= '0' . $seconds . ' ' . $date_unit;
76                       
77        } else if ( $days > 0 or $hours > 0 or $minutes > 0 )
78                $date_str .= '00 ' . $date_unit;
79
[114]80        return $date_str;
81}
82
83function makeDate( $time ) {
84        return strftime( "%a %d %b %Y %H:%M:%S", $time );
85}
86
87function colorRed( $color ) {
88        return substr( $color, 0, 2 );
89}
90function colorGreen( $color ) {
91        return substr( $color, 2, 2 );
92}
93function colorBlue( $color ) {
94        return substr( $color, 4, 2 );
95}
96
97function colorDiffer( $first, $second ) {
98
99        // Make sure these two colors differ atleast 50 R/G/B
100        $min_diff = 50;
101
102        $c1r = decHex( colorRed( $first ) );
103        $c1g = decHex( colorGreen( $first ) );
104        $c1b = decHex( colorBlue( $first ) );
105
106        $c2r = decHex( colorRed( $second ) );
107        $c2g = decHex( colorGreen( $second ) );
108        $c2b = decHex( colorBlue( $second ) );
109
110        $rdiff = ($c1r >= $c2r) ? $c1r - $c2r : $c2r - $c1r;
111        $gdiff = ($c1g >= $c2g) ? $c1g - $c2g : $c2g - $c1g;
112        $bdiff = ($c1b >= $c2b) ? $c1b - $c2b : $c2b - $c1b;
113
114        if( $rdiff >= $min_diff or $gdiff >= $min_diff or $bdiff >= $min_diff )
115                return TRUE;
116        else
117                return FALSE;
118}
119
120function randomColor( $known_colors ) {
121
122        $start = hexdec( "004E00" );
123        $end = hexdec( "FFFFFF" );
124
125        if( count( $known_colors ) == 0 )
126                return dechex(rand( $start, $end ));
127
128        $color_changed = TRUE;
129
130        while( $color_changed ) {
131
132                $color_changed = FALSE;
133
134                foreach( $known_colors as $old ) {
135
136                        if( !isset( $new ) )
137                                $new = rand( $start, $end );
138
139                        if( !colorDiffer( dechex( $new ), $old ) )
140
141                                while( !colorDiffer( $new, $old ) ) {
142
143                                        $new = rand( $start, $end );
144                                        $color_changed = TRUE;
145                                }
146                }
147        }
148
149        // Whoa! Actually found a good color ;)
150        return dechex( $new );
151}
152
153function drawPie() {
154
155        global $jobs, $nodes;
156
157        $pie_args = "title=" . rawurlencode("Cluster Jobload");
158        $pie_args .= "&size=250x150";
159
160        $queues = array();
161        $nr_jobs = count( $jobs );
162        $nr_nodes = count( $nodes );
163
164        $emptynodes = 0;
165
166        foreach( $nodes as $node ) {
167
168                $myjobs = $node->getJobs();
169
170                if( count( $myjobs ) == 0 )
171                        $emptynodes++;
172                else
173                        $nodes_jobs = $nodes_jobs + count( $myjobs );
174        }
175
176        $empty_percentage = ($emptynodes / $nr_nodes) * 100;
177        $job_percentage = 100 - $empty_percentage; 
178
179        $color = randomColor( $qcolors );
180        $qcolors[] = $color;
181        $pie_args .= "&free=$empty_percentage,$color";
182
183        foreach( $jobs as $jobid => $jobattrs ) {
184
185                $qname = $jobattrs[queue];
186
187                if( !array_search( $qname, $queues ) ) {
188
189                        if( !isset( $queues[$qname] ) )
190                                $queues[$qname] = array();
191
192                        $queues[$qname][] = $jobid;
193                }
194        }
195
196        $qcolors = array();
197        foreach( $queues as $queue => $myjobs ) {
198
199                $qjobs = count ( $myjobs );
200                $percentage = ( $qjobs / $nr_jobs ) * $job_percentage;
201                $color = randomColor( $qcolors );
202                $qcolors[] = $color;
203                $pie_args .= "&$queue=$percentage,$color";
204        }
205        $pie = "../../pie.php?$pie_args";
206
207        return $pie;
208}
209
210foreach( $jobs as $jobid => $jobattrs ) {
211
212        $report_time = $jobattrs[reported];
213
214        if( $report_time == $heartbeat ) {
215
216                $tpl->newBlock("node");
217                $tpl->assign("id", $jobid );
218                $tpl->assign("state", $jobattrs[status] );
219                $tpl->assign("user", $jobattrs[owner] );
220                $tpl->assign("queue", $jobattrs[queue] );
221                $tpl->assign("name", $jobattrs[name] );
222                $nodes = count( $jobattrs[nodes] );
223                $ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1;
224                $cpus = $nodes * $ppn;
225                $tpl->assign("cpus", $cpus );
226                $tpl->assign("req_cpu", $jobattrs[requested_time] );
227                $tpl->assign("req_memory", $jobattrs[requested_memory] );
228                $tpl->assign("nodes", $nodes );
229                $start_time = (int) $jobattrs[start_timestamp];
230                $runningtime = makeTime( $report_time - $start_time );
231                $tpl->assign("started", makeDate( $start_time ) );
232                $tpl->assign("runningtime", $runningtime );
233        }
234}
235
236$tpl->printToScreen();
237
[113]238?>
Note: See TracBrowser for help on using the repository browser.