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

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

web/addons/job_monarch/overview.php:

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