Add support for memcached to poller for current bps/pps for ports and ability to disable writing these values to MySQL. HIGHLY RECOMMENDED FOR LARGE INSTALLS. Also PROCEED WITH CAUTION.

git-svn-id: http://www.observium.org/svn/observer/trunk@2955 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2012-04-04 18:10:45 +00:00
parent d16f4b30ae
commit e44c47cabd
5 changed files with 87 additions and 22 deletions

View File

@@ -8,6 +8,11 @@ $config['db_user'] = "USERNAME";
$config['db_pass'] = "PASSWORD";
$config['db_name'] = "observium";
### Memcached config - We use this to store realtime usage
$config['memcached']['enable'] = FALSE;
$config['memcached']['host'] = "localhost";
$config['memcached']['port'] = 11211;
### Locations
$config['install_dir'] = "/opt/observium";
$config['html_dir'] = $config['install_dir'] . "/html";

View File

@@ -37,6 +37,16 @@ $config['unflatten'] = "/usr/bin/unflatten";
$config['neato'] = "/usr/bin/neato";
$config['sfdp'] = "/usr/bin/sfdp";
### Memcached - Keep immediate statistics
$config['memcached']['enable'] = FALSE;
$config['memcached']['host'] = "localhost";
$config['memcached']['port'] = 11211;
$config['slow_statistics'] = TRUE; ### THIS WILL CHANGE TO FALSE IN FUTURE
### RRDCacheD - Make sure it can write to your RRD dir!
#$config['rrdcached'] = "unix:/var/run/rrdcached.sock";

View File

@@ -87,7 +87,7 @@ function poll_sensor($device, $class, $unit)
function poll_device($device, $options)
{
global $config, $device, $polled_devices, $db_stats;
global $config, $device, $polled_devices, $db_stats, $memcache;
$attribs = get_dev_attribs($device['device_id']);

View File

@@ -160,12 +160,29 @@ foreach ($ports as $port)
$this_port = &$port_stats[$port['ifIndex']];
if ($device['os'] == "vmware" && preg_match("/Device ([a-z0-9]+) at .*/", $this_port['ifDescr'], $matches)) { $this_port['ifDescr'] = $matches[1]; }
if($config['memcached']['enable'])
{
$port['poll_time'] = $memcache->get('port-'.$port['interface_id'].'-poll_time');
# echo("time".$port['poll_time']);
}
$polled_period = $polled - $port['poll_time'];
$port['update'] = array();
$port['update']['poll_time'] = $polled;
$port['update']['poll_prev'] = $port['poll_time'];
$port['update']['poll_period'] = $polled_period;
if($config['slow_statistics'] == TRUE) {
$port['update']['poll_time'] = $polled;
$port['update']['poll_prev'] = $port['poll_time'];
$port['update']['poll_period'] = $polled_period;
}
if($config['memcached']['enable'])
{
$memcache->set('port-'.$port['interface_id'].'-poll_time', $polled);
$memcache->set('port-'.$port['interface_id'].'-poll_prev', $port['poll_time']);
$memcache->set('port-'.$port['interface_id'].'-poll_period', $polled_period);
}
/// Copy ifHC[In|Out]Octets values to non-HC if they exist
if ($this_port['ifHCInOctets'] > 0 && is_numeric($this_port['ifHCInOctets']) && $this_port['ifHCOutOctets'] > 0 && is_numeric($this_port['ifHCOutOctets']))
@@ -262,24 +279,56 @@ foreach ($ports as $port)
/// Update IF-MIB metrics
foreach ($stat_oids_db as $oid)
{
$port['update'][$oid] = $this_port[$oid];
$port['update'][$oid.'_prev'] = $port[$oid];
# echo("\n".$oid.":");
if($config['slow_statistics'] == TRUE) {
$port['update'][$oid] = $this_port[$oid];
$port['update'][$oid.'_prev'] = $port[$oid];
}
if($config['memcached']['enable'])
{
$port[$oid] = $memcache->get('port-'.$port['interface_id'].'-'.$oid);
$memcache->set('port-'.$port['interface_id'].'-'.$oid, $this_port[$oid]);
$memcache->set('port-'.$port['interface_id'].'-'.$oid.'_prev', $port[$oid]);
# echo("MEMCACHE!");
}
# echo(" old[".$port[$oid]."]");
# echo(" new[".$this_port[$oid]."]");
$oid_prev = $oid . "_prev";
if ($port[$oid])
if (isset($port[$oid]))
{
$oid_diff = $this_port[$oid] - $port[$oid];
# echo(" diff[".$oid_diff."]");
$oid_rate = $oid_diff / $polled_period;
# echo(" rate[".$oid_rate."]");
if ($oid_rate < 0) { $oid_rate = "0"; echo("negative $oid"); }
$port['update'][$oid.'_rate'] = $oid_rate;
$port['update'][$oid.'_delta'] = $oid_diff;
$port['stats'][$oid.'_rate'] = $oid_rate;
$port['stats'][$oid.'_diff'] = $oid_diff;
if($config['slow_statistics'] == TRUE) {
$port['update'][$oid.'_rate'] = $oid_rate;
$port['update'][$oid.'_delta'] = $oid_diff;
}
if($config['memcached']['enable'])
{
$memcache->set('port-'.$port['interface_id'].'-'.$oid.'_rate', $oid_rate);
$memcache->set('port-'.$port['interface_id'].'-'.$oid.'_delta', $oid_diff);
# echo($oid."[".$oid_rate."]");
}
if ($debug) {echo("\n $oid ($oid_diff B) $oid_rate Bps $polled_period secs\n"); }
}
}
$port['ifInBits_rate'] = $port['update']['ifInOctets_rate'] * 8;
$port['ifOutBits_rate'] = $port['update']['ifOutOctets_rate'] * 8;
echo('bits('.formatRates($port['ifInBits_rate']).'/'.formatRates($port['ifOutBits_rate']).')');
echo('pkts('.format_si($port['update']['ifInUcastPkts_rate']).'pps/'.format_si($port['update']['ifOutUcastPkts_rate']).'pps)');
$port['stats']['ifInBits_rate'] = $port['stats']['ifInOctets_rate'] * 8;
$port['stats']['ifOutBits_rate'] = $port['stats']['ifOutOctets_rate'] * 8;
echo('bps('.formatRates($port['stats']['ifInBits_rate']).'/'.formatRates($port['stats']['ifOutBits_rate']).')');
echo('bytes('.formatStorage($port['stats']['ifInOctets_diff']).'/'.formatStorage($port['stats']['ifOutOctets_diff']).')');
echo('pkts('.format_si($port['stats']['ifInUcastPkts_rate']).'pps/'.format_si($port['stats']['ifOutUcastPkts_rate']).'pps)');
### Port utilisation % threshold alerting. ## Fixme allow setting threshold per-port. probably 90% of ports we don't care about.
if($config['alerts']['port_util_alert'])
@@ -287,11 +336,11 @@ foreach ($ports as $port)
// Check for port saturation of $config['alerts']['port_util_perc'] or higher. Alert if we see this.
// Check both inbound and outbound rates
$saturation_threshold = $this_port['ifSpeed'] * ( $config['alerts']['port_util_perc'] / 100 );
echo("IN: " . $port['ifInBits_rate'] . " OUT: " . $port['ifOutBits_rate'] . " THRESH: " . $saturation_threshold);
if (($port['ifInBits_rate'] >= $saturation_threshold || $port['ifOutBits_rate'] >= $saturation_threshold) && $saturation_threshold > 0)
echo("IN: " . $port['stats']['ifInBits_rate'] . " OUT: " . $port['stats']['ifOutBits_rate'] . " THRESH: " . $saturation_threshold);
if (($port['stats']['ifInBits_rate'] >= $saturation_threshold || $port['stats']['ifOutBits_rate'] >= $saturation_threshold) && $saturation_threshold > 0)
{
log_event('Port reached saturation threshold: ' . formatRates($port['ifInBits_rate']) . '/' . formatRates($port['ifOutBits_rate']) . ' - ifspeed: ' . formatRates( $this_port['ifSpeed']) , $device, 'interface', $port['interface_id']);
notify($device, 'Port saturation threshold reached on ' . $device['hostname'] , 'Port saturation threshold alarm: ' . $device['hostname'] . ' on ' . $port['ifDescr'] . "\nRates:" . formatRates($port['ifInBits_rate']) . '/' . formatRates($port['ifOutBits_rate']) . ' - ifspeed: ' . formatRates( $this_port['ifSpeed']) . "\nTimestamp: " . date($config['timestamp_format']));
log_event('Port reached saturation threshold: ' . formatRates($port['stats']['ifInBits_rate']) . '/' . formatRates($port['stats']['ifOutBits_rate']) . ' - ifspeed: ' . formatRates( $this_port['stats']['ifSpeed']) , $device, 'interface', $port['interface_id']);
notify($device, 'Port saturation threshold reached on ' . $device['hostname'] , 'Port saturation threshold alarm: ' . $device['hostname'] . ' on ' . $port['ifDescr'] . "\nRates:" . formatRates($port['stats']['ifInBits_rate']) . '/' . formatRates($port['stats']['ifOutBits_rate']) . ' - ifspeed: ' . formatRates( $this_port['ifSpeed']) . "\nTimestamp: " . date($config['timestamp_format']));
}
}

View File

@@ -1125,11 +1125,12 @@ if (!$observium_link)
}
$observium_db = mysql_select_db($config['db_name'], $observium_link);
#try {
# $db = new PDO('mysql:host='.$config['db_host'].';dbname='.$config['db_name'], $config['db_user'], $config['db_pass']);
#} catch (PDOException $e) {
# print "Error!: " . $e->getMessage() . "<br/>";
#}
if($config['memcached']['enable'])
{
$memcache = new Memcached();
$memcache->addServer($config['memcached']['host'], $config['memcached']['port']);
if($debug) { print_r($memcache->getStats()); }
}
# Set some times needed by loads of scripts (it's dynamic, so we do it here!)