source: branches/1.1/web/addons/job_monarch/overview.php @ 932

Last change on this file since 932 was 932, checked in by sil, 10 years ago

Removed deprecated compare-function for array-sorting.

  • Property svn:keywords set to Id
File size: 27.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 932 2013-08-06 12:48:14Z sil $
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    if( isset( $jobs ) && count( $jobs ) > 0 ) 
214    {
215        foreach( $jobs as $jobid => $jobattrs ) 
216        {
217                $state     = $jobattrs['status'];
218                $owner     = $jobattrs['owner'];
219                $queue     = $jobattrs['queue'];
220                $name      = $jobattrs['name'];
221                $req_cpu   = $jobattrs['requested_time'];
222                $req_memory= $jobattrs['requested_memory'];
223
224                if( $state == 'R' )
225                {
226                    $nodes = count( $jobattrs['nodes'] );
227                }
228                else
229                {
230                    $nodes = $jobattrs['nodes'];
231                }
232
233                $ppn         = (int) $jobattrs['ppn'] ? $jobattrs['ppn'] : 1;
234                $cpus        = $nodes * $ppn;
235                $queued_time = (int) $jobattrs['queued_timestamp'];
236                $start_time  = (int) $jobattrs['start_timestamp'];
237                $runningtime = $report_time - $start_time;
238
239                switch( $sortby ) 
240                {
241                    case "id":
242                        $sorted[$jobid] = $jobid;
243                        break;
244
245                    case "state":
246                        $sorted[$jobid] = $state;
247                        break;
248
249                    case "owner":
250                        $sorted[$jobid] = $owner;
251                        break;
252
253                    case "queue":
254                        $sorted[$jobid] = $queue;
255                        break;
256
257                    case "name":
258                        $sorted[$jobid] = $name;
259                        break;
260
261                    case "req_cpu":
262                        $sorted[$jobid] = timeToEpoch( $req_cpu );
263                        break;
264
265                    case "req_mem":
266                        $sorted[$jobid] = $req_memory;
267                        break;
268
269                    case "nodes":
270                        $sorted[$jobid] = $nodes;
271                        break;
272
273                    case "cpus":
274                        $sorted[$jobid] = $cpus;
275                        break;
276
277                    case "queued":
278                        $sorted[$jobid] = $queued_time;
279                        break;
280
281                    case "start":
282                        $sorted[$jobid] = $start_time;
283                        break;
284
285                    case "runningtime":
286                        $sorted[$jobid] = $runningtime;
287                        break;
288
289                    default:
290                        break;
291                }
292        }
293    }
294
295    if( $sortorder == "asc" )
296    {
297        asort( $sorted );
298    }
299    else if( $sortorder == "desc" )
300    {
301        arsort( $sorted );
302    }
303
304    return $sorted;
305}
306
307function makeOverview() 
308{
309    global $dwoo, $tpl, $tpl_data, $jobs, $nodes, $heartbeat, $clustername, $tpl_data;
310    global $sortorder, $sortby, $filter, $sh, $hc, $m, $range;
311    global $cluster_url, $get_metric_string, $host_url, $metrics;
312    global $start, $end, $reports, $gnodes, $default_showhosts;
313    global $COLUMN_QUEUED, $COLUMN_REQUESTED_MEMORY, $COLUMN_NODES, $hostname;
314    global $cluster, $use_fqdn, $myxml_data, $data_gatherer;
315
316    $metricname        = $m;
317    if( isset($conf['default_metric']) and ($metricname =='') )
318        $metricname = $conf['default_metric'];
319    else
320        if( isset( $m ) )
321            $metricname = $m;
322        else
323            $metricname = "load_one";
324
325    $tpl_data["sortorder"]= $sortorder;
326    $tpl_data["sortby"]= $sortby;
327
328    $sorted_jobs        = sortJobs( $jobs, $sortby, $sortorder );
329
330    $even               = 1;
331
332    $used_jobs          = 0;
333    $used_cpus          = 0;
334    $used_nodes         = 0;
335
336    $queued_jobs        = 0;
337    $queued_nodes       = 0;
338    $queued_cpus        = 0;
339
340    $total_nodes        = 0;
341    $total_cpus         = 0;
342    $total_jobs         = 0;
343
344    $all_used_nodes     = array();
345    $total_used_nodes   = array();
346
347    $running_name_nodes = array();
348
349    $running_nodes      = 0;
350    $running_jobs       = 0;
351    $running_cpus       = 0;
352
353    $avail_nodes        = count( $gnodes );
354    $avail_cpus         = cluster_sum("cpu_num", $metrics);
355
356    $view_cpus          = 0;
357    $view_jobs          = 0;
358    $view_nodes         = 0;
359
360    $all_nodes          = 0;
361    $all_jobs           = 0;
362    $all_cpus           = 0;
363
364    $view_name_nodes    = array();
365
366    // Is the "requested memory" column enabled in the config
367    //
368    if( $COLUMN_REQUESTED_MEMORY ) 
369    {
370        $tpl_data[ "column_header_req_mem"]= "yes";
371    }
372
373    // Is the "nodes hostnames" column enabled in the config
374    //
375    if( $COLUMN_NODES ) 
376    {
377        $tpl_data[ "column_header_nodes"]= "yes";
378    }
379
380    // Is the "queued time" column enabled in the config
381    //
382    if( $COLUMN_QUEUED ) 
383    {
384        $tpl_data[ "column_header_queued"]= "yes" ;
385    }
386
387    $last_displayed_job = null;
388
389    $rjqj_host = null;
390
391    $na_nodes  = 0;
392    $na_cpus   = 0;
393
394    foreach( $metrics as $bhost => $bmetric )
395    {
396        foreach( $bmetric as $mname => $mval )
397        {
398            if( ( $mname == 'zplugin_monarch_rj' ) || ($mname == 'zplugin_monarch_qj') )
399            {
400                $rjqj_host = $bhost;
401            }
402        }
403    }
404
405    foreach( $gnodes as $ghost => $gnode )
406    {
407        if( $gnode->isDown() || $gnode->isOffline() )
408        {
409            $na_nodes += 1;
410            $na_cpus  += $metrics[$ghost]['cpu_num']['VAL'];
411        }
412    }
413
414    $node_list = array();
415
416    foreach( $sorted_jobs as $jobid => $sortdec ) 
417    {
418        $report_time     = $jobs[$jobid]['reported'];
419
420        if( $jobs[$jobid]['status'] == 'R' )
421        {
422            $nodes = count( $jobs[$jobid]['nodes'] );
423        }
424        else if( $jobs[$jobid]['status'] == 'Q' )
425        {
426            $nodes = $jobs[$jobid]['nodes'];
427        }
428
429        $ppn  = isset( $jobs[$jobid]['ppn'] ) ? $jobs[$jobid]['ppn'] : 1;
430        $cpus = $nodes * $ppn;
431
432        if( $report_time == $heartbeat ) 
433        {
434            $display_job    = 1;
435
436            if( $jobs[$jobid]['status'] == 'R' ) 
437            {
438                foreach( $jobs[$jobid]['nodes'] as $tempnode ) 
439                {
440                    $all_used_nodes[] = $tempnode;
441                }
442            }
443
444            $used_cpus += $cpus;
445
446            if( $jobs[$jobid]['status'] == 'R' ) 
447            {
448                $running_cpus     += $cpus;
449
450                $running_jobs++;
451
452                $found_node_job    = 0;
453
454                foreach( $jobs[$jobid]['nodes'] as $tempnode ) 
455                {
456                    $running_name_nodes[] = $tempnode;
457
458                    $hostnode = $data_gatherer->makeHostname( $tempnode, $jobs[$jobid]['domain'] );
459
460                    if( isset( $hostname ) && $hostname != '' ) 
461                    {
462                        if( $hostname == $hostnode ) 
463                        {
464                            $found_node_job = 1;
465                            $display_job = 1;
466                        } 
467                        else if( !$found_node_job ) 
468                        {
469                            $display_job = 0;
470                        }
471                    }
472                }
473            }
474
475            if( $jobs[$jobid]['status'] == 'Q' ) 
476            {
477                if( isset( $hostname ) && $hostname != '' )
478                {
479                    $display_job = 0;
480                }
481
482                $queued_cpus  += $cpus;
483                $queued_nodes += $nodes;
484
485                $queued_jobs++;
486            }
487
488            foreach( $filter as $filtername=>$filtervalue ) 
489            {
490                if( $filtername == 'id' && $jobid != $filtervalue )
491                {
492                    $display_job = 0;
493                }
494                else if( $filtername == 'state' && $jobs[$jobid]['status'] != $filtervalue )
495                {
496                    $display_job = 0;
497                }
498                else if( $filtername == 'queue' && $jobs[$jobid]['queue'] != $filtervalue )
499                {
500                    $display_job = 0;
501                }
502                else if( $filtername == 'owner' && $jobs[$jobid]['owner'] != $filtervalue )
503                {
504                    $display_job = 0;
505                }
506            }
507
508
509            if( $display_job ) 
510            {
511                unset( $job_loop );
512                $job_loop = array();
513                $job_loop["clustername"] = $clustername;
514
515                $job_loop["id"] = $jobid;
516
517                $last_displayed_job     = $jobid;
518
519                $job_loop["state"] = $jobs[$jobid]['status'];
520
521                $fullstate         = '';
522
523                if( $jobs[$jobid]['status'] == 'R' ) 
524                {
525                    $fullstate     = "Running";
526                } 
527                else if( $jobs[$jobid]['status'] == 'Q' ) 
528                {
529                    $fullstate     = "Queued";
530                }
531
532                $job_loop["fullstate"] = $fullstate;
533               
534                $job_loop["owner"] = $jobs[$jobid]['owner'];
535                $job_loop["queue"] = $jobs[$jobid]['queue'];
536
537                $fulljobname         = $jobs[$jobid]['name'];
538                $shortjobname        = '';
539
540                $job_loop["fulljobname"] = $fulljobname;
541
542                $fulljobname_fields    = explode( ' ', $fulljobname );
543
544                $capjobname        = 0;
545
546                if( strlen( $fulljobname_fields[0] ) > 10 )
547                {
548                    $capjobname    = 1;
549                }
550
551                if( $capjobname ) 
552                {
553                    $job_loop[ "jobname_hint_start" ] = "yes";
554
555                    $shortjobname     = substr( $fulljobname, 0, 10 ) . '..';
556                } 
557                else 
558                {
559                    $shortjobname     = $fulljobname;
560                }
561               
562                $job_loop["name"] = $shortjobname;
563
564                if( $capjobname ) 
565                {
566                    $job_loop[ "jobname_hint_end" ] = "yes";
567                }
568
569                $domain         = $jobs[$jobid]['domain'];
570
571                $job_loop["req_cpu"] = makeTime( timeToEpoch( $jobs[$jobid]['requested_time'] ) );
572
573                if( $COLUMN_REQUESTED_MEMORY ) 
574                {
575                    $job_loop[ "column_req_mem" ] = "yes";
576                    $job_loop["req_memory"] = $jobs[$jobid]['requested_memory'];
577                }
578
579
580                if( $COLUMN_QUEUED ) 
581                {
582                    $job_loop[ "column_queued" ] = "yes";
583                    $job_loop["queued"] = makeDate( $jobs[$jobid]['queued_timestamp'] );
584                }
585                if( $COLUMN_NODES ) 
586                {
587                    $job_loop[ "column_nodes" ] = "yes";
588                    //echo "colum nodes";
589                }
590
591                $ppn       = isset( $jobs[$jobid]['ppn'] ) ? $jobs[$jobid]['ppn'] : 1;
592                $cpus      = $nodes * $ppn;
593
594                $job_loop["nodes"] = $nodes;
595                $job_loop["cpus"] = $cpus;
596
597                $start_time= (int) $jobs[$jobid]['start_timestamp'];
598                $job_start = $start_time;
599
600
601                $view_cpus += $cpus;
602
603                $view_jobs++;
604
605                if( $jobs[$jobid]['status'] == 'R' ) 
606                {
607                    $job_runningtime    = $heartbeat - $start_time;
608                    if( $rjqj_start == null ) 
609                    {
610                        $rjqj_start = intval( $start_time - (intval( $job_runningtime * 0.10 ) ) );
611                    }
612                    else if( $start_time < $rjqj_start )
613                    {
614                        $rjqj_start = intval( $start_time - (intval( $job_runningtime * 0.10 ) ) );
615                    }
616
617                    foreach( $jobs[$jobid]['nodes'] as $tempnode )
618                    {
619                        $view_name_nodes[]     = $tempnode;
620                    }
621
622                    if( $COLUMN_NODES ) 
623                    {
624                        $job_loop[ "column_nodes" ] = "yes";
625
626                        $mynodehosts         = array();
627
628                        foreach( $jobs[$jobid]['nodes'] as $shortnode ) 
629                        {
630                            $domain         = $jobs[$jobid]['domain'];
631                            $mynode         = $data_gatherer->makeHostname( $shortnode, $domain );
632                            $myhost_href    = "./?c=".$clustername."&h=".$mynode;
633                            $mynodehosts[]  = "<A HREF=\"".$myhost_href."\">".$shortnode."</A>";
634                        }
635
636                        $nodes_hostnames    = implode( " ", $mynodehosts );
637
638                        $job_loop["nodes_hostnames"] = $nodes_hostnames;
639                    }
640                } 
641                else if( $jobs[$jobid]['status'] == 'Q' ) 
642                {
643                    $view_nodes     += (int) $jobs[$jobid]['nodes'];
644                }
645
646                if( $even ) 
647                {
648                    $job_loop["nodeclass"] = "even";
649
650                    $even         = 0;
651                } 
652                else 
653                {
654                    $job_loop["nodeclass"] = "odd";
655
656                    $even         = 1;
657                }
658
659                if( $start_time ) 
660                {
661                    $runningtime        = makeTime( $report_time - $start_time );
662                    $job_runningtime    = $heartbeat - $start_time;
663
664                    $job_loop["started"] = makeDate( $start_time );
665                    $job_loop["runningtime"] = $runningtime;
666                }
667                $node_list[] = &$job_loop;
668            }
669            $tpl_data["node_list"]= &$node_list ;
670        }
671    }
672    if( intval($view_jobs) == 1 and $start_time )
673    {
674        if( $last_displayed_job != null )
675        {
676            $filter['id'] = $last_displayed_job;
677        }
678    }
679    // Running / queued amount jobs graph
680    //
681    if( $rjqj_host != null )
682    {
683        $rjqj_graphargs = "?z=overview-medium&c=$clustername&h=$rjqj_host&g=job_report&r=$range";
684        if( $range == 'job' )
685        {
686            $rjqj_end = time();
687
688            if( $rjqj_start == null ) 
689            { // probably no running jobs in this view: only queued
690                $rjqj_start = $rjqj_end - (24 * 3600); // default to 1 day
691            }
692            $rjqj_title = rawurlencode( makeTime( ($rjqj_end - $rjqj_start) ) );
693            $rjqj_graphargs .= "&period_start=$rjqj_start&period_stop=$rjqj_end&t=$rjqj_title";
694        }
695        else
696        {
697            $rjqj_graphargs .= "&st=$cluster[LOCALTIME]";
698        }
699        if( intval($view_jobs) == 1 and $start_time )
700        {
701            $job_start     = $jobs[$last_displayed_job]['start_timestamp'];
702            $rjqj_graphargs .= "&job_start=$start_time";
703        }
704
705        $rjqj_str  = "<A HREF=\"./graph.php$rjqj_graphargs\">";
706        $rjqj_str .= "<IMG BORDER=0 SRC=\"./graph.php$rjqj_graphargs\">";
707        $rjqj_str .= "</A>";
708
709        $tpl_data[ "rjqj_graph"]= $rjqj_str ;
710    }
711
712    $all_used_nodes     = array_unique( $all_used_nodes );
713    $view_name_nodes    = array_unique( $view_name_nodes );
714    $running_name_nodes = array_unique( $running_name_nodes );
715
716    $used_nodes         = count( $all_used_nodes );
717    $view_nodes        += count( $view_name_nodes );
718    $running_nodes     += count( $running_name_nodes );
719
720    $total_nodes        = $queued_nodes + $running_nodes;
721    $total_cpus         = $queued_cpus + $running_cpus;
722    $total_jobs         = $queued_jobs + $running_jobs;
723
724    $free_nodes         = $avail_nodes - $running_nodes - $na_nodes;
725    $free_nodes         = ( $free_nodes >= 0 ) ? $free_nodes : 0;
726    $free_cpus          = $avail_cpus - $running_cpus - $na_cpus;
727    $free_cpus          = ( $free_cpus >= 0 ) ? $free_cpus : 0;
728
729    $tpl_data[ "avail_nodes"]= $avail_nodes ;
730    $tpl_data[ "avail_cpus"]= $avail_cpus ;
731
732    $tpl_data[ "queued_nodes"]= $queued_nodes ;
733    $tpl_data[ "queued_jobs"]= $queued_jobs ;
734    $tpl_data[ "queued_cpus"]= $queued_cpus ;
735
736    // Only display "Unavailable" in count overview there are any
737    //
738    if( $na_nodes > 0 )
739    {
740        $tpl_data[ "show_na_nodes"]= "yes";
741
742        $tpl_data[ "na_nodes"]= $na_nodes ;
743        $tpl_data[ "na_cpus"]= $na_cpus ;
744    }
745
746    $tpl_data[ "total_nodes"]= $total_nodes ;
747    $tpl_data[ "total_jobs"]= $total_jobs ;
748    $tpl_data[ "total_cpus"]= $total_cpus ;
749
750    $tpl_data[ "running_nodes"]= $running_nodes ;
751    $tpl_data[ "running_jobs"]= $running_jobs ;
752    $tpl_data[ "running_cpus"]= $running_cpus ;
753
754    $tpl_data[ "used_nodes"]= $used_nodes ;
755    $tpl_data[ "used_jobs"]= $used_jobs ;
756    $tpl_data[ "used_cpus"]= $used_cpus ;
757
758    $tpl_data[ "free_nodes"]= $free_nodes ;
759    $tpl_data[ "free_cpus"]= $free_cpus ;
760
761    $tpl_data[ "view_nodes"]= $view_nodes ;
762    $tpl_data[ "view_jobs"]= $view_jobs ;
763    $tpl_data[ "view_cpus"]= $view_cpus ;
764
765    $tpl_data[ "report_time"]= makeDate( $heartbeat);
766
767
768    global $longtitle, $title;
769
770    $longtitle = "Batch Report :: Powered by Job Monarch!";
771    $title = "Batch Report";
772
773    makeHeader( 'overview', $title, $longtitle );
774
775    setupFilterSettings();
776
777    if( intval($view_jobs) == 1 and $start_time )
778    {
779        $tpl_data[ "showhosts"]= "yes" ;
780
781        $showhosts     = isset($sh) ? $sh : $default_showhosts;
782
783        $tpl_data[ "checked$showhosts"]= "checked" ;
784
785        $sorted_list = array();
786
787        if( $showhosts )
788        {
789            if( !isset( $start ) )
790            {
791                $start    ="jobstart";
792            }
793            if( !isset( $stop ) )
794            {
795                $stop    ="now";
796            }
797
798            $sorted_hosts = array();
799            $hosts_up     = $jobs[$filter['id']]['nodes'];
800
801            $r            = intval($job_runningtime * 1.2);
802
803            $jobrange     = -$r ;
804            $jobstart     = $start_time;
805
806            if ( $reports[$metricname] )
807            {
808                $metricval     = "g";
809            }
810            else
811            {
812                $metricval    = "m";
813            }
814               
815            foreach ( $hosts_up as $host )
816            {
817                $host             = $data_gatherer->makeHostname( $host, $domain );
818
819                $cpus             = 0;
820
821                $cpus             = $metrics[$host]["cpu_num"]["VAL"];
822
823                if( $cpus == 0 )
824                {
825                    $cpus        = 1;
826                }
827
828                $load_one         = $metrics[$host]["load_one"]['VAL'];
829                $load             = ((float) $load_one) / $cpus;
830                $host_load[$host] = $load;
831
832                $percent_hosts[load_color($load)] ++;
833
834                if ($metricname=="load_one")
835                {
836                    $sorted_hosts[$host]     = $load;
837                }
838                else
839                {
840                    $sorted_hosts[$host]     = $metrics[$host][$metricname]['VAL'];
841                }
842            }
843
844            switch ( $sort )
845            {
846                case "descending":
847                    arsort( $sorted_hosts );
848                    break;
849
850                case "by hostname":
851                    ksort( $sorted_hosts );
852                    break;
853
854                case "ascending":
855                    asort( $sorted_hosts );
856                    break;
857
858                default:
859                    break;
860            }
861
862            // First pass to find the max value in all graphs for this
863            // metric. The $start,$end variables comes from get_context.php,
864            // included in index.php.
865            //
866            list($min, $max) = find_limits($sorted_hosts, $metricname);
867
868            // Second pass to output the graphs or metrics.
869            $i = 1;
870
871            $metric_loop = array();
872            foreach ( $sorted_hosts as $host=>$value  )
873            {
874                $host_url    = rawurlencode( $host );
875                $cluster_url = rawurlencode( $clustername );
876
877                $textval     = "";
878
879                $val         = $metrics[$host][$metricname];
880                $class       = "metric";
881
882                if ( $val["TYPE"] == "timestamp" || $always_timestamp[$metricname] )
883                {
884                    $textval     = date( "r", $val["VAL"] );
885                }
886                elseif ( $val["TYPE"] == "string" || $val["SLOPE"] == "zero" || $always_constant[$metricname] || ($max_graphs > 0 and $i > $max_graphs ))
887                {
888                    $textval     = $val["VAL"] . " " . $val["UNITS"];
889                }
890                else
891                {
892                    $job_start     = $jobs[$last_displayed_job]['start_timestamp'];
893                    $period_end    = $cluster['LOCALTIME'];
894                    $runningtime   = intval( $period_end ) - intval( $job_start );
895                    $load_color    = load_color($host_load[$host]);
896                    $period_start  = intval( $job_start - (intval( $runningtime * 0.10 ) ) );
897                    //printf("last job %s job start %s runningtime %s period start %s", $last_displayed_job, $jobstart, $job_runningtime, $period_start);
898                    $graphargs     = ($reports[$metricname]) ? "g=$metricname&" : "m=$metricname&";
899                    $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'];
900                    $host_link     = "?j_view=overview-host&c=$cluster_url&r=$range&h=$host_url&job_start=$jobstart";
901
902                    if( $range == 'job' )
903                    {
904                        $graphargs     .= "&period_start=$period_start&period_stop=$period_end";
905                        $host_link     .= "&period_start=$period_start&period_stop=$period_end";
906                    }
907                    else
908                    {
909                        $graphargs     .= "&st=$period_end";
910                        $host_link     .= "&st=$period_end";
911                    }
912                    if( $max > 0 )
913                    {
914                        $graphargs    .= "&x=$max&n=$min";
915                    }
916                }
917                if ($textval)
918                {
919                    $cell    = "<td class=$class>".  "<b><a href=$host_link>$host</a></b><br>".  "<i>$metricname:</i> <b>$textval</b></td>";
920                } else {
921                    $cell    = "<A HREF=\"$host_link\">" . "<IMG SRC=\"./graph.php?$graphargs\" " . "ALT=\"$host\" BORDER=0></A>";
922                }
923
924                $metric_loop["metric_image"] = $cell;
925
926                //if(! ($i++ % $hostcols) )
927                //{
928                //     $metric_loop["br"] = "</tr><tr>";
929                //}
930                $sorted_list[] = $metric_loop;
931            }
932            $tpl_data["sorted_list"]= $sorted_list ;
933        }
934    }
935    $dwoo->output($tpl, $tpl_data);
936}
937
938?>
Note: See TracBrowser for help on using the repository browser.