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

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

ALL:

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