function retrieve_metrics_cache() { global $conf, $index_array, $hosts, $grid, $clusters, $debug, $metrics, $context; if ($conf['cachedata'] == 1 && file_exists($conf['cachefile'])) { // check for the cached file // snag it and return it if it is still fresh $time_diff = time() - filemtime($conf['cachefile']); $expires_in = $conf['cachetime'] - $time_diff; if ($time_diff < $conf['cachetime']) { if ($debug == 1) { echo "DEBUG: Fetching data from cache. Expires in " . $expires_in . " seconds.\n"; } $index_array = unserialize(file_get_contents($conf['cachefile'])); } } if (!isset($index_array) || sizeof($index_array) == 0) { if ($debug == 1) { echo "DEBUG: Querying GMond for new data\n"; } // Set up for cluster summary $context = "index_array"; include_once $conf['gweb_root'] . "/ganglia.php"; Gmetad($conf['ganglia_ip'], $conf['ganglia_port']); foreach ($index_array['cluster'] as $hostname => $elements) { $hosts[] = $hostname; } asort($hosts); $index_array['hosts'] = $hosts; file_put_contents($conf['cachefile'], serialize($index_array)); } }
# Retrieves and parses the XML output from gmond. Results stored # in global variables: $clusters, $hosts, $hosts_down, $metrics. # Assumes you have already called get_context.php. # # If we are in compare_hosts, views and decompose_graph context we shouldn't attempt # any connections to the gmetad if (in_array($context, $SKIP_GMETAD_CONTEXTS)) { } else { if (!Gmetad($conf['ganglia_ip'], $conf['ganglia_port'])) { print "<H4>There was an error collecting ganglia data " . "({$conf['ganglia_ip']}:{$conf['ganglia_port']}): {$error}</H4>\n"; exit; } # If we have no child data sources, assume something is wrong. if (!count($grid) and !count($cluster)) { print "<H4>Ganglia cannot find a data source. Is gmond running?</H4>"; exit; } # If we only have one cluster source, suppress MetaCluster output. if (count($grid) < 2 and $context == "meta") { # Lets look for one cluster (the other is our grid). foreach ($grid as $source) { if (isset($source['CLUSTER']) and $source['CLUSTER']) { $standalone = 1; $context = "cluster"; # Need to refresh data with new context. Gmetad($conf['ganglia_ip'], $conf['ganglia_port']); $clustername = $source['NAME']; } } } }
<?php # $Id$ # Retrieves and parses the XML output from gmond. Results stored # in global variables: $clusters, $hosts, $hosts_down, $metrics. # Assumes you have already called get_context.php. # if (!Gmetad($ganglia_ip, $ganglia_port)) { print "<H4>There was an error collecting ganglia data " . "({$ganglia_ip}:{$ganglia_port}): {$error}</H4>\n"; exit; } # If we have no child data sources, assume something is wrong. if (!count($grid) and !count($cluster)) { print "<H4>Ganglia cannot find a data source. Is gmond running?</H4>"; exit; } # If we only have one cluster source, suppress MetaCluster output. if (count($grid) <= 2 and $context == "meta") { # Lets look for one cluster (the other is our grid). foreach ($grid as $source) { if (isset($source['CLUSTER']) and $source['CLUSTER']) { $standalone = 1; $context = "cluster"; # Need to refresh data with new context. Gmetad($ganglia_ip, $ganglia_port); $clustername = $source['NAME']; } } }