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

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

web/addons/job_monarch/overview.php:

  • fixed: forgot nodes column block for queued jobs
  • Property svn:keywords set to Id
File size: 20.9 KB
Line 
1<?php
2/*
3 *
4 * This file is part of Jobmonarch
5 *
6 * Copyright (C) 2006  Ramon Bastiaans
7 *
8 * Jobmonarch is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * Jobmonarch is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 *
22 * SVN $Id: overview.php 322 2007-04-19 09:43:32Z bastiaans $
23 */
24
25global $GANGLIA_PATH, $clustername, $tpl, $filter, $cluster, $get_metric_string, $cluster_url, $sh;
26global $hosts_up, $m, $start, $end, $filterorder, $COLUMN_REQUESTED_MEMORY, $COLUMN_QUEUED, $COLUMN_NODES, $hostname, $piefilter;
27
28$data_gatherer = new DataGatherer( $clustername );
29
30$tpl->assign( "clustername", $clustername );
31
32if( $JOB_ARCHIVE )
33        $tpl->assign( "cluster_url", rawurlencode($clustername) );
34
35$data_gatherer->parseXML();
36
37$heartbeat = $data_gatherer->getHeartbeat();
38$jobs = $data_gatherer->getJobs();
39$gnodes = $data_gatherer->getNodes();
40$cpus = $data_gatherer->getCpus();
41
42function setupFilterSettings() {
43        global $tpl, $filter, $clustername, $piefilter;
44
45        $filter_image_url = "";
46
47        $tpl->gotoBlock( "_ROOT" );
48
49        foreach( $filter as $filtername => $filtervalue ) {
50                $tpl->assign( "f_".$filtername, $filtervalue );
51                $filter_image_url .= "&$filtername=$filtervalue";
52        }
53
54        $tpl->assign( "clusterimage", "./image.php?c=".rawurlencode($clustername)."&view=big-clusterimage".$filter_image_url );
55        $tpl->assign( "f_order", $filterorder );
56
57        if( array_key_exists( "id", $filter ) )
58                $piefilter = 'id';
59        else if( array_key_exists( "user", $filter ) )
60                $piefilter = 'user';
61        else if( array_key_exists( "queue", $filter ) )
62                $piefilter = 'queue';
63
64        $pie = drawPie();
65        $tpl->assign("pie", $pie );
66}
67
68function timeToEpoch( $time ) {
69
70        $time_fields = explode( ':', $time );
71
72        if( count($time_fields) == 3 ) {
73
74                $hours = $time_fields[0];
75                $minutes = $time_fields[1];
76                $seconds = $time_fields[2];
77
78        } else if( count($time_fields) == 2 ) {
79
80                $hours = 0;
81                $minutes = $time_fields[0];
82                $seconds = $time_fields[1];
83
84        } else if( count($time_fields) == 1 ) {
85
86                $hours = 0;
87                $minutes = 0;
88                $seconds = $time_fields[0];
89        }
90
91        $myepoch = intval( $seconds + (intval( $minutes * 60 )) + (intval( $hours * 3600 )) );
92
93        return $myepoch;
94}
95
96//function makeDate( $time ) {
97//      return strftime( "%a %d %b %Y %H:%M:%S", $time );
98//}
99
100function colorRed( $color ) {
101        return substr( $color, 0, 2 );
102}
103function colorGreen( $color ) {
104        return substr( $color, 2, 2 );
105}
106function colorBlue( $color ) {
107        return substr( $color, 4, 2 );
108}
109
110function colorDiffer( $first, $second ) {
111
112        // Make sure these two colors differ atleast 50 R/G/B
113        $min_diff = 50;
114
115        $c1r = hexDec( colorRed( $first ) );
116        $c1g = hexDec( colorGreen( $first ) );
117        $c1b = hexDec( colorBlue( $first ) );
118
119        $c2r = hexDec( colorRed( $second ) );
120        $c2g = hexDec( colorGreen( $second ) );
121        $c2b = hexDec( colorBlue( $second ) );
122
123        $rdiff = ($c1r >= $c2r) ? $c1r - $c2r : $c2r - $c1r;
124        $gdiff = ($c1g >= $c2g) ? $c1g - $c2g : $c2g - $c1g;
125        $bdiff = ($c1b >= $c2b) ? $c1b - $c2b : $c2b - $c1b;
126
127        if( $rdiff >= $min_diff or $gdiff >= $min_diff or $bdiff >= $min_diff )
128                return TRUE;
129        else
130                return FALSE;
131}
132
133function randomColor( $known_colors ) {
134
135        $start = "004E00";
136       
137        $start_red = colorRed( $start );
138        $start_green = colorGreen( $start );
139        $start_blue = colorBlue( $start );
140       
141        $end = "FFFFFF";
142
143        $end_red = colorRed( $end );
144        $end_green = colorGreen( $end );
145        $end_blue = colorBlue( $end );
146
147        $change_color = TRUE;
148
149        while( $change_color ) {
150
151                $change_color = FALSE;
152
153                $new_red = rand( hexDec( $start_red ), hexDec( $end_red ) );
154                $new_green = rand( hexDec( $start_green ), hexDec( $end_green ) );
155                $new_blue = rand( hexDec( $start_blue ), hexDec( $end_blue ) );
156
157                $new = decHex( $new_red ) . decHex( $new_green ) . decHex( $new_blue );
158
159                foreach( $known_colors as $old )
160
161                        if( !colorDiffer( $new, $old ) )
162
163                                $change_color = TRUE;
164        }
165
166        // Whoa! Actually found a good color ;)
167        return $new;
168}
169
170function drawJobPie() {
171}
172
173function drawUserPie() {
174
175}
176
177function drawQueuePie() {
178
179}
180
181
182function drawPie() {
183
184        global $jobs, $gnodes, $piefilter, $filter, $metrics;
185
186        $nodes          = $gnodes;
187
188        if( isset($piefilter) ) 
189                $pie_args       = "title=" . rawurlencode("Cluster ".$piefilter." usage");
190        else
191                $pie_args       = "title=" . rawurlencode("Cluster queue usage");
192               
193        $pie_args       .= "&size=250x150";
194
195        $queues         = array();
196        $nr_jobs        = count( $jobs );
197        $nr_nodes       = count( $nodes );
198
199        $nr_cpus        = cluster_sum("cpu_num", $metrics);
200
201        $empty_cpus     = 0;
202        $used_cpus      = 0;
203
204        $job_weight     = array();
205
206        foreach( $nodes as $node ) {
207
208                $myjobs         = $node->getJobs();
209                $myhost         = $node->getHostname();
210                $node_cpus      = $metrics[$myhost]["cpu_num"][VAL];
211                $job_cpu        = 0;
212
213                foreach( $myjobs as $myjob ) {
214
215                        $job_cpu        += (int) $jobs[$myjob][ppn] ? $jobs[$myjob][ppn] : 1;
216                }
217
218                $node_freecpu   = $node_cpus - $job_cpu;
219
220                $empty_cpus     += $node_freecpu;
221        }
222
223        $used_cpus              = $nr_cpus - $empty_cpus;
224
225        $empty_percentage       = ($empty_cpus / $nr_cpus) * 100;
226
227        $qcolors                = array();
228        $color                  = randomColor( $qcolors );
229        $qcolors[]              = $color;
230        $pie_args               .= "&free=$empty_percentage,$color";
231
232        if( isset( $piefilter ) )
233                $filterpie = array();
234
235        foreach( $nodes as $node ) {
236
237                $node_jobs      = $node->getJobs();
238                $nr_node_jobs   = count( $node_jobs );
239                $myhost         = $node->getHostname();
240                $node_cpus      = $metrics[$myhost]["cpu_num"][VAL];
241
242                foreach( $node_jobs as $myjob ) {
243
244                        $job_cpu                = (int) $jobs[$myjob][ppn] ? $jobs[$myjob][ppn] : 1;
245
246                        // Determine the weight of this job
247                        // - what percentage of the cpus is in use by this job
248                        //
249                        $job_weight[$myjob]     = ( $job_cpu / $nr_cpus );
250
251
252                        if( isset($piefilter) ) {
253                                $countjob = 1;
254                                if( $piefilter == 'id' ) {
255                                        if( $myjob != $filter[$piefilter] )
256                                                $countjob = 0;
257                                } else if( $piefilter == 'user' ) {
258                                        if( $jobs[$myjob][owner] != $filter[$piefilter] )
259                                                $countjob = 0;
260                                } else {
261                                        if( $jobs[$myjob][$piefilter] != $filter[$piefilter] )
262                                                $countjob = 0;
263                                }
264
265                                if( $countjob ) {
266
267                                        if( !isset( $filterpie[$filter[$piefilter]] ) )
268                                                $filterpie[$filter[$piefilter]] = $job_weight[$myjob];
269                                        else
270                                                $filterpie[$filter[$piefilter]] = $filterpie[$filter[$piefilter]] + $job_weight[$myjob];
271                                } else {
272                                        if( !isset( $filterpie["other"] ) )
273                                                $filterpie["other"] = $job_weight[$myjob];
274                                        else
275                                                $filterpie["other"] = $filterpie["other"] + $job_weight[$myjob];
276
277                                }
278                               
279                        } else {
280
281                                $qname          = $jobs[$myjob][queue];
282
283                                if( !isset( $queues[$qname] ) )
284                                        $queues[$qname] = $job_weight[$myjob];
285                                else
286                                        $queues[$qname] = $queues[$qname] + $job_weight[$myjob];
287                        }
288                }
289        }
290
291        if( isset( $piefilter ) )
292                $graphvals = $filterpie;
293        else
294                $graphvals = $queues;
295
296        foreach( $graphvals as $name => $totalweight) {
297
298                $percentage     = ( $totalweight * 100 );
299               
300                $color          = randomColor( $qcolors );
301                $qcolors[]      = $color;
302                $pie_args       .= "&$name=$percentage,$color";
303        }
304        $pie = "../../pie.php?$pie_args";
305
306        return $pie;
307}
308
309
310function sortJobs( $jobs, $sortby, $sortorder ) {
311
312        $sorted = array();
313
314        $cmp = create_function( '$a, $b', 
315                "global \$sortby, \$sortorder;".
316
317                "if( \$a == \$b ) return 0;".
318
319                "if (\$sortorder==\"desc\")".
320                        "return ( \$a < \$b ) ? 1 : -1;".
321                "else if (\$sortorder==\"asc\")".
322                        "return ( \$a > \$b ) ? 1 : -1;" );
323
324        if( isset( $jobs ) && count( $jobs ) > 0 ) {
325
326                foreach( $jobs as $jobid => $jobattrs ) {
327
328                                $state = $jobattrs[status];
329                                $user = $jobattrs[owner];
330                                $queue = $jobattrs[queue];
331                                $name = $jobattrs[name];
332                                $req_cpu = $jobattrs[requested_time];
333                                $req_memory = $jobattrs[requested_memory];
334
335                                if( $state == 'R' )
336                                        $nodes = count( $jobattrs[nodes] );
337                                else
338                                        $nodes = $jobattrs[nodes];
339
340                                $ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1;
341                                $cpus = $nodes * $ppn;
342                                $queued_time = (int) $jobattrs[queued_timestamp];
343                                $start_time = (int) $jobattrs[start_timestamp];
344                                $runningtime = $report_time - $start_time;
345
346                                switch( $sortby ) {
347                                        case "id":
348                                                $sorted[$jobid] = $jobid;
349                                                break;
350
351                                        case "state":
352                                                $sorted[$jobid] = $state;
353                                                break;
354
355                                        case "user":
356                                                $sorted[$jobid] = $user;
357                                                break;
358
359                                        case "queue":
360                                                $sorted[$jobid] = $queue;
361                                                break;
362
363                                        case "name":
364                                                $sorted[$jobid] = $name;
365                                                break;
366
367                                        case "req_cpu":
368                                                $sorted[$jobid] = timeToEpoch( $req_cpu );
369                                                break;
370
371                                        case "req_mem":
372                                                $sorted[$jobid] = $req_memory;
373                                                break;
374
375                                        case "nodes":
376                                                $sorted[$jobid] = $nodes;
377                                                break;
378
379                                        case "cpus":
380                                                $sorted[$jobid] = $cpus;
381                                                break;
382
383                                        case "queued":
384                                                $sorted[$jobid] = $queued_time;
385                                                break;
386
387                                        case "start":
388                                                $sorted[$jobid] = $start_time;
389                                                break;
390
391                                        case "runningtime":
392                                                $sorted[$jobid] = $runningtime;
393                                                break;
394
395                                        default:
396                                                break;
397
398                                }
399                }
400        }
401
402        //uasort( $sorted, $cmp );
403        if( $sortorder == "asc" )
404                arsort( $sorted );
405        else if( $sortorder == "desc" )
406                asort( $sorted );
407
408        return $sorted;
409}
410
411function makeOverview() {
412
413        global $jobs, $nodes, $heartbeat, $clustername, $tpl;
414        global $sortorder, $sortby, $filter, $sh, $hc, $m;
415        global $cluster_url, $get_metric_string, $host_url, $metrics;
416        global $start, $end, $reports, $gnodes, $default_showhosts;
417        global $COLUMN_QUEUED, $COLUMN_REQUESTED_MEMORY, $COLUMN_NODES, $hostname;
418        $metricname = $m;
419
420        $tpl->assign("sortorder", $sortorder );
421        $tpl->assign("sortby", $sortby );
422
423        $sorted_jobs = sortJobs( $jobs, $sortby, $sortorder );
424
425        $even = 1;
426
427        $used_jobs = 0;
428        $used_cpus = 0;
429        $used_nodes = 0;
430
431        $queued_jobs = 0;
432        $queued_nodes = 0;
433        $queued_cpus = 0;
434
435        $total_nodes = 0;
436        $total_cpus = 0;
437        $total_jobs = 0;
438
439        $all_used_nodes = array();
440        $total_used_nodes = array();
441
442        $running_name_nodes = array();
443
444        $running_nodes = 0;
445        $running_jobs = 0;
446        $running_cpus = 0;
447
448        $avail_nodes = count( $gnodes );
449        $avail_cpus = cluster_sum("cpu_num", $metrics);
450
451        $view_cpus = 0;
452        $view_jobs = 0;
453        $view_nodes = 0;
454
455        $all_nodes = 0;
456        $all_jobs = 0;
457        $all_cpus = 0;
458
459        $view_name_nodes = array();
460
461        if( $COLUMN_REQUESTED_MEMORY ) {
462                $tpl->newBlock( "column_header_req_mem" );
463        }
464
465        if( $COLUMN_NODES ) {
466                $tpl->newBlock( "column_header_nodes" );
467        }
468
469        if( $COLUMN_QUEUED ) {
470                $tpl->newBlock( "column_header_queued" );
471        }
472
473        $last_displayed_job = null;
474
475        foreach( $sorted_jobs as $jobid => $sortdec ) {
476
477                $report_time = $jobs[$jobid][reported];
478
479                if( $jobs[$jobid][status] == 'R' )
480                        $nodes = count( $jobs[$jobid][nodes] );
481                else if( $jobs[$jobid][status] == 'Q' )
482                        $nodes = $jobs[$jobid][nodes];
483
484                $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1;
485                $cpus = $nodes * $ppn;
486
487                if( $report_time == $heartbeat ) {
488
489                        $display_job = 1;
490
491                        if( $jobs[$jobid][status] == 'R' ) {
492                                foreach( $jobs[$jobid][nodes] as $tempnode ) {
493                                        $all_used_nodes[] = $tempnode;
494                                }
495                        }
496
497                        $used_cpus += $cpus;
498
499                        if( $jobs[$jobid][status] == 'R' ) {
500                                $running_cpus += $cpus;
501                                $running_jobs++;
502
503                                $found_node_job = 0;
504
505                                foreach( $jobs[$jobid][nodes] as $tempnode ) {
506                                        $running_name_nodes[] = $tempnode;
507
508                                        if( isset( $hostname ) && $hostname != '' ) {
509                                                //$filter[host] = $hostname;
510
511                                                $domain_len = 0 - strlen( $jobs[$jobid][domain] );
512                                                $hostnode = $tempnode;
513                                                if( substr( $hostnode, $domain_len ) != $jobs[$jobid][domain] ) {
514                                                        $hostnode = $hostnode. '.'. $jobs[$jobid][domain];
515                                                }
516
517                                                if( $hostname == $hostnode ) {
518                                                        $found_node_job = 1;
519                                                        $display_job = 1;
520                                                } else if( !$found_node_job ) {
521                                                        $display_job = 0;
522                                                }
523                                        }
524                                }
525                        }
526
527                        if( $jobs[$jobid][status] == 'Q' ) {
528                                if( isset( $hostname ) && $hostname != '' )
529                                        $display_job = 0;
530
531                                $queued_cpus += $cpus;
532                                $queued_nodes += $nodes;
533                                $queued_jobs++;
534                        }
535
536                        foreach( $filter as $filtername=>$filtervalue ) {
537
538                                if( $filtername == 'id' && $jobid != $filtervalue )
539                                        $display_job = 0;
540                                else if( $filtername == 'state' && $jobs[$jobid][status] != $filtervalue )
541                                        $display_job = 0;
542                                else if( $filtername == 'queue' && $jobs[$jobid][queue] != $filtervalue )
543                                        $display_job = 0;
544                                else if( $filtername == 'user' && $jobs[$jobid][owner] != $filtervalue )
545                                        $display_job = 0;
546                        }
547
548                        if( $display_job ) {
549
550                                $tpl->newBlock("node");
551                                $tpl->assign( "clustername", $clustername );
552                                $tpl->assign("id", $jobid );
553
554                                $last_displayed_job = $jobid;
555
556                                $tpl->assign("state", $jobs[$jobid][status] );
557
558                                $fullstate = '';
559                                if( $jobs[$jobid][status] == 'R' ) {
560                                        $fullstate = "Running";
561                                } else if( $jobs[$jobid][status] == 'Q' ) {
562                                        $fullstate = "Queued";
563                                }
564
565                                $tpl->assign("fullstate", $fullstate );
566                               
567                                $tpl->assign("user", $jobs[$jobid][owner] );
568                                $tpl->assign("queue", $jobs[$jobid][queue] );
569
570                                $fulljobname = $jobs[$jobid][name];
571                                $shortjobname = '';
572
573                                $tpl->assign("fulljobname", $fulljobname );
574
575                                $fulljobname_fields     = explode( ' ', $fulljobname );
576
577                                $capjobname     = 0;
578
579                                if( strlen( $fulljobname_fields[0] ) > 10 )
580                                        $capjobname     = 1;
581
582                                if( $capjobname ) {
583                                        $tpl->newBlock("jobname_hint_start");
584                                        $tpl->gotoBlock("node");
585
586                                        $shortjobname = substr( $fulljobname, 0, 10 ) . '..';
587                                } else {
588                                        $shortjobname = $fulljobname;
589                                }
590                               
591                                $tpl->assign("name", $shortjobname );
592
593                                if( $capjobname ) {
594                                        $tpl->newBlock("jobname_hint_end");
595                                        $tpl->gotoBlock("node");
596                                }
597
598                                $domain = $jobs[$jobid][domain];
599                                $tpl->assign("req_cpu", makeTime( timeToEpoch( $jobs[$jobid][requested_time] ) ) );
600
601                                if( $COLUMN_REQUESTED_MEMORY ) {
602                                        $tpl->newBlock( "column_req_mem" );
603                                        $tpl->assign( "req_memory", $jobs[$jobid][requested_memory] );
604                                        $tpl->gotoBlock( "node" );
605                                }
606
607
608                                if( $COLUMN_QUEUED ) {
609                                        $tpl->newBlock( "column_queued" );
610                                        $tpl->assign( "queued", makeDate( $jobs[$jobid][queued_timestamp] ) );
611                                        $tpl->gotoBlock( "node" );
612                                }
613                                if( $COLUMN_NODES ) {
614                                        $tpl->newBlock( "column_nodes" );
615                                        $tpl->gotoBlock( "node" );
616                                }
617
618                                $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1;
619                                $cpus = $nodes * $ppn;
620                                $tpl->assign("nodes", $nodes );
621                                $tpl->assign("cpus", $cpus );
622                                $start_time = (int) $jobs[$jobid][start_timestamp];
623                                $job_start = $start_time;
624
625                                $view_cpus += $cpus;
626                                $view_jobs++;
627
628                                if( $jobs[$jobid][status] == 'R' ) {
629                                        foreach( $jobs[$jobid][nodes] as $tempnode )
630                                                $view_name_nodes[] = $tempnode;
631
632                                        if( $COLUMN_NODES ) {
633                                                $tpl->gotoBlock( "column_nodes" );
634                                                $mynodehosts = array();
635                                                foreach( $jobs[$jobid][nodes] as $mynode ) {
636                                                        $myhost_href = "./?c=".$clustername."&h=".$mynode.".".$jobs[$jobid][domain];
637                                                        $mynodehosts[] = "<A HREF=\"".$myhost_href."\">".$mynode."</A>";
638                                                }
639                                                $nodes_hostnames = implode( " ", $mynodehosts );
640                                                $tpl->assign( "nodes_hostnames", $nodes_hostnames );
641                                                $tpl->gotoBlock( "node" );
642                                        }
643                                } else if( $jobs[$jobid][status] == 'Q' ) {
644                                        $view_nodes += (int) $jobs[$jobid][nodes];
645                                }
646
647                                if( $even ) {
648
649                                        $tpl->assign("nodeclass", "even");
650                                        $even = 0;
651                                } else {
652
653                                        $tpl->assign("nodeclass", "odd");
654                                        $even = 1;
655                                }
656
657                                if( $start_time ) {
658
659                                        $runningtime = makeTime( $report_time - $start_time );
660                                        $job_runningtime = $report_time - $start_time;
661                                        $tpl->assign("started", makeDate( $start_time ) );
662                                        $tpl->assign("runningtime", $runningtime );
663                                }
664                        }
665                }
666        }
667        $all_used_nodes = array_unique( $all_used_nodes );
668        $view_name_nodes = array_unique( $view_name_nodes );
669        $running_name_nodes = array_unique( $running_name_nodes );
670
671        $used_nodes = count( $all_used_nodes );
672        $view_nodes += count( $view_name_nodes );
673        $running_nodes += count( $running_name_nodes );
674
675        $total_nodes = $queued_nodes + $running_nodes;
676        $total_cpus = $queued_cpus + $running_cpus;
677        $total_jobs = $queued_jobs + $running_jobs;
678
679        $tpl->assignGlobal("avail_nodes", $avail_nodes );
680        $tpl->assignGlobal("avail_cpus", $avail_cpus );
681
682        $tpl->assignGlobal("queued_nodes", $queued_nodes );
683        $tpl->assignGlobal("queued_jobs", $queued_jobs );
684        $tpl->assignGlobal("queued_cpus", $queued_cpus );
685
686        $tpl->assignGlobal("total_nodes", $total_nodes );
687        $tpl->assignGlobal("total_jobs", $total_jobs );
688        $tpl->assignGlobal("total_cpus", $total_cpus );
689
690        $tpl->assignGlobal("running_nodes", $running_nodes );
691        $tpl->assignGlobal("running_jobs", $running_jobs );
692        $tpl->assignGlobal("running_cpus", $running_cpus );
693
694        $tpl->assignGlobal("used_nodes", $used_nodes );
695        $tpl->assignGlobal("used_jobs", $used_jobs );
696        $tpl->assignGlobal("used_cpus", $used_cpus );
697
698        $free_nodes = $avail_nodes - $running_nodes;
699        $free_cpus = $avail_cpus - $running_cpus;
700
701        $tpl->assignGlobal("free_nodes", $free_nodes );
702        $tpl->assignGlobal("free_cpus", $free_cpus );
703
704        $tpl->assignGlobal("view_nodes", $view_nodes );
705        $tpl->assignGlobal("view_jobs", $view_jobs );
706        $tpl->assignGlobal("view_cpus", $view_cpus );
707
708        $tpl->assignGlobal("report_time", makeDate( $heartbeat));
709
710        if( intval($view_jobs) == 1 and $start_time )
711                if( $last_displayed_job != null )
712                        $filter[id] = $last_displayed_job;
713
714        makeHeader( 'overview' );
715        setupFilterSettings();
716
717        if( intval($view_jobs) == 1 and $start_time ) {
718
719                $tpl->newBlock( "showhosts" );
720
721                # Present a width list
722                $cols_menu = "<SELECT NAME=\"hc\" OnChange=\"toga_form.submit();\">\n";
723
724
725                $hostcols = ($hc) ? $hc : 4;
726
727                foreach(range(1,25) as $cols) {
728                        $cols_menu .= "<OPTION VALUE=$cols ";
729                        if ($cols == $hostcols)
730                                $cols_menu .= "SELECTED";
731                        $cols_menu .= ">$cols\n";
732                }
733                $cols_menu .= "</SELECT>\n";
734
735                //$tpl->assign("cluster", $clustername);
736                $tpl->assign("metric","$metricname $units");
737                $tpl->assign("id", $filter[id]);
738                # Host columns menu defined in header.php
739                $tpl->assign("cols_menu", $cols_menu);
740
741                $showhosts = isset($sh) ? $sh : $default_showhosts;
742                //if( !$showhosts) $showhosts = $default_showhosts;
743                $tpl->assign("checked$showhosts", "checked");
744
745                if( $showhosts ) {
746                        //-----
747
748                        if( !isset($start) ) $start="jobstart";
749                        if( !isset($stop) ) $stop="now";
750                        //$tpl->assign("start", $start);
751                        //$tpl->assign("stop", $stop);
752
753                        $sorted_hosts = array();
754                        $hosts_up = $jobs[$filter[id]][nodes];
755
756                        $r = intval($job_runningtime * 1.25);
757
758                        $jobrange = ($job_runningtime < 3600) ? -3600 : -$r ;
759                        $jobstart = $report_time - $job_runningtime;
760
761                        if ($reports[$metricname])
762                                $metricval = "g";
763                        else
764                                $metricval = "m";
765                               
766                        foreach ($hosts_up as $host ) {
767
768                                $domain_len = 0 - strlen( $domain );
769                                if( substr( $host, $domain_len ) != $domain ) {
770                                        $host = $host. '.'.$domain;
771                                }
772                                $cpus = $metrics[$host]["cpu_num"][VAL];
773                                if (!$cpus) $cpus=1;
774                                $load_one  = $metrics[$host]["load_one"][VAL];
775                                $load = ((float) $load_one)/$cpus;
776                                $host_load[$host] = $load;
777                                $percent_hosts[load_color($load)] += 1;
778                                if ($metricname=="load_one")
779                                        $sorted_hosts[$host] = $load;
780                                else
781                                        $sorted_hosts[$host] = $metrics[$host][$metricname][VAL];
782                        }
783                        switch ($sort) {
784                                case "descending":
785                                        arsort($sorted_hosts);
786                                        break;
787                                case "by hostname":
788                                        ksort($sorted_hosts);
789                                        break;
790                                default:
791                                case "ascending":
792                                        asort($sorted_hosts);
793                                        break;
794                        }
795
796                        //$sorted_hosts = array_merge($down_hosts, $sorted_hosts);
797
798                        # First pass to find the max value in all graphs for this
799                        # metric. The $start,$end variables comes from get_context.php,
800                        # included in index.php.
801                        list($min, $max) = find_limits($sorted_hosts, $metricname);
802
803                        # Second pass to output the graphs or metrics.
804                        $i = 1;
805                        foreach ( $sorted_hosts as $host=>$value  ) {
806                                $tpl->newBlock ("sorted_list");
807                                //$host = $host. '.'.$domain;
808                                $host_url = rawurlencode($host);
809                                $cluster_url = rawurlencode($clustername);
810
811                                $textval = "";
812                                //printf("host = %s, value = %s", $host, $value);
813                                //echo "$host: $value, ";
814                                $val = $metrics[$host][$metricname];
815                                $class = "metric";
816                                $host_link="\"../../?c=$cluster_url&h=$host_url&r=job&jr=$jobrange&js=$jobstart\"";
817
818                                if ($val[TYPE]=="timestamp" or $always_timestamp[$metricname]) {
819                                        $textval = date("r", $val[VAL]);
820                                } elseif ($val[TYPE]=="string" or $val[SLOPE]=="zero" or $always_constant[$metricname] or ($max_graphs > 0 and $i > $max_graphs )) {
821                                        $textval = "$val[VAL] $val[UNITS]";
822                                } else {
823                                        $load_color = load_color($host_load[$host]);
824                                        $graphargs = ($reports[$metricname]) ? "g=$metricname&" : "m=$metricname&";
825                                        $graphargs .= "z=small&c=$cluster_url&h=$host_url&l=$load_color" ."&v=$val[VAL]&r=job&jr=$jobrange&js=$jobstart";
826                                        if( $max > 0 ) {
827
828                                                $graphargs .= "&x=$max&n=$min";
829                                        }
830                                }
831                                if ($textval) {
832                                        $cell="<td class=$class>".  "<b><a href=$host_link>$host</a></b><br>".  "<i>$metricname:</i> <b>$textval</b></td>";
833                                } else {
834                                        $cell="<td><a href=$host_link>".  "<img src=\"../../graph.php?$graphargs\" ".  "alt=\"$host\" border=0></a></td>";
835                                }
836
837                                $tpl->assign("metric_image", $cell);
838                                if (! ($i++ % $hostcols) )
839                                         $tpl->assign ("br", "</tr><tr>");
840                        }
841                }
842//---
843        }
844}
845?>
Note: See TracBrowser for help on using the repository browser.