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

Last change on this file since 836 was 836, checked in by ramonb, 11 years ago

libtoga.php:

  • calculate parsetime

templates/footer.tpl:

  • made parsetime optional

index.php:

  • don't show parsetime for archive: not applicable

overview.php:

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