function get_host_metric_graphs($showhosts, $hosts_up, $hosts_down, $user, $conf, $metrics, $metricname, $sort, $clustername, $get_metric_string, $cluster, $always_timestamp, $reports_metricname, $clustergraphsize, $range, $start, $end, $cs, $ce, $vlabel, $data) { $sorted_hosts = array(); $down_hosts = array(); if ($showhosts == 0) { return; } foreach ($hosts_up as $host => $val) { // If host_regex is defined if (isset($user['host_regex']) && !preg_match("/" . $user['host_regex'] . "/", $host)) { continue; } $load = get_load($host, $metrics); $host_load[$host] = $load; if ($metricname == "load_one") { $sorted_hosts[$host] = $load; } else { if (isset($metrics[$host][$metricname])) { $sorted_hosts[$host] = $metrics[$host][$metricname]['VAL']; } else { $sorted_hosts[$host] = ""; } } } // foreach hosts_up foreach ($hosts_down as $host => $val) { $down_hosts[$host] = -1.0; } $data->assign("node_legend", 1); if (!is_array($hosts_up)) { return; } switch ($sort) { case "descending": arsort($sorted_hosts); break; case "by name": uksort($sorted_hosts, "strnatcmp"); break; default: case "ascending": asort($sorted_hosts); break; } $sorted_hosts = array_merge($down_hosts, $sorted_hosts); if (isset($user['max_graphs'])) { $max_graphs = $user['max_graphs']; } else { $max_graphs = $conf['max_graphs']; } // First pass to find the max value in all graphs for this // metric. The $start,$end variables comes from get_context.php, // included in index.php. // Do this only if person has not selected a maximum set of graphs to display if ($max_graphs == 0 && $showhosts == 1) { $cs = $user['cs']; if ($cs and (is_numeric($cs) or strtotime($cs))) { $start = $cs; } $ce = $user['ce']; if ($ce and (is_numeric($ce) or strtotime($ce))) { $end = $ce; } list($min, $max) = find_limits($clustername, $sorted_hosts, $metricname, $start, $end, $metrics, $conf, $rrd_options); } // Second pass to output the graphs or metrics. $i = 1; // Initialize overflow list $overflow_list = array(); $overflow_counter = 1; $cluster_url = rawurlencode($clustername); $size = isset($clustergraphsize) ? $clustergraphsize : 'small'; if ($conf['hostcols'] == 0) { // enforce small size in multi-host report $size = 'small'; } // set host zoom class based on the size of the graph shown if (isset($conf['zoom_support']) && $conf['zoom_support'] === true) { $additional_host_img_html_args = "class=host_{$size}_zoomable"; } foreach ($sorted_hosts as $host => $value) { if (isset($hosts_down[$host]) and $hosts_down[$host] && isset($conf['cluster_hide_down_hosts']) && $conf['cluster_hide_down_hosts']) { // If we're hiding DOWN hosts, we skip to next iteration of the loop. continue; } $host_url = $case_sensitive_hostnames ? rawurlencode($host) : strtolower(rawurlencode($host)); $host_link = "\"?c={$cluster_url}&h={$host_url}&{$get_metric_string}\""; $textval = ""; //echo "$host: $value, "; if (isset($hosts_down[$host]) and $hosts_down[$host]) { $last_heartbeat = $cluster['LOCALTIME'] - $hosts_down[$host]['REPORTED']; $age = $last_heartbeat > 3600 ? uptime($last_heartbeat) : "{$last_heartbeat}s"; $class = "down"; $textval = "down <br> <font size=\"-2\">Last heartbeat {$age} ago</font>"; } else { if (isset($metrics[$host][$metricname])) { $val = $metrics[$host][$metricname]; } else { $val = NULL; } $class = "metric"; if ($val['TYPE'] == "timestamp" or isset($always_timestamp[$metricname]) and $always_timestamp[$metricname]) { $textval = date("r", $val['VAL']); } elseif ($val['TYPE'] == "string" or $val['SLOPE'] == "zero" or (isset($always_constant[$metricname]) and $always_constant[$metricname] or $max_graphs > 0 and $i > $max_graphs)) { if (isset($reports_metricname) and $reports_metricname) { // No "current" values available for reports $textval = "N/A"; } else { $textval = "{$val['VAL']}"; } if (isset($val['UNITS'])) { $textval .= " {$val['UNITS']}"; } } } $graphargs = "z={$size}&c={$cluster_url}&h={$host_url}"; if (isset($host_load[$host])) { $load_color = load_color($host_load[$host]); $graphargs .= "&l={$load_color}&v={$val['VAL']}"; } $graphargs .= "&r={$range}&su=1&st={$cluster['LOCALTIME']}"; if ($cs) { $graphargs .= "&cs=" . rawurlencode($cs); } if ($ce) { $graphargs .= "&ce=" . rawurlencode($ce); } // If we want scaling to be the same in clusterview we need to set // $max and $min values if ($showhosts == 1 && $max_graphs == 0) { $graphargs .= "&x={$max}&n={$min}"; } if (isset($vlabel)) { $graphargs .= "&vl=" . urlencode($vlabel); } if ($textval) { $cell = "<td class={$class}>" . "<b><a href={$host_link}>{$host}</a></b><br>" . "<i>{$metricname}:</i> <b>{$textval}</b></td>"; } else { $cell = "<td><div><font style='font-size: 8px'>{$host}</font><br><a href={$host_link}><img {$additional_host_img_html_args} src=\"./graph.php?"; $cell .= (isset($reports_metricname) and $reports_metricname) ? "g={$metricname}" : "m={$metricname}"; $cell .= "&{$graphargs}\" title=\"{$host}\" border=0 style=\"padding:2px;\"></a></div></td>"; } if ($conf['hostcols'] == 0) { $pre = "<td><a href={$host_link}><img src=\"./graph.php?g="; $post = "&{$graphargs}\" {$additional_host_img_html_args} title=\"{$host}\" border=0 style=\"padding:2px;\"></a></td>"; $cell .= $pre . "load_report" . $post; $cell .= $pre . "mem_report" . $post; $cell .= $pre . "cpu_report" . $post; $cell .= $pre . "network_report" . $post; } // Check if max_graphs is set. // If it put cells in an overflow list since that one is hidden by default if ($max_graphs > 0 and $i > $max_graphs) { $overflow_list[$host]["metric_image"] = $cell; if (!($overflow_counter++ % $conf['hostcols'])) { $overflow_list[$host]["br"] = "</tr><tr>"; } else { $overflow_list[$host]["br"] = ""; } } else { $sorted_list[$host]["metric_image"] = $cell; if (!($i++ % $conf['hostcols'])) { $sorted_list[$host]["br"] = "</tr><tr>"; } else { $sorted_list[$host]["br"] = ""; } } // end of if ($max_graphs > 0 and $i > $max_graphs ) { } // foreach sorted_hosts $data->assign("sorted_list", $sorted_list); // If there is an overflow list. These are hosts for which we don't show graphs // just names if (count($overflow_list) > 0) { $data->assign("overflow_list_header", '<p><table width=80%><tr><td align=center class=metric> <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 (' . ($overflow_counter - 1) . ')</a> </td></tr></table> <div style="display: none;" id="overflow_list"><table> <tr> '); $data->assign("overflow_list_footer", "</div></tr></table></div>"); } else { $data->assign("overflow_list_header", ""); $data->assign("overflow_list_footer", ""); } $data->assign("overflow_list", $overflow_list); }
case "descending": arsort($sorted_hosts); break; case "by name": uksort($sorted_hosts, "strnatcmp"); break; default: case "ascending": asort($sorted_hosts); break; } $sorted_hosts = array_merge($down_hosts, $sorted_hosts); # First pass to find the max value in all graphs for this # metric. The $start,$end variables comes from get_context.php, # included in index.php. list($min, $max) = find_limits($sorted_hosts, $metricname); # Second pass to output the graphs or metrics. $i = 1; foreach ($sorted_hosts as $host => $value) { $host_url = rawurlencode($host); $host_link = "\"?c={$cluster_url}&h={$host_url}&{$get_metric_string}\""; $textval = ""; #echo "$host: $value, "; if (isset($hosts_down[$host]) and $hosts_down[$host]) { $last_heartbeat = $cluster['LOCALTIME'] - $hosts_down[$host]['REPORTED']; $age = $last_heartbeat > 3600 ? uptime($last_heartbeat) : "{$last_heartbeat}s"; $class = "down"; $textval = "down <br> <font size=\"-2\">Last heartbeat {$age} ago</font>"; } else { if (isset($metrics[$host][$metricname])) { $val = $metrics[$host][$metricname];