source: branches/1.0/web/addons/job_monarch/overview.php

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