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

Last change on this file since 231 was 231, checked in by bastiaans, 18 years ago

*.php:

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