"Fossies" - the Fresh Open Source Software Archive

Member "ganglia-web-3.7.2/cluster_view.php" (8 Jun 2016, 25004 Bytes) of package /linux/www/ganglia-web-3.7.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "cluster_view.php" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 3.7.1_vs_3.7.2.

    1 <?php
    2 $refresh = isset($_GET['refresh']);
    3 
    4 
    5 include_once "./eval_conf.php";
    6 // ATD - function.php must be included before get_context.php.  
    7 // It defines some needed functions.
    8 include_once "./functions.php";
    9 include_once "./get_context.php";
   10 include_once "./ganglia.php";
   11 include_once "./get_ganglia.php";
   12 include_once "./dwoo/dwooAutoload.php";
   13 
   14 if ($refresh) {
   15   try {
   16     $dwoo = new Dwoo($conf['dwoo_compiled_dir'], $conf['dwoo_cache_dir']);
   17   } catch (Exception $e) {
   18     print "<H4>There was an error initializing the Dwoo PHP Templating Engine: " .
   19       $e->getMessage() . 
   20       "<br><br>The compile directory should be owned and writable by the apache user.</H4>";
   21     exit;
   22   }
   23 }
   24 
   25 function get_picker_metrics($metrics, $reports, $gweb_root, $graph_engine) {
   26   $context_metrics = "";
   27   if (count($metrics)) {
   28     foreach ($metrics as $host_metrics) {
   29       foreach ($host_metrics as $metric_name => $metric_value) {
   30     $context_metrics[$metric_name] = rawurldecode($metric_name);
   31       }
   32     }
   33     foreach ($reports as $report_name => $report_value)
   34       $context_metrics[] = $report_name;
   35   }
   36 
   37   if (!is_array($context_metrics))
   38     return NULL;
   39 
   40   $picker_metrics = array();
   41 
   42   // Find all the optional reports
   43   if ($handle = opendir($gweb_root . '/graph.d')) {
   44     // If we are using RRDtool reports can be json or PHP suffixes
   45     if ( $graph_engine == "rrdtool" )
   46       $report_suffix = "php|json";
   47     else
   48       $report_suffix = "json";
   49     
   50     while (false !== ($file = readdir($handle))) {
   51       if (preg_match("/(.*)(_report)\.(" . $report_suffix .")/", 
   52              $file, 
   53              $out)) {
   54         if (!in_array($out[1] . "_report", $context_metrics))
   55           $context_metrics[] = $out[1] . "_report";
   56       }
   57     }
   58     closedir($handle);
   59   }
   60 
   61   sort($context_metrics);
   62 
   63   foreach ($context_metrics as $metric) {
   64     $url = rawurlencode($metric);
   65     $picker_metrics[] = "<option value=\"$url\">$metric</option>";
   66   }
   67   return $picker_metrics;
   68 }
   69 
   70 function get_load($host, $metrics) {
   71   if (isset($metrics[$host]["cpu_num"]['VAL']) and 
   72       $metrics[$host]["cpu_num"]['VAL'] != 0 ) {
   73     $cpus = $metrics[$host]["cpu_num"]['VAL'];
   74   } else {
   75     $cpus = 1;
   76   }
   77 
   78   if (isset($metrics[$host]["load_one"]['VAL']) ){
   79     $load_one = $metrics[$host]["load_one"]['VAL'];
   80   } else {
   81     $load_one = 0;
   82   }
   83   $load = ((float) $load_one) / $cpus;
   84   return $load;
   85 }
   86 
   87 function get_load_pie($showhosts, 
   88               $hosts_up, 
   89               $hosts_down, 
   90               $user, 
   91               $conf,
   92               $metrics, 
   93               $cluster,
   94               $name,
   95               $data) {
   96   if ($showhosts != 0) {
   97     $percent_hosts = array();
   98     foreach ($hosts_up as $host => $val) {
   99       // If host_regex is defined
  100       if (isset($user['host_regex']) && 
  101           ! preg_match("/" .$user['host_regex'] . "/", $host))
  102         continue;
  103       
  104       $load = get_load($host, $metrics);
  105 
  106       if (isset($percent_hosts[load_color($load)])) { 
  107         $percent_hosts[load_color($load)] += 1;
  108       } else {
  109         $percent_hosts[load_color($load)] = 1;
  110       }
  111     }
  112          
  113     foreach ($hosts_down as $host => $val) {
  114       $load = -1.0;
  115       if (isset($percent_hosts[load_color($load)])) {
  116         $percent_hosts[load_color($load)] += 1;
  117       } else {
  118         $percent_hosts[load_color($load)] = 1;
  119       }
  120     }
  121 
  122     // Show pie chart of loads
  123     $pie_args = "title=" . rawurlencode("Cluster Load Percentages");
  124     $pie_args .= "&amp;size=250x150";
  125     foreach ($conf['load_colors'] as $name => $color) {
  126       if (!array_key_exists($color, $percent_hosts))
  127         continue;
  128       $n = $percent_hosts[$color];
  129       $name_url = rawurlencode($name);
  130       $pie_args .= "&amp;$name_url=$n,$color";
  131     }
  132     $data->assign("pie_args", $pie_args);
  133   } else {
  134     // Show pie chart of hosts up/down
  135     $pie_args = "title=" . rawurlencode("Host Status");
  136     $pie_args .= "&amp;size=250x150";
  137     $up_color = $conf['load_colors']["25-50"];
  138     $down_color = $conf['load_colors']["down"];
  139     $pie_args .= "&amp;Up=$cluster[HOSTS_UP],$up_color";
  140     $pie_args .= "&amp;Down=$cluster[HOSTS_DOWN],$down_color";
  141     $data->assign("pie_args", $pie_args);
  142   }
  143 }
  144 
  145 function get_host_metric_graphs($showhosts,
  146                 $hosts_up, 
  147                                 $hosts_down, 
  148                                 $user, 
  149                                 $conf,
  150                                 $metrics, 
  151                                 $metricname,
  152                                 $sort,
  153                                 $clustername,
  154                                 $get_metric_string,
  155                                 $cluster,
  156                                 $always_timestamp,
  157                                 $reports_metricname,
  158                                 $clustergraphsize,
  159                                 $range,
  160                 $start,
  161                 $end,
  162                                 $cs,
  163                                 $ce,
  164                                 $vlabel,
  165                     $data) {
  166   $sorted_hosts = array();
  167   $down_hosts = array();
  168 
  169   if ($showhosts == 0)
  170     return;
  171 
  172   foreach ($hosts_up as $host => $val) {
  173     // If host_regex is defined
  174     if (isset($user['host_regex']) && 
  175     ! preg_match("/" .$user['host_regex'] . "/", $host))
  176       continue;
  177 
  178     $load = get_load($host, $metrics);
  179     $host_load[$host] = $load;
  180 
  181     if ($metricname == "load_one")
  182       $sorted_hosts[$host] = $load;
  183     else if (isset($metrics[$host][$metricname]))
  184       $sorted_hosts[$host] = $metrics[$host][$metricname]['VAL'];
  185     else
  186       $sorted_hosts[$host] = "";
  187   } // foreach hosts_up
  188          
  189   foreach ($hosts_down as $host => $val) {
  190     $down_hosts[$host] = -1.0;
  191   }
  192 
  193   $data->assign("node_legend", 1);
  194 
  195   if (!is_array($hosts_up))
  196     return;
  197 
  198   switch ($sort) {
  199   case "descending":
  200     arsort($sorted_hosts);
  201     break;
  202   case "by name":
  203     uksort($sorted_hosts, "strnatcmp");
  204     break;
  205   default:
  206   case "ascending":
  207     asort($sorted_hosts);
  208     break;
  209   }
  210 
  211   $sorted_hosts = array_merge($down_hosts, $sorted_hosts);
  212 
  213   if (isset($user['max_graphs']))
  214     $max_graphs = $user['max_graphs'];
  215   else
  216     $max_graphs = $conf['max_graphs'];
  217 
  218   // First pass to find the max value in all graphs for this
  219   // metric. The $start,$end variables comes from get_context.php, 
  220   // included in index.php.
  221   // Do this only if person has not selected a maximum set of graphs to display
  222   if ($max_graphs == 0 && $showhosts == 1) {
  223     $cs = $user['cs'];
  224     if ($cs and (is_numeric($cs) or strtotime($cs)))
  225       $start = $cs;
  226 
  227     $ce = $user['ce'];
  228     if ($ce and (is_numeric($ce) or strtotime($ce)))
  229       $end = $ce;
  230 
  231     list($min, $max) = find_limits($clustername,
  232                    $sorted_hosts, 
  233                    $metricname,
  234                    $start,
  235                    $end,
  236                    $metrics,
  237                    $conf,
  238                    $rrd_options);
  239   }
  240 
  241   // Second pass to output the graphs or metrics.
  242   $i = 1;
  243 
  244   // Initialize overflow list
  245   $overflow_list = array();
  246   $overflow_counter = 1;
  247   $cluster_url = rawurlencode($clustername);
  248   $size = isset($clustergraphsize) ? $clustergraphsize : 'small';
  249   if ($conf['hostcols'] == 0) // enforce small size in multi-host report
  250     $size = 'small';
  251   // set host zoom class based on the size of the graph shown
  252   if (isset($conf['zoom_support']) && $conf['zoom_support'] === true)
  253     $additional_host_img_html_args = "class=host_${size}_zoomable";
  254 
  255   foreach ($sorted_hosts as $host => $value) {
  256     if (isset($hosts_down[$host]) and $hosts_down[$host] && isset($conf['cluster_hide_down_hosts']) && $conf['cluster_hide_down_hosts']) {
  257       // If we're hiding DOWN hosts, we skip to next iteration of the loop.
  258       continue;
  259     }
  260     $host_url = ($case_sensitive_hostnames) ? rawurlencode($host) : strtolower(rawurlencode($host));
  261     
  262     $host_link="\"?c=$cluster_url&amp;h=$host_url&amp;$get_metric_string\"";
  263     $textval = "";
  264 
  265     //echo "$host: $value, ";
  266 
  267     if (isset($hosts_down[$host]) and $hosts_down[$host]) {
  268       $last_heartbeat = $cluster['LOCALTIME'] - $hosts_down[$host]['REPORTED'];
  269       $age = $last_heartbeat > 3600 ? 
  270         uptime($last_heartbeat) : "${last_heartbeat}s";
  271 
  272       $class = "down";
  273       $textval = "down <br>&nbsp;<font size=\"-2\">Last heartbeat $age ago</font>";
  274     } else {
  275       if (isset($metrics[$host][$metricname]))
  276         $val = $metrics[$host][$metricname];
  277       else
  278         $val = NULL;
  279       $class = "metric";
  280       
  281       if ($val['TYPE']=="timestamp" or 
  282           (isset($always_timestamp[$metricname]) and
  283            $always_timestamp[$metricname])) {
  284         $textval = date("r", $val['VAL']);
  285       } elseif ($val['TYPE']=="string" or 
  286                 $val['SLOPE']=="zero" or
  287                 (isset($always_constant[$metricname]) and
  288                  $always_constant[$metricname] or
  289                  ($max_graphs > 0 and $i > $max_graphs))) {
  290         if (isset($reports_metricname) and $reports_metricname)
  291           // No "current" values available for reports
  292           $textval = "N/A";
  293         else
  294           $textval = "$val[VAL]";
  295         if (isset($val['UNITS']))
  296           $textval .= " $val[UNITS]";
  297       }
  298     }
  299     
  300     $graphargs = "z=$size&amp;c=$cluster_url&amp;h=$host_url";
  301     
  302     if (isset($host_load[$host])) {
  303       $load_color = load_color($host_load[$host]);
  304       $graphargs .= "&amp;l=$load_color&amp;v=$val[VAL]";
  305     }
  306     $graphargs .= "&amp;r=$range&amp;su=1&amp;st=$cluster[LOCALTIME]";
  307     if ($cs)
  308       $graphargs .= "&amp;cs=" . rawurlencode($cs);
  309     if ($ce)
  310       $graphargs .= "&amp;ce=" . rawurlencode($ce);
  311     
  312     // If we want scaling to be the same in clusterview we need to set 
  313     // $max and $min values
  314     if ($showhosts == 1 && $max_graphs == 0 )
  315       $graphargs .= "&amp;x=$max&amp;n=$min";
  316     
  317     if (isset($vlabel))
  318       $graphargs .= "&amp;vl=" . urlencode($vlabel);
  319     
  320     if ($textval) {
  321       $cell = "<td class=$class>" .
  322     "<b><a href=$host_link>$host</a></b><br>" .
  323     "<i>$metricname:</i> <b>$textval</b></td>";
  324     } else {
  325       $cell = "<td><div><font style='font-size: 8px'>$host</font><br><a href=$host_link><img $additional_host_img_html_args src=\"./graph.php?";
  326       $cell .= (isset($reports_metricname) and 
  327                 $reports_metricname) ? "g=$metricname" : "m=$metricname";
  328       $cell .= "&amp;$graphargs\" title=\"$host\" border=0 style=\"padding:2px;\"></a></div></td>";
  329     }
  330 
  331     if ($conf['hostcols'] == 0) {
  332       $pre = "<td><a href=$host_link><img src=\"./graph.php?g=";
  333       $post = "&amp;$graphargs\" $additional_host_img_html_args title=\"$host\" border=0 style=\"padding:2px;\"></a></td>";
  334       $cell .= $pre . "load_report" . $post;
  335       $cell .= $pre . "mem_report" . $post;
  336       $cell .= $pre . "cpu_report" . $post;
  337       $cell .= $pre . "network_report" . $post;
  338     }
  339     
  340     // Check if max_graphs is set. 
  341     // If it put cells in an overflow list since that one is hidden by default
  342     if ($max_graphs > 0 and $i > $max_graphs ) {
  343       $overflow_list[$host]["metric_image"] = $cell;
  344       if (! ($overflow_counter++ % $conf['hostcols']) ) {
  345         $overflow_list[$host]["br"] = "</tr><tr>";
  346       } else {
  347         $overflow_list[$host]["br"] = "";
  348       }
  349     } else {
  350       $sorted_list[$host]["metric_image"] = $cell;
  351       if (! ($i++ % $conf['hostcols']) ) {
  352         $sorted_list[$host]["br"] = "</tr><tr>";
  353       } else {
  354         $sorted_list[$host]["br"] = "";
  355       }
  356     } // end of if ($max_graphs > 0 and $i > $max_graphs ) {
  357   } // foreach sorted_hosts
  358   
  359   $data->assign("sorted_list", $sorted_list);
  360   
  361   // If there is an overflow list. These are hosts for which we don't show graphs
  362   // just names
  363   if (count($overflow_list) > 0) {
  364     $data->assign("overflow_list_header", '<p><table width=80%><tr><td align=center class=metric>
  365     <a href="#" id="overflow_list_button"onclick="$(\'#overflow_list\').toggle();" class="button ui-state-default ui-corner-all" title="Toggle overflow list">Show more hosts (' 
  366     . ($overflow_counter - 1) .')</a>
  367     </td></tr></table>
  368     <div style="display: none;" id="overflow_list"><table>
  369     <tr>
  370     ');
  371     $data->assign("overflow_list_footer", "</div></tr></table></div>");
  372   } else {
  373     $data->assign("overflow_list_header", "");
  374     $data->assign("overflow_list_footer", "");
  375   }
  376   $data->assign("overflow_list", $overflow_list);
  377 }
  378 
  379 function get_cluster_overview($showhosts, 
  380                               $metrics,
  381                               $cluster,
  382                               $range, 
  383                               $clustername, 
  384                               $data) {
  385   $cpu_num = !$showhosts ? $metrics["cpu_num"]['SUM'] : 
  386                            cluster_sum("cpu_num", $metrics);
  387   $data->assign("cpu_num", $cpu_num);
  388 
  389   if (isset($cluster['HOSTS_UP'])) {
  390     $data->assign("num_nodes", intval($cluster['HOSTS_UP']));
  391   } else {
  392     $data->assign("num_nodes", 0);
  393   }
  394 
  395   if (isset($cluster['HOSTS_DOWN'])) {
  396     $data->assign("num_dead_nodes", intval($cluster['HOSTS_DOWN']));
  397   } else {
  398     $data->assign("num_dead_nodes", 0);
  399   }
  400 
  401   $load_one_sum = !$showhosts ? $metrics["load_one"]['SUM'] : 
  402                                 cluster_sum("load_one", $metrics);
  403   $load_five_sum = !$showhosts ? $metrics["load_five"]['SUM'] : 
  404                                  cluster_sum("load_five", $metrics);
  405   $load_fifteen_sum = !$showhosts ? $metrics["load_fifteen"]['SUM'] : 
  406                                     cluster_sum("load_fifteen", $metrics);
  407 
  408   if (!$cpu_num) 
  409     $cpu_num = 1;
  410   $cluster_load15 = sprintf("%.0f", 
  411                             ((double) $load_fifteen_sum / $cpu_num) * 100);
  412   $cluster_load5 = sprintf("%.0f", ((double) $load_five_sum / $cpu_num) * 100);
  413   $cluster_load1 = sprintf("%.0f", ((double) $load_one_sum / $cpu_num) * 100);
  414   $data->assign("cluster_load", 
  415                 "$cluster_load15%, $cluster_load5%, $cluster_load1%");
  416 
  417   $avg_cpu_num = find_avg($clustername, "", "cpu_num");
  418   if ($avg_cpu_num == 0) 
  419     $avg_cpu_num = 1;
  420   $cluster_util = 
  421     sprintf("%.0f", 
  422         ((double) find_avg($clustername, 
  423                    "",
  424                    "load_one") / $avg_cpu_num ) * 100);
  425   $data->assign("cluster_util", "$cluster_util%");
  426   $data->assign("range", $range);
  427 }
  428 
  429 function get_cluster_optional_reports($conf, 
  430                                       $clustername, 
  431                                       $get_metric_string,
  432                                       $localtime,
  433                                       $data) {
  434   $cluster_url = rawurlencode($clustername);
  435   $graph_args = "c=$cluster_url&amp;$get_metric_string&amp;st=$localtime";
  436 
  437   $optional_reports = "";
  438 
  439   // If we want zoomable support on graphs we need to add correct zoomable 
  440   // class to every image
  441   $additional_cluster_img_html_args = "";
  442   if (isset($conf['zoom_support']) && $conf['zoom_support'] === true)
  443     $additional_cluster_img_html_args = "class=cluster_zoomable";
  444 
  445   $data->assign("additional_cluster_img_html_args", 
  446         $additional_cluster_img_html_args);
  447 
  448 ###############################################################################
  449 # Let's find out what optional reports are included
  450 # First we find out what the default (site-wide) reports are then look
  451 # for host specific included or excluded reports
  452 ###############################################################################
  453   $default_reports = array("included_reports" => array(), 
  454                "excluded_reports" => array());
  455  if (is_file($conf['conf_dir'] . "/default.json")) {
  456    $default_reports = array_merge(
  457      $default_reports,
  458      json_decode(file_get_contents($conf['conf_dir'] . "/default.json"), TRUE));
  459  }
  460 
  461  $cluster_file = $conf['conf_dir'] . 
  462    "/cluster_" . 
  463    str_replace(" ", "_", $clustername) . 
  464    ".json";
  465 
  466  $override_reports = array("included_reports" => array(), 
  467                "excluded_reports" => array());
  468  if (is_file($cluster_file)) {
  469    $override_reports = 
  470      array_merge($override_reports, 
  471          json_decode(file_get_contents($cluster_file), TRUE));
  472  }
  473 
  474 # Merge arrays
  475  $reports["included_reports"] = 
  476    array_merge($default_reports["included_reports"],
  477            $override_reports["included_reports"]);
  478  $reports["excluded_reports"] = 
  479    array_merge($default_reports["excluded_reports"],
  480            $override_reports["excluded_reports"]);
  481 
  482 # Remove duplicates
  483  $reports["included_reports"] = array_unique($reports["included_reports"]);
  484  $reports["excluded_reports"] = array_unique($reports["excluded_reports"]);
  485 
  486  $cluster_url = rawurlencode($clustername);
  487 
  488  foreach ($reports["included_reports"] as $index => $report_name ) {
  489    if (! in_array( $report_name, $reports["excluded_reports"])) {
  490      $optional_reports .= "<A HREF=\"./graph_all_periods.php?$graph_args&amp;g=" . $report_name . "&amp;z=large\">
  491     <IMG BORDER=0 style=\"padding:2px;\" $additional_cluster_img_html_args title=\"$cluster_url\" SRC=\"./graph.php?$graph_args&amp;g=" . $report_name ."&amp;z=" . $conf['default_optional_graph_size'] . "\"></A>
  492 ";
  493    }
  494  }
  495  $data->assign("optional_reports", $optional_reports);
  496 
  497  $data->assign("graph_args", $graph_args);
  498 
  499  if (!isset($conf['optional_graphs']))
  500    $conf['optional_graphs'] = array();
  501  $optional_graphs_data = array();
  502  foreach ($conf['optional_graphs'] as $g) {
  503    $optional_graphs_data[$g]['name'] = $g;
  504    $optional_graphs_data[$g]['graph_args'] = $graph_args;
  505  }
  506  $data->assign('optional_graphs_data', $optional_graphs_data);
  507 }
  508 
  509 function get_load_heatmap($hosts_up, $host_regex, $metrics, $data, $sort) {
  510   foreach ($hosts_up as $host => $val) {
  511     // If host_regex is defined
  512     if (isset($host_regex) && 
  513         ! preg_match("/" . $host_regex . "/", $host))
  514       continue;
  515     
  516     $load = get_load($host, $metrics);
  517     $host_load[$host] = $load;
  518   }
  519 
  520   $num_hosts = count($host_load);
  521   if ($num_hosts == 0)
  522     return;
  523 
  524   switch ($sort) {
  525   case "descending":
  526     arsort($host_load);
  527     break;
  528   case "by name":
  529     uksort($host_load, "strnatcmp");
  530     break;
  531   default:
  532   case "ascending":
  533     asort($host_load);
  534     break;
  535   }
  536 
  537   $num_cols = ceil(sqrt($num_hosts));
  538 
  539   $col_index = 0;
  540   $row_index = 0;
  541   $heatmap = '[';
  542   foreach ($host_load as $host => $load) {
  543     if ($col_index == 0) {
  544       if ($row_index > 0)
  545     $heatmap .= ',';
  546       $heatmap .= '[';
  547     }
  548     
  549     if ($col_index > 0)
  550       $heatmap .= ',';
  551 
  552     $heatmap .= "{host:\"$host\",load:$load}";
  553 
  554     if ($col_index == $num_cols - 1) {
  555       $heatmap .= ']';
  556       $col_index = 0;
  557       $row_index++;
  558     } else
  559       $col_index++;
  560   }
  561 
  562   if ($col_index != 0) {
  563     for ($i = 0; $i < ($num_cols * $num_cols - $num_hosts); $i++) {
  564       $heatmap .= ",{host:\"unused\",load:0}";
  565     }
  566     $heatmap .= ']';
  567   }
  568 
  569   $heatmap .= ']';
  570 
  571   $data->assign("heatmap_data", $heatmap);
  572 }
  573 
  574 $fn = "cluster_" . ($refresh ? "refresh" : "view") . ".tpl";
  575 $tpl = new Dwoo_Template_File(template($fn));
  576 
  577 $data = new Dwoo_Data();
  578 
  579 if (! $refresh) {
  580   $data->assign("php_gd", 
  581         (function_exists('imagegif') or function_exists('imagepng')));
  582   
  583   $data->assign("extra", template("cluster_extra.tpl"));
  584   
  585   $data->assign("user_may_edit", 
  586         checkAccess( $clustername, GangliaAcl::EDIT, $conf ) );
  587   
  588   $data->assign("graph_engine", $conf['graph_engine']);
  589  }
  590 
  591 $data->assign("cluster", $clustername);
  592 
  593 $data->assign("localtimestamp", $cluster['LOCALTIME']);
  594 
  595 $data->assign("localtime", date("Y-m-d H:i", $cluster['LOCALTIME']));
  596 
  597 get_cluster_overview($showhosts, 
  598              $metrics,
  599              $cluster,
  600              $range, 
  601              $clustername, 
  602              $data);
  603 
  604 $user_metricname = $user['metricname'];
  605 if (!$showhosts) {
  606   if (array_key_exists($user_metricname, $metrics))
  607     $units = $metrics[$user_metricname]['UNITS'];
  608 } else {
  609   if (array_key_exists($user_metricname, $metrics[key($metrics)]))
  610     if (isset($metrics[key($metrics)][$user_metricname]['UNITS']))
  611       $units = $metrics[key($metrics)][$user_metricname]['UNITS'];
  612     else
  613       $units = '';
  614 }
  615 
  616 if (isset($units))
  617   $vlabel = $units;
  618 
  619 if (! $refresh) {
  620   get_cluster_optional_reports($conf, 
  621                    $clustername, 
  622                    $get_metric_string,
  623                    $cluster[LOCALTIME],
  624                    $data);
  625   
  626   //////////////////////////////////////////////////////////////////////////////
  627   // Begin Host Display Controller
  628   //////////////////////////////////////////////////////////////////////////////
  629   
  630   // Correctly handle *_report cases and blank (" ") units
  631   
  632   if (isset($units)) {
  633     if ($units == " ")
  634       $units = "";
  635     else
  636       $units = $units ? "($units)" : "";
  637   } else {
  638     $units = "";
  639   }
  640   $data->assign("metric","{$user['metricname']} $units");
  641   $data->assign("metric_name","{$user['metricname']}");
  642   $data->assign("sort", $sort);
  643   $data->assign("range", $range);
  644   
  645   $showhosts_levels = array(2 => array('checked'=>'', 'name'=>'Auto'),
  646                 1 => array('checked'=>'', 'name'=>'Same'),
  647                 0 => array('checked'=>'', 'name'=>'None'),
  648                 );
  649   $showhosts_levels[$showhosts]['checked'] = 'checked';
  650   $data->assign("showhosts_levels", $showhosts_levels);
  651   
  652   if ($showhosts) {
  653     $data->assign("columns_size_dropdown", 1);
  654     $data->assign("cols_menu", $cols_menu);
  655     $data->assign("size_menu", $size_menu);
  656   }
  657 
  658   if (isset($user['host_regex']) && $user['host_regex'] != "")
  659     $set_host_regex_value = "value='" . htmlentities($user['host_regex'], ENT_QUOTES) . "'";
  660   else
  661     $set_host_regex_value = "";
  662 
  663   // In some clusters you may have thousands of hosts which may load
  664   // for a long time. For those cases we have the ability to display
  665   // only the max amount of graphs and put place holders for the rest ie.
  666   // it will say only print host name without an image
  667   $max_graphs_options = array(1000,500,200,100,50,25,20,15,10);
  668 
  669   if (isset($user['max_graphs']) && is_numeric($user['max_graphs']))
  670     $max_graphs = $user['max_graphs'];
  671   else
  672     $max_graphs = $conf['max_graphs'];
  673   
  674   $max_graphs_values = "<option value=0>all</option>";
  675   foreach ($max_graphs_options as $value) {
  676     if ($max_graphs == $value)
  677       $max_graphs_values .= "<option selected>" . $value . "</option>";
  678     else
  679       $max_graphs_values .= "<option>" . $value . "</option>";
  680   }
  681 
  682   $data->assign("additional_filter_options", "");
  683   if ($showhosts) {
  684     $data->assign("additional_filter_options", 
  685           'Show only nodes matching <input name=host_regex ' . 
  686           $set_host_regex_value . '>' . 
  687           '<input class="header_btn" type="SUBMIT" VALUE="Filter">' .
  688           '<div style="display:inline;padding-left:10px;" class="nobr">Max graphs to show <select onChange="ganglia_submit();" name="max_graphs">' . 
  689           $max_graphs_values . 
  690           '</select></div>' .
  691           '<div style="display:inline;padding-left:10px;" class="nobr">' .
  692           make_sort_menu($context, $sort) .
  693           '</div>');
  694   } 
  695 
  696   //////////////////////////////////////////////////////////////////////////////
  697   // End Host Display Controller
  698   //////////////////////////////////////////////////////////////////////////////
  699  }
  700 
  701 if ((count($hosts_up) == 0) ||
  702     !(isset($conf['heatmaps_enabled']) and $conf['heatmaps_enabled'] == 1))
  703   get_load_pie($showhosts, 
  704            $hosts_up, 
  705            $hosts_down, 
  706            $user, 
  707            $conf,
  708            $metrics, 
  709            $cluster,
  710            $name,
  711            $data);
  712 
  713 if ($showhosts != 0)
  714   get_host_metric_graphs($showhosts,
  715              $hosts_up, 
  716              $hosts_down, 
  717              $user, 
  718              $conf,
  719              $metrics, 
  720              $user['metricname'],
  721              $sort,
  722              $clustername,
  723              $get_metric_string,
  724              $cluster,
  725              $always_timestamp,
  726              $reports[$user['metricname']],
  727              $clustergraphsize,
  728              $range,
  729              $start,
  730              $end,
  731              $cs,
  732              $ce,
  733              $vlabel,
  734              $data);
  735 
  736 ///////////////////////////////////////////////////////////////////////////////
  737 // Creates a heatmap
  738 ///////////////////////////////////////////////////////////////////////////////
  739 if (isset($conf['heatmaps_enabled']) and 
  740     $conf['heatmaps_enabled'] == 1 and
  741     (count($hosts_up) > 0))
  742   get_load_heatmap($hosts_up, $user['host_regex'], $metrics, $data, $sort);
  743 
  744 $data->assign("conf", $conf);
  745 $data->assign("showhosts", $showhosts);
  746 
  747 // No reason to go on if we are not displaying individual hosts
  748 if (!is_array($hosts_up) or !$showhosts) {
  749   $dwoo->output($tpl, $data);
  750   return;
  751 }
  752 
  753 ///////////////////////////////////////////////////////////////////////////////
  754 // Show stacked graphs
  755 ///////////////////////////////////////////////////////////////////////////////
  756 if (isset($conf['show_stacked_graphs']) and 
  757     $conf['show_stacked_graphs'] == 1  and 
  758     ! preg_match("/_report$/", $user['metricname'])) {
  759   $cluster_url = rawurlencode($clustername);
  760   $stacked_args = "m={$user['metricname']}&amp;c=$cluster_url&amp;r=$range&amp;st=$cluster[LOCALTIME]";
  761   if (isset($user['host_regex']))
  762     $stacked_args .= "&amp;host_regex=" . $user['host_regex'];
  763   $data->assign("stacked_graph_args", $stacked_args);
  764 }
  765 
  766 if ($conf['picker_autocomplete'] == true) {
  767   $data->assign('picker_autocomplete', true);
  768 } else {
  769   $picker_metrics = get_picker_metrics($metrics, 
  770                        $reports,
  771                        $conf['gweb_root'], 
  772                        $conf['graph_engine']);
  773   if ($picker_metrics != NULL)
  774     $data->assign("picker_metrics", join("", $picker_metrics));
  775 }
  776 
  777 $dwoo->output($tpl, $data);
  778 ?>