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

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

web/addons/job_monarch/styles.css:

  • added extra overview table styles

web/addons/job_monarch/templates/overview.tpl:

  • added table to show usage of jobs/nodes/cpus

web/addons/job_monarch/overview.php:

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