source: trunk/web/addons/job_monarch/overview.php @ 326

Last change on this file since 326 was 326, checked in by bastiaans, 17 years ago

web/addons/job_monarch/overview.php:

  • make our own datasource
  • store the XML data in a session for the clusterimage
  • assign a image map of clickable nodes for the clusterimage

web/addons/job_monarch/templates/overview.tpl:

  • add node_clustermap imagemap block

web/addons/job_monarch/libtoga.php:

web/addons/job_monarch/image.php:

  • Property svn:keywords set to Id
File size: 21.6 KB
Line 
1<?php
2/*
3 *
4 * This file is part of Jobmonarch
5 *
6 * Copyright (C) 2006  Ramon Bastiaans
7 *
8 * Jobmonarch is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * Jobmonarch is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 *
22 * SVN $Id: overview.php 326 2007-04-21 14:22:47Z bastiaans $
23 */
24
25global $GANGLIA_PATH, $clustername, $tpl, $filter, $cluster, $get_metric_string, $cluster_url, $sh;
26global $hosts_up, $m, $start, $end, $filterorder, $COLUMN_REQUESTED_MEMORY, $COLUMN_QUEUED, $COLUMN_NODES, $hostname, $piefilter;
27
28$ds             = new DataSource();
29$myxml_data     = $ds->getData();
30
31$data_gatherer = new DataGatherer( $clustername );
32
33$tpl->assign( "clustername", $clustername );
34
35if( $JOB_ARCHIVE )
36        $tpl->assign( "cluster_url", rawurlencode($clustername) );
37
38$data_gatherer->parseXML( $myxml_data );
39
40$heartbeat = $data_gatherer->getHeartbeat();
41$jobs = $data_gatherer->getJobs();
42$gnodes = $data_gatherer->getNodes();
43$cpus = $data_gatherer->getCpus();
44
45function setupFilterSettings() {
46        global $tpl, $filter, $clustername, $piefilter, $data_gatherer, $myxml_data;
47
48        $filter_image_url = "";
49
50        $tpl->gotoBlock( "_ROOT" );
51
52        foreach( $filter as $filtername => $filtervalue ) {
53                $tpl->assign( "f_".$filtername, $filtervalue );
54                $filter_image_url .= "&$filtername=$filtervalue";
55        }
56
57        //include( "./ci_test.php" );
58        session_start();
59        //printf("data %s\n", strval( $myxml_data ) );
60        $_SESSION["data"] = &$myxml_data;
61
62        $ic = new ClusterImage( $myxml_data, $clustername );
63        $ic->setBig();
64        $ic->setNoimage();
65        $ic->draw();
66
67        //$tpl->assign( "clusterimage", "./image.php?c=".rawurlencode($clustername)."&view=big-clusterimage".$filter_image_url );
68        $tpl->assign( "clusterimage", "./image.php?". session_name() . "=" . session_id() ."&c=".rawurlencode($clustername)."&view=big-clusterimage".$filter_image_url );
69
70        $tpl->assign( "clusterimage_width", $ic->getWidth() );
71        $tpl->assign( "clusterimage_height", $ic->getHeight() );
72
73        $tpl->newBlock( "node_clustermap" );
74        $tpl->assign( "node_area_map", $ic->getImagemapArea() );
75        $tpl->gotoBlock( "_ROOT" );
76
77        $tpl->assign( "f_order", $filterorder );
78
79        if( array_key_exists( "id", $filter ) )
80                $piefilter = 'id';
81        else if( array_key_exists( "user", $filter ) )
82                $piefilter = 'user';
83        else if( array_key_exists( "queue", $filter ) )
84                $piefilter = 'queue';
85
86        $pie = drawPie();
87        $tpl->assign("pie", $pie );
88}
89
90function timeToEpoch( $time ) {
91
92        $time_fields = explode( ':', $time );
93
94        if( count($time_fields) == 3 ) {
95
96                $hours = $time_fields[0];
97                $minutes = $time_fields[1];
98                $seconds = $time_fields[2];
99
100        } else if( count($time_fields) == 2 ) {
101
102                $hours = 0;
103                $minutes = $time_fields[0];
104                $seconds = $time_fields[1];
105
106        } else if( count($time_fields) == 1 ) {
107
108                $hours = 0;
109                $minutes = 0;
110                $seconds = $time_fields[0];
111        }
112
113        $myepoch = intval( $seconds + (intval( $minutes * 60 )) + (intval( $hours * 3600 )) );
114
115        return $myepoch;
116}
117
118//function makeDate( $time ) {
119//      return strftime( "%a %d %b %Y %H:%M:%S", $time );
120//}
121
122function colorRed( $color ) {
123        return substr( $color, 0, 2 );
124}
125function colorGreen( $color ) {
126        return substr( $color, 2, 2 );
127}
128function colorBlue( $color ) {
129        return substr( $color, 4, 2 );
130}
131
132function colorDiffer( $first, $second ) {
133
134        // Make sure these two colors differ atleast 50 R/G/B
135        $min_diff = 50;
136
137        $c1r = hexDec( colorRed( $first ) );
138        $c1g = hexDec( colorGreen( $first ) );
139        $c1b = hexDec( colorBlue( $first ) );
140
141        $c2r = hexDec( colorRed( $second ) );
142        $c2g = hexDec( colorGreen( $second ) );
143        $c2b = hexDec( colorBlue( $second ) );
144
145        $rdiff = ($c1r >= $c2r) ? $c1r - $c2r : $c2r - $c1r;
146        $gdiff = ($c1g >= $c2g) ? $c1g - $c2g : $c2g - $c1g;
147        $bdiff = ($c1b >= $c2b) ? $c1b - $c2b : $c2b - $c1b;
148
149        if( $rdiff >= $min_diff or $gdiff >= $min_diff or $bdiff >= $min_diff )
150                return TRUE;
151        else
152                return FALSE;
153}
154
155function randomColor( $known_colors ) {
156
157        $start = "004E00";
158       
159        $start_red = colorRed( $start );
160        $start_green = colorGreen( $start );
161        $start_blue = colorBlue( $start );
162       
163        $end = "FFFFFF";
164
165        $end_red = colorRed( $end );
166        $end_green = colorGreen( $end );
167        $end_blue = colorBlue( $end );
168
169        $change_color = TRUE;
170
171        while( $change_color ) {
172
173                $change_color = FALSE;
174
175                $new_red = rand( hexDec( $start_red ), hexDec( $end_red ) );
176                $new_green = rand( hexDec( $start_green ), hexDec( $end_green ) );
177                $new_blue = rand( hexDec( $start_blue ), hexDec( $end_blue ) );
178
179                $new = decHex( $new_red ) . decHex( $new_green ) . decHex( $new_blue );
180
181                foreach( $known_colors as $old )
182
183                        if( !colorDiffer( $new, $old ) )
184
185                                $change_color = TRUE;
186        }
187
188        // Whoa! Actually found a good color ;)
189        return $new;
190}
191
192function drawJobPie() {
193}
194
195function drawUserPie() {
196
197}
198
199function drawQueuePie() {
200
201}
202
203
204function drawPie() {
205
206        global $jobs, $gnodes, $piefilter, $filter, $metrics;
207
208        $nodes          = $gnodes;
209
210        if( isset($piefilter) ) 
211                $pie_args       = "title=" . rawurlencode("Cluster ".$piefilter." usage");
212        else
213                $pie_args       = "title=" . rawurlencode("Cluster queue usage");
214               
215        $pie_args       .= "&size=250x150";
216
217        $queues         = array();
218        $nr_jobs        = count( $jobs );
219        $nr_nodes       = count( $nodes );
220
221        $nr_cpus        = cluster_sum("cpu_num", $metrics);
222
223        $empty_cpus     = 0;
224        $used_cpus      = 0;
225
226        $job_weight     = array();
227
228        foreach( $nodes as $node ) {
229
230                $myjobs         = $node->getJobs();
231                $myhost         = $node->getHostname();
232                $node_cpus      = $metrics[$myhost]["cpu_num"][VAL];
233                $job_cpu        = 0;
234
235                foreach( $myjobs as $myjob ) {
236
237                        $job_cpu        += (int) $jobs[$myjob][ppn] ? $jobs[$myjob][ppn] : 1;
238                }
239
240                $node_freecpu   = $node_cpus - $job_cpu;
241
242                $empty_cpus     += $node_freecpu;
243        }
244
245        $used_cpus              = $nr_cpus - $empty_cpus;
246
247        $empty_percentage       = ($empty_cpus / $nr_cpus) * 100;
248
249        $qcolors                = array();
250        $color                  = randomColor( $qcolors );
251        $qcolors[]              = $color;
252        $pie_args               .= "&free=$empty_percentage,$color";
253
254        if( isset( $piefilter ) )
255                $filterpie = array();
256
257        foreach( $nodes as $node ) {
258
259                $node_jobs      = $node->getJobs();
260                $nr_node_jobs   = count( $node_jobs );
261                $myhost         = $node->getHostname();
262                $node_cpus      = $metrics[$myhost]["cpu_num"][VAL];
263
264                foreach( $node_jobs as $myjob ) {
265
266                        $job_cpu                = (int) $jobs[$myjob][ppn] ? $jobs[$myjob][ppn] : 1;
267
268                        // Determine the weight of this job
269                        // - what percentage of the cpus is in use by this job
270                        //
271                        $job_weight[$myjob]     = ( $job_cpu / $nr_cpus );
272
273
274                        if( isset($piefilter) ) {
275                                $countjob = 1;
276                                if( $piefilter == 'id' ) {
277                                        if( $myjob != $filter[$piefilter] )
278                                                $countjob = 0;
279                                } else if( $piefilter == 'user' ) {
280                                        if( $jobs[$myjob][owner] != $filter[$piefilter] )
281                                                $countjob = 0;
282                                } else {
283                                        if( $jobs[$myjob][$piefilter] != $filter[$piefilter] )
284                                                $countjob = 0;
285                                }
286
287                                if( $countjob ) {
288
289                                        if( !isset( $filterpie[$filter[$piefilter]] ) )
290                                                $filterpie[$filter[$piefilter]] = $job_weight[$myjob];
291                                        else
292                                                $filterpie[$filter[$piefilter]] = $filterpie[$filter[$piefilter]] + $job_weight[$myjob];
293                                } else {
294                                        if( !isset( $filterpie["other"] ) )
295                                                $filterpie["other"] = $job_weight[$myjob];
296                                        else
297                                                $filterpie["other"] = $filterpie["other"] + $job_weight[$myjob];
298
299                                }
300                               
301                        } else {
302
303                                $qname          = $jobs[$myjob][queue];
304
305                                if( !isset( $queues[$qname] ) )
306                                        $queues[$qname] = $job_weight[$myjob];
307                                else
308                                        $queues[$qname] = $queues[$qname] + $job_weight[$myjob];
309                        }
310                }
311        }
312
313        if( isset( $piefilter ) )
314                $graphvals = $filterpie;
315        else
316                $graphvals = $queues;
317
318        foreach( $graphvals as $name => $totalweight) {
319
320                $percentage     = ( $totalweight * 100 );
321               
322                $color          = randomColor( $qcolors );
323                $qcolors[]      = $color;
324                $pie_args       .= "&$name=$percentage,$color";
325        }
326        $pie = "../../pie.php?$pie_args";
327
328        return $pie;
329}
330
331
332function sortJobs( $jobs, $sortby, $sortorder ) {
333
334        $sorted = array();
335
336        $cmp = create_function( '$a, $b', 
337                "global \$sortby, \$sortorder;".
338
339                "if( \$a == \$b ) return 0;".
340
341                "if (\$sortorder==\"desc\")".
342                        "return ( \$a < \$b ) ? 1 : -1;".
343                "else if (\$sortorder==\"asc\")".
344                        "return ( \$a > \$b ) ? 1 : -1;" );
345
346        if( isset( $jobs ) && count( $jobs ) > 0 ) {
347
348                foreach( $jobs as $jobid => $jobattrs ) {
349
350                                $state = $jobattrs[status];
351                                $user = $jobattrs[owner];
352                                $queue = $jobattrs[queue];
353                                $name = $jobattrs[name];
354                                $req_cpu = $jobattrs[requested_time];
355                                $req_memory = $jobattrs[requested_memory];
356
357                                if( $state == 'R' )
358                                        $nodes = count( $jobattrs[nodes] );
359                                else
360                                        $nodes = $jobattrs[nodes];
361
362                                $ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1;
363                                $cpus = $nodes * $ppn;
364                                $queued_time = (int) $jobattrs[queued_timestamp];
365                                $start_time = (int) $jobattrs[start_timestamp];
366                                $runningtime = $report_time - $start_time;
367
368                                switch( $sortby ) {
369                                        case "id":
370                                                $sorted[$jobid] = $jobid;
371                                                break;
372
373                                        case "state":
374                                                $sorted[$jobid] = $state;
375                                                break;
376
377                                        case "user":
378                                                $sorted[$jobid] = $user;
379                                                break;
380
381                                        case "queue":
382                                                $sorted[$jobid] = $queue;
383                                                break;
384
385                                        case "name":
386                                                $sorted[$jobid] = $name;
387                                                break;
388
389                                        case "req_cpu":
390                                                $sorted[$jobid] = timeToEpoch( $req_cpu );
391                                                break;
392
393                                        case "req_mem":
394                                                $sorted[$jobid] = $req_memory;
395                                                break;
396
397                                        case "nodes":
398                                                $sorted[$jobid] = $nodes;
399                                                break;
400
401                                        case "cpus":
402                                                $sorted[$jobid] = $cpus;
403                                                break;
404
405                                        case "queued":
406                                                $sorted[$jobid] = $queued_time;
407                                                break;
408
409                                        case "start":
410                                                $sorted[$jobid] = $start_time;
411                                                break;
412
413                                        case "runningtime":
414                                                $sorted[$jobid] = $runningtime;
415                                                break;
416
417                                        default:
418                                                break;
419
420                                }
421                }
422        }
423
424        //uasort( $sorted, $cmp );
425        if( $sortorder == "asc" )
426                arsort( $sorted );
427        else if( $sortorder == "desc" )
428                asort( $sorted );
429
430        return $sorted;
431}
432
433function makeOverview() {
434
435        global $jobs, $nodes, $heartbeat, $clustername, $tpl;
436        global $sortorder, $sortby, $filter, $sh, $hc, $m;
437        global $cluster_url, $get_metric_string, $host_url, $metrics;
438        global $start, $end, $reports, $gnodes, $default_showhosts;
439        global $COLUMN_QUEUED, $COLUMN_REQUESTED_MEMORY, $COLUMN_NODES, $hostname;
440        $metricname = $m;
441
442        $tpl->assign("sortorder", $sortorder );
443        $tpl->assign("sortby", $sortby );
444
445        $sorted_jobs = sortJobs( $jobs, $sortby, $sortorder );
446
447        $even = 1;
448
449        $used_jobs = 0;
450        $used_cpus = 0;
451        $used_nodes = 0;
452
453        $queued_jobs = 0;
454        $queued_nodes = 0;
455        $queued_cpus = 0;
456
457        $total_nodes = 0;
458        $total_cpus = 0;
459        $total_jobs = 0;
460
461        $all_used_nodes = array();
462        $total_used_nodes = array();
463
464        $running_name_nodes = array();
465
466        $running_nodes = 0;
467        $running_jobs = 0;
468        $running_cpus = 0;
469
470        $avail_nodes = count( $gnodes );
471        $avail_cpus = cluster_sum("cpu_num", $metrics);
472
473        $view_cpus = 0;
474        $view_jobs = 0;
475        $view_nodes = 0;
476
477        $all_nodes = 0;
478        $all_jobs = 0;
479        $all_cpus = 0;
480
481        $view_name_nodes = array();
482
483        if( $COLUMN_REQUESTED_MEMORY ) {
484                $tpl->newBlock( "column_header_req_mem" );
485        }
486
487        if( $COLUMN_NODES ) {
488                $tpl->newBlock( "column_header_nodes" );
489        }
490
491        if( $COLUMN_QUEUED ) {
492                $tpl->newBlock( "column_header_queued" );
493        }
494
495        $last_displayed_job = null;
496
497        foreach( $sorted_jobs as $jobid => $sortdec ) {
498
499                $report_time = $jobs[$jobid][reported];
500
501                if( $jobs[$jobid][status] == 'R' )
502                        $nodes = count( $jobs[$jobid][nodes] );
503                else if( $jobs[$jobid][status] == 'Q' )
504                        $nodes = $jobs[$jobid][nodes];
505
506                $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1;
507                $cpus = $nodes * $ppn;
508
509                if( $report_time == $heartbeat ) {
510
511                        $display_job = 1;
512
513                        if( $jobs[$jobid][status] == 'R' ) {
514                                foreach( $jobs[$jobid][nodes] as $tempnode ) {
515                                        $all_used_nodes[] = $tempnode;
516                                }
517                        }
518
519                        $used_cpus += $cpus;
520
521                        if( $jobs[$jobid][status] == 'R' ) {
522                                $running_cpus += $cpus;
523                                $running_jobs++;
524
525                                $found_node_job = 0;
526
527                                foreach( $jobs[$jobid][nodes] as $tempnode ) {
528                                        $running_name_nodes[] = $tempnode;
529
530                                        if( isset( $hostname ) && $hostname != '' ) {
531                                                //$filter[host] = $hostname;
532
533                                                $domain_len = 0 - strlen( $jobs[$jobid][domain] );
534                                                $hostnode = $tempnode;
535                                                if( substr( $hostnode, $domain_len ) != $jobs[$jobid][domain] ) {
536                                                        $hostnode = $hostnode. '.'. $jobs[$jobid][domain];
537                                                }
538
539                                                if( $hostname == $hostnode ) {
540                                                        $found_node_job = 1;
541                                                        $display_job = 1;
542                                                } else if( !$found_node_job ) {
543                                                        $display_job = 0;
544                                                }
545                                        }
546                                }
547                        }
548
549                        if( $jobs[$jobid][status] == 'Q' ) {
550                                if( isset( $hostname ) && $hostname != '' )
551                                        $display_job = 0;
552
553                                $queued_cpus += $cpus;
554                                $queued_nodes += $nodes;
555                                $queued_jobs++;
556                        }
557
558                        foreach( $filter as $filtername=>$filtervalue ) {
559
560                                if( $filtername == 'id' && $jobid != $filtervalue )
561                                        $display_job = 0;
562                                else if( $filtername == 'state' && $jobs[$jobid][status] != $filtervalue )
563                                        $display_job = 0;
564                                else if( $filtername == 'queue' && $jobs[$jobid][queue] != $filtervalue )
565                                        $display_job = 0;
566                                else if( $filtername == 'user' && $jobs[$jobid][owner] != $filtervalue )
567                                        $display_job = 0;
568                        }
569
570                        if( $display_job ) {
571
572                                $tpl->newBlock("node");
573                                $tpl->assign( "clustername", $clustername );
574                                $tpl->assign("id", $jobid );
575
576                                $last_displayed_job = $jobid;
577
578                                $tpl->assign("state", $jobs[$jobid][status] );
579
580                                $fullstate = '';
581                                if( $jobs[$jobid][status] == 'R' ) {
582                                        $fullstate = "Running";
583                                } else if( $jobs[$jobid][status] == 'Q' ) {
584                                        $fullstate = "Queued";
585                                }
586
587                                $tpl->assign("fullstate", $fullstate );
588                               
589                                $tpl->assign("user", $jobs[$jobid][owner] );
590                                $tpl->assign("queue", $jobs[$jobid][queue] );
591
592                                $fulljobname = $jobs[$jobid][name];
593                                $shortjobname = '';
594
595                                $tpl->assign("fulljobname", $fulljobname );
596
597                                $fulljobname_fields     = explode( ' ', $fulljobname );
598
599                                $capjobname     = 0;
600
601                                if( strlen( $fulljobname_fields[0] ) > 10 )
602                                        $capjobname     = 1;
603
604                                if( $capjobname ) {
605                                        $tpl->newBlock("jobname_hint_start");
606                                        $tpl->gotoBlock("node");
607
608                                        $shortjobname = substr( $fulljobname, 0, 10 ) . '..';
609                                } else {
610                                        $shortjobname = $fulljobname;
611                                }
612                               
613                                $tpl->assign("name", $shortjobname );
614
615                                if( $capjobname ) {
616                                        $tpl->newBlock("jobname_hint_end");
617                                        $tpl->gotoBlock("node");
618                                }
619
620                                $domain = $jobs[$jobid][domain];
621                                $tpl->assign("req_cpu", makeTime( timeToEpoch( $jobs[$jobid][requested_time] ) ) );
622
623                                if( $COLUMN_REQUESTED_MEMORY ) {
624                                        $tpl->newBlock( "column_req_mem" );
625                                        $tpl->assign( "req_memory", $jobs[$jobid][requested_memory] );
626                                        $tpl->gotoBlock( "node" );
627                                }
628
629
630                                if( $COLUMN_QUEUED ) {
631                                        $tpl->newBlock( "column_queued" );
632                                        $tpl->assign( "queued", makeDate( $jobs[$jobid][queued_timestamp] ) );
633                                        $tpl->gotoBlock( "node" );
634                                }
635                                if( $COLUMN_NODES ) {
636                                        $tpl->newBlock( "column_nodes" );
637                                        $tpl->gotoBlock( "node" );
638                                }
639
640                                $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1;
641                                $cpus = $nodes * $ppn;
642                                $tpl->assign("nodes", $nodes );
643                                $tpl->assign("cpus", $cpus );
644                                $start_time = (int) $jobs[$jobid][start_timestamp];
645                                $job_start = $start_time;
646
647                                $view_cpus += $cpus;
648                                $view_jobs++;
649
650                                if( $jobs[$jobid][status] == 'R' ) {
651                                        foreach( $jobs[$jobid][nodes] as $tempnode )
652                                                $view_name_nodes[] = $tempnode;
653
654                                        if( $COLUMN_NODES ) {
655                                                $tpl->gotoBlock( "column_nodes" );
656                                                $mynodehosts = array();
657                                                foreach( $jobs[$jobid][nodes] as $mynode ) {
658                                                        $myhost_href = "./?c=".$clustername."&h=".$mynode.".".$jobs[$jobid][domain];
659                                                        $mynodehosts[] = "<A HREF=\"".$myhost_href."\">".$mynode."</A>";
660                                                }
661                                                $nodes_hostnames = implode( " ", $mynodehosts );
662                                                $tpl->assign( "nodes_hostnames", $nodes_hostnames );
663                                                $tpl->gotoBlock( "node" );
664                                        }
665                                } else if( $jobs[$jobid][status] == 'Q' ) {
666                                        $view_nodes += (int) $jobs[$jobid][nodes];
667                                }
668
669                                if( $even ) {
670
671                                        $tpl->assign("nodeclass", "even");
672                                        $even = 0;
673                                } else {
674
675                                        $tpl->assign("nodeclass", "odd");
676                                        $even = 1;
677                                }
678
679                                if( $start_time ) {
680
681                                        $runningtime = makeTime( $report_time - $start_time );
682                                        $job_runningtime = $report_time - $start_time;
683                                        $tpl->assign("started", makeDate( $start_time ) );
684                                        $tpl->assign("runningtime", $runningtime );
685                                }
686                        }
687                }
688        }
689        $all_used_nodes = array_unique( $all_used_nodes );
690        $view_name_nodes = array_unique( $view_name_nodes );
691        $running_name_nodes = array_unique( $running_name_nodes );
692
693        $used_nodes = count( $all_used_nodes );
694        $view_nodes += count( $view_name_nodes );
695        $running_nodes += count( $running_name_nodes );
696
697        $total_nodes = $queued_nodes + $running_nodes;
698        $total_cpus = $queued_cpus + $running_cpus;
699        $total_jobs = $queued_jobs + $running_jobs;
700
701        $tpl->assignGlobal("avail_nodes", $avail_nodes );
702        $tpl->assignGlobal("avail_cpus", $avail_cpus );
703
704        $tpl->assignGlobal("queued_nodes", $queued_nodes );
705        $tpl->assignGlobal("queued_jobs", $queued_jobs );
706        $tpl->assignGlobal("queued_cpus", $queued_cpus );
707
708        $tpl->assignGlobal("total_nodes", $total_nodes );
709        $tpl->assignGlobal("total_jobs", $total_jobs );
710        $tpl->assignGlobal("total_cpus", $total_cpus );
711
712        $tpl->assignGlobal("running_nodes", $running_nodes );
713        $tpl->assignGlobal("running_jobs", $running_jobs );
714        $tpl->assignGlobal("running_cpus", $running_cpus );
715
716        $tpl->assignGlobal("used_nodes", $used_nodes );
717        $tpl->assignGlobal("used_jobs", $used_jobs );
718        $tpl->assignGlobal("used_cpus", $used_cpus );
719
720        $free_nodes = $avail_nodes - $running_nodes;
721        $free_cpus = $avail_cpus - $running_cpus;
722
723        $tpl->assignGlobal("free_nodes", $free_nodes );
724        $tpl->assignGlobal("free_cpus", $free_cpus );
725
726        $tpl->assignGlobal("view_nodes", $view_nodes );
727        $tpl->assignGlobal("view_jobs", $view_jobs );
728        $tpl->assignGlobal("view_cpus", $view_cpus );
729
730        $tpl->assignGlobal("report_time", makeDate( $heartbeat));
731
732        if( intval($view_jobs) == 1 and $start_time )
733                if( $last_displayed_job != null )
734                        $filter[id] = $last_displayed_job;
735
736        makeHeader( 'overview' );
737        setupFilterSettings();
738
739        if( intval($view_jobs) == 1 and $start_time ) {
740
741                $tpl->newBlock( "showhosts" );
742
743                # Present a width list
744                $cols_menu = "<SELECT NAME=\"hc\" OnChange=\"toga_form.submit();\">\n";
745
746
747                $hostcols = ($hc) ? $hc : 4;
748
749                foreach(range(1,25) as $cols) {
750                        $cols_menu .= "<OPTION VALUE=$cols ";
751                        if ($cols == $hostcols)
752                                $cols_menu .= "SELECTED";
753                        $cols_menu .= ">$cols\n";
754                }
755                $cols_menu .= "</SELECT>\n";
756
757                //$tpl->assign("cluster", $clustername);
758                $tpl->assign("metric","$metricname $units");
759                $tpl->assign("id", $filter[id]);
760                # Host columns menu defined in header.php
761                $tpl->assign("cols_menu", $cols_menu);
762
763                $showhosts = isset($sh) ? $sh : $default_showhosts;
764                //if( !$showhosts) $showhosts = $default_showhosts;
765                $tpl->assign("checked$showhosts", "checked");
766
767                if( $showhosts ) {
768                        //-----
769
770                        if( !isset($start) ) $start="jobstart";
771                        if( !isset($stop) ) $stop="now";
772                        //$tpl->assign("start", $start);
773                        //$tpl->assign("stop", $stop);
774
775                        $sorted_hosts = array();
776                        $hosts_up = $jobs[$filter[id]][nodes];
777
778                        $r = intval($job_runningtime * 1.25);
779
780                        $jobrange = ($job_runningtime < 3600) ? -3600 : -$r ;
781                        $jobstart = $report_time - $job_runningtime;
782
783                        if ($reports[$metricname])
784                                $metricval = "g";
785                        else
786                                $metricval = "m";
787                               
788                        foreach ($hosts_up as $host ) {
789
790                                $domain_len = 0 - strlen( $domain );
791                                if( substr( $host, $domain_len ) != $domain ) {
792                                        $host = $host. '.'.$domain;
793                                }
794                                $cpus = $metrics[$host]["cpu_num"][VAL];
795                                if (!$cpus) $cpus=1;
796                                $load_one  = $metrics[$host]["load_one"][VAL];
797                                $load = ((float) $load_one)/$cpus;
798                                $host_load[$host] = $load;
799                                $percent_hosts[load_color($load)] += 1;
800                                if ($metricname=="load_one")
801                                        $sorted_hosts[$host] = $load;
802                                else
803                                        $sorted_hosts[$host] = $metrics[$host][$metricname][VAL];
804                        }
805                        switch ($sort) {
806                                case "descending":
807                                        arsort($sorted_hosts);
808                                        break;
809                                case "by hostname":
810                                        ksort($sorted_hosts);
811                                        break;
812                                default:
813                                case "ascending":
814                                        asort($sorted_hosts);
815                                        break;
816                        }
817
818                        //$sorted_hosts = array_merge($down_hosts, $sorted_hosts);
819
820                        # First pass to find the max value in all graphs for this
821                        # metric. The $start,$end variables comes from get_context.php,
822                        # included in index.php.
823                        list($min, $max) = find_limits($sorted_hosts, $metricname);
824
825                        # Second pass to output the graphs or metrics.
826                        $i = 1;
827                        foreach ( $sorted_hosts as $host=>$value  ) {
828                                $tpl->newBlock ("sorted_list");
829                                //$host = $host. '.'.$domain;
830                                $host_url = rawurlencode($host);
831                                $cluster_url = rawurlencode($clustername);
832
833                                $textval = "";
834                                //printf("host = %s, value = %s", $host, $value);
835                                //echo "$host: $value, ";
836                                $val = $metrics[$host][$metricname];
837                                $class = "metric";
838                                $host_link="\"../../?c=$cluster_url&h=$host_url&r=job&jr=$jobrange&js=$jobstart\"";
839
840                                if ($val[TYPE]=="timestamp" or $always_timestamp[$metricname]) {
841                                        $textval = date("r", $val[VAL]);
842                                } elseif ($val[TYPE]=="string" or $val[SLOPE]=="zero" or $always_constant[$metricname] or ($max_graphs > 0 and $i > $max_graphs )) {
843                                        $textval = "$val[VAL] $val[UNITS]";
844                                } else {
845                                        $load_color = load_color($host_load[$host]);
846                                        $graphargs = ($reports[$metricname]) ? "g=$metricname&" : "m=$metricname&";
847                                        $graphargs .= "z=small&c=$cluster_url&h=$host_url&l=$load_color" ."&v=$val[VAL]&r=job&jr=$jobrange&js=$jobstart";
848                                        if( $max > 0 ) {
849
850                                                $graphargs .= "&x=$max&n=$min";
851                                        }
852                                }
853                                if ($textval) {
854                                        $cell="<td class=$class>".  "<b><a href=$host_link>$host</a></b><br>".  "<i>$metricname:</i> <b>$textval</b></td>";
855                                } else {
856                                        $cell="<td><a href=$host_link>".  "<img src=\"../../graph.php?$graphargs\" ".  "alt=\"$host\" border=0></a></td>";
857                                }
858
859                                $tpl->assign("metric_image", $cell);
860                                if (! ($i++ % $hostcols) )
861                                         $tpl->assign ("br", "</tr><tr>");
862                        }
863                }
864//---
865        }
866}
867?>
Note: See TracBrowser for help on using the repository browser.