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

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

web/addons/job_monarch/version.php:

  • SVN version

web/addons/job_monarch/libtoga.php:

  • need $start in my graph.php

jobmond/jobmond.py:

  • added number of running and queued jobs metric reporting

web/addons/job_monarch/graph.php:

  • added 'job_report' graph, shows running and queued jobs

web/addons/job_monarch/overview.php:

  • included IMG to job_report graph

web/addons/job_monarch/index.php:

  • added range menu
  • fixed metric_menu selection now properly instantly refreshes graphs

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

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