Skip to content
Snippets Groups Projects
Commit 6778ae6a authored by Nigel Kukard's avatar Nigel Kukard
Browse files

Reworked statistics plugin against new API

parent 46d67b77
No related branches found
No related tags found
No related merge requests found
# OpenTrafficShaper Traffic shaping statistics # OpenTrafficShaper Traffic shaping statistics
# Copyright (C) 2007-2013, AllWorldIT # Copyright (C) 2007-2014, AllWorldIT
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
...@@ -21,7 +21,6 @@ package opentrafficshaper::plugins::statistics; ...@@ -21,7 +21,6 @@ package opentrafficshaper::plugins::statistics;
use strict; use strict;
use warnings; use warnings;
use DBI; use DBI;
use POE; use POE;
...@@ -30,15 +29,15 @@ use opentrafficshaper::logger; ...@@ -30,15 +29,15 @@ use opentrafficshaper::logger;
use opentrafficshaper::utils; use opentrafficshaper::utils;
use opentrafficshaper::plugins::configmanager qw( use opentrafficshaper::plugins::configmanager qw(
getLimit getPool
getLimits getPools
getLimitUsername
getLimitTxInterface getPoolTxInterface
getLimitRxInterface getPoolRxInterface
getPoolTrafficClassID
getTrafficClasses getTrafficClasses
getAllTrafficClasses
); );
# NK: TODO: Maybe we want to remove timing at some stage? maybe not? # NK: TODO: Maybe we want to remove timing at some stage? maybe not?
...@@ -65,7 +64,7 @@ our (@ISA,@EXPORT,@EXPORT_OK); ...@@ -65,7 +64,7 @@ our (@ISA,@EXPORT,@EXPORT_OK);
); );
use constant { use constant {
VERSION => '0.1.1', VERSION => '0.2.2',
# How often our config check ticks # How often our config check ticks
TICK_PERIOD => 5, TICK_PERIOD => 5,
...@@ -144,43 +143,37 @@ sub plugin_init ...@@ -144,43 +143,37 @@ sub plugin_init
# Setup our environment # Setup our environment
$logger = $globals->{'logger'}; $logger = $globals->{'logger'};
$logger->log(LOG_NOTICE,"[STATISTICS] OpenTrafficShaper Statistics v".VERSION." - Copyright (c) 2013, AllWorldIT"); $logger->log(LOG_NOTICE,"[STATISTICS] OpenTrafficShaper Statistics v%s - Copyright (c) 2007-2014, AllWorldIT",VERSION);
# Check our interfaces # Check our interfaces
if (defined(my $dbdsn = $globals->{'file.config'}->{'plugin.statistics'}->{'db_dsn'})) { if (defined(my $dbdsn = $globals->{'file.config'}->{'plugin.statistics'}->{'db_dsn'})) {
$logger->log(LOG_INFO,"[STATISTICS] Set db_dsn to '$dbdsn'"); $logger->log(LOG_INFO,"[STATISTICS] Set db_dsn to '%s'",$dbdsn);
$config->{'db_dsn'} = $dbdsn; $config->{'db_dsn'} = $dbdsn;
} else { } else {
$logger->log(LOG_WARN,"[STATISTICS] No db_dsn to specified in configuration file. Stats storage disabled!"); $logger->log(LOG_WARN,"[STATISTICS] No db_dsn to specified in configuration file. Stats storage disabled!");
} }
if (defined(my $dbuser = $globals->{'file.config'}->{'plugin.statistics'}->{'db_username'})) { if (defined(my $dbuser = $globals->{'file.config'}->{'plugin.statistics'}->{'db_username'})) {
$logger->log(LOG_INFO,"[STATISTICS] Set db_username to '$dbuser'"); $logger->log(LOG_INFO,"[STATISTICS] Set db_username to '%s'",$dbuser);
$config->{'db_username'} = $dbuser; $config->{'db_username'} = $dbuser;
} }
if (defined(my $dbpass = $globals->{'file.config'}->{'plugin.statistics'}->{'db_password'})) { if (defined(my $dbpass = $globals->{'file.config'}->{'plugin.statistics'}->{'db_password'})) {
$logger->log(LOG_INFO,"[STATISTICS] Set db_password to '$dbpass'"); $logger->log(LOG_INFO,"[STATISTICS] Set db_password to '%s'",$dbpass);
$config->{'db_password'} = $dbpass; $config->{'db_password'} = $dbpass;
} }
# This is our main stats session # This is our main stats session
POE::Session->create( POE::Session->create(
inline_states => { inline_states => {
_start => \&session_start, _start => \&_session_start,
_stop => \&session_stop, _stop => \&_session_stop,
_tick => \&_session_tick,
tick => \&session_tick,
db_ready => \&do_db_ready,
db_notready => \&do_db_notready,
db_query_success => \&do_db_query_success,
db_query_failure => \&do_db_query_failure,
# Stats update event # Stats update event
update => \&do_update, update => \&_session_update,
# Subscription events # Subscription events
subscribe => \&do_subscribe, subscribe => \&_session_subscribe,
unsubscribe => \&do_unsubscribe, unsubscribe => \&_session_unsubscribe,
} }
); );
...@@ -191,7 +184,7 @@ sub plugin_init ...@@ -191,7 +184,7 @@ sub plugin_init
$config->{'db_dsn'}, $config->{'db_username'}, $config->{'db_password'}, $config->{'db_dsn'}, $config->{'db_username'}, $config->{'db_password'},
{ {
'AutoCommit' => 1, 'AutoCommit' => 1,
'RaiseError' => 1, 'RaiseError' => 0,
'FetchHashKeyName' => 'NAME_lc' 'FetchHashKeyName' => 'NAME_lc'
} }
); );
...@@ -221,8 +214,9 @@ sub plugin_init ...@@ -221,8 +214,9 @@ sub plugin_init
SELECT SELECT
`IdentifierID`, `Timestamp` - (`Timestamp` % ?) AS TimestampM, `IdentifierID`, `Timestamp` - (`Timestamp` % ?) AS TimestampM,
`Direction`, `Direction`,
MAX(`CIR`) AS `CIR`, MAX(`Limit`) AS `Limit`, MAX(`Rate`) AS `Rate`, MAX(`PPS`) AS `PPS`, MAX(`Queue_Len`) AS `Queue_Len`, MAX(`CIR`) AS `CIR`, MAX(`Limit`) AS `Limit`, MAX(`Rate`) AS `Rate`, MAX(`PPS`) AS `PPS`,
AVG(`Total_Bytes`) AS `Total_Bytes`, AVG(`Total_Packets`) AS `Total_Packets`, AVG(`Total_Overlimits`) AS `Total_Overlimits`, AVG(`Total_Dropped`) AS `Total_Dropped` MAX(`Queue_Len`) AS `Queue_Len`, AVG(`Total_Bytes`) AS `Total_Bytes`, AVG(`Total_Packets`) AS `Total_Packets`,
AVG(`Total_Overlimits`) AS `Total_Overlimits`, AVG(`Total_Dropped`) AS `Total_Dropped`
FROM FROM
stats stats
WHERE WHERE
...@@ -294,7 +288,7 @@ sub plugin_start ...@@ -294,7 +288,7 @@ sub plugin_start
# Initialize this plugins main POE session # Initialize this plugins main POE session
sub session_start sub _session_start
{ {
my ($kernel,$heap) = @_[KERNEL, HEAP]; my ($kernel,$heap) = @_[KERNEL, HEAP];
...@@ -303,14 +297,14 @@ sub session_start ...@@ -303,14 +297,14 @@ sub session_start
$kernel->alias_set("statistics"); $kernel->alias_set("statistics");
# Set delay on config updates # Set delay on config updates
$kernel->delay(tick => TICK_PERIOD); $kernel->delay('_tick' => TICK_PERIOD);
$logger->log(LOG_DEBUG,"[STATISTICS] Initialized"); $logger->log(LOG_DEBUG,"[STATISTICS] Initialized");
} }
# Stop session # Stop session
sub session_stop sub _session_stop
{ {
my ($kernel,$heap) = @_[KERNEL, HEAP]; my ($kernel,$heap) = @_[KERNEL, HEAP];
...@@ -335,7 +329,7 @@ sub session_stop ...@@ -335,7 +329,7 @@ sub session_stop
# Time ticker for processing changes # Time ticker for processing changes
sub session_tick sub _session_tick
{ {
my ($kernel,$heap) = @_[KERNEL,HEAP]; my ($kernel,$heap) = @_[KERNEL,HEAP];
...@@ -422,7 +416,11 @@ sub session_tick ...@@ -422,7 +416,11 @@ sub session_tick
# We only need stats if we did something, right? # We only need stats if we did something, right?
if ($numFlush) { if ($numFlush) {
my $timediff2 = tv_interval($timer1,$timer2); my $timediff2 = tv_interval($timer1,$timer2);
$logger->log(LOG_INFO,"[STATISTICS] Total stats flush time %s/%s records: %s",$numFlush,$maxFlush,sprintf('%.3fs',$timediff2)); $logger->log(LOG_INFO,"[STATISTICS] Total stats flush time %s/%s records: %s",
$numFlush,
$maxFlush,
sprintf('%.3fs',$timediff2)
);
} }
my $res; my $res;
...@@ -461,7 +459,9 @@ sub session_tick ...@@ -461,7 +459,9 @@ sub session_tick
} }
# If there was an error, make sure we report it # If there was an error, make sure we report it
} else { } else {
$logger->log(LOG_ERR,"[STATISTICS] Failed to execute stats_basic consolidation statement: %s",$sthStatsBasicConsolidate->errstr()); $logger->log(LOG_ERR,"[STATISTICS] Failed to execute stats_basic consolidation statement: %s",
$sthStatsBasicConsolidate->errstr()
);
} }
# And the normal stats... # And the normal stats...
$res = $sthStatsConsolidate->execute($precision,$prevKey,$consolidateUpTo); $res = $sthStatsConsolidate->execute($precision,$prevKey,$consolidateUpTo);
...@@ -478,7 +478,9 @@ sub session_tick ...@@ -478,7 +478,9 @@ sub session_tick
} }
# If there was an error, make sure we report it # If there was an error, make sure we report it
} else { } else {
$logger->log(LOG_ERR,"[STATISTICS] Failed to execute stats consolidation statement: %s",$sthStatsConsolidate->errstr()); $logger->log(LOG_ERR,"[STATISTICS] Failed to execute stats consolidation statement: %s",
$sthStatsConsolidate->errstr()
);
} }
# Set last cleanup to now # Set last cleanup to now
...@@ -487,8 +489,14 @@ sub session_tick ...@@ -487,8 +489,14 @@ sub session_tick
my $timerB = [gettimeofday]; my $timerB = [gettimeofday];
my $timediffB = tv_interval($timerA,$timerB); my $timediffB = tv_interval($timerA,$timerB);
$logger->log(LOG_INFO,"[STATISTICS] Stats consolidation time for key %s: %s (%s basic, %s normal), up to %s [%s]",$key, $logger->log(LOG_INFO,"[STATISTICS] Stats consolidation time for key %s: %s (%s basic, %s normal), up to %s [%s]",
sprintf('%.3fs',$timediffB),$numStatsBasicConsolidated,$numStatsConsolidated,$consolidateUpTo,scalar(localtime($consolidateUpTo))); $key,
sprintf('%.3fs',$timediffB),
$numStatsBasicConsolidated,
$numStatsConsolidated,
$consolidateUpTo,
scalar(localtime($consolidateUpTo))
);
} }
# Setup another timer # Setup another timer
...@@ -505,22 +513,30 @@ sub session_tick ...@@ -505,22 +513,30 @@ sub session_tick
if ($res = $sthStatsBasicCleanup->execute(0, $cleanUpTo)) { if ($res = $sthStatsBasicCleanup->execute(0, $cleanUpTo)) {
# We get 0E0 for 0 when none were removed # We get 0E0 for 0 when none were removed
if ($res ne "0E0") { if ($res ne "0E0") {
$logger->log(LOG_INFO,"[STATISTICS] Cleanup streamed stats_basic %s, up to %s [%s]",$res,$cleanUpTo, $logger->log(LOG_INFO,"[STATISTICS] Cleanup streamed stats_basic %s, up to %s [%s]",
scalar(localtime($cleanUpTo))); $res,
$cleanUpTo,
scalar(localtime($cleanUpTo))
);
} }
} else { } else {
$logger->log(LOG_ERR,"[STATISTICS] Failed to execute stats_basic cleanup statement: %s", $logger->log(LOG_ERR,"[STATISTICS] Failed to execute stats_basic cleanup statement: %s",
$sthStatsBasicCleanup->errstr()); $sthStatsBasicCleanup->errstr()
);
} }
# And the normal stats... # And the normal stats...
if ($res = $sthStatsCleanup->execute(0, $cleanUpTo)) { if ($res = $sthStatsCleanup->execute(0, $cleanUpTo)) {
# We get 0E0 for 0 when none were removed # We get 0E0 for 0 when none were removed
if ($res ne "0E0") { if ($res ne "0E0") {
$logger->log(LOG_INFO,"[STATISTICS] Cleanup streamed stats %s, up to %s [%s]",$res,$cleanUpTo, $logger->log(LOG_INFO,"[STATISTICS] Cleanup streamed stats %s, up to %s [%s]",
scalar(localtime($cleanUpTo))); $res,
$cleanUpTo,scalar(localtime($cleanUpTo))
);
} }
} else { } else {
$logger->log(LOG_ERR,"[STATISTICS] Failed to execute stats cleanup statement: %s",$sthStatsCleanup->errstr()); $logger->log(LOG_ERR,"[STATISTICS] Failed to execute stats cleanup statement: %s",
$sthStatsCleanup->errstr()
);
} }
# Loop and remove retained stats # Loop and remove retained stats
...@@ -532,22 +548,35 @@ sub session_tick ...@@ -532,22 +548,35 @@ sub session_tick
if ($res = $sthStatsBasicCleanup->execute($key, $cleanUpTo)) { if ($res = $sthStatsBasicCleanup->execute($key, $cleanUpTo)) {
# We get 0E0 for 0 when none were removed # We get 0E0 for 0 when none were removed
if ($res ne "0E0") { if ($res ne "0E0") {
$logger->log(LOG_INFO,"[STATISTICS] Cleanup key %s stats_basic %s, up to %s [%s]",$key,$res,$cleanUpTo, $logger->log(LOG_INFO,"[STATISTICS] Cleanup key %s stats_basic %s, up to %s [%s]",
scalar(localtime($cleanUpTo))); $key,
$res,
$cleanUpTo,
scalar(localtime($cleanUpTo))
);
} }
} else { } else {
$logger->log(LOG_ERR,"[STATISTICS] Failed to execute stats_basic cleanup statement for key %s: %s",$key, $logger->log(LOG_ERR,"[STATISTICS] Failed to execute stats_basic cleanup statement for key %s: %s",
$sthStatsBasicCleanup->errstr()); $key,
$sthStatsBasicCleanup->errstr()
);
} }
# And normal stats... # And normal stats...
if ($res = $sthStatsCleanup->execute($key, $cleanUpTo)) { if ($res = $sthStatsCleanup->execute($key, $cleanUpTo)) {
# We get 0E0 for 0 when none were removed # We get 0E0 for 0 when none were removed
if ($res ne "0E0") { if ($res ne "0E0") {
$logger->log(LOG_INFO,"[STATISTICS] Cleanup key %s stats %s, up to %s [%s]",$key,$res,$cleanUpTo, $logger->log(LOG_INFO,"[STATISTICS] Cleanup key %s stats %s, up to %s [%s]",
scalar(localtime($cleanUpTo))); $key,
$res,
$cleanUpTo,
scalar(localtime($cleanUpTo))
);
} }
} else { } else {
$logger->log(LOG_ERR,"[STATISTICS] Failed to execute stats cleanup statement for key %s: %s",$key,$sthStatsCleanup->errstr()); $logger->log(LOG_ERR,"[STATISTICS] Failed to execute stats cleanup statement for key %s: %s",
$key,
$sthStatsCleanup->errstr()
);
} }
} }
...@@ -556,7 +585,9 @@ sub session_tick ...@@ -556,7 +585,9 @@ sub session_tick
my $timer4 = [gettimeofday]; my $timer4 = [gettimeofday];
my $timediff4 = tv_interval($timer3,$timer4); my $timediff4 = tv_interval($timer3,$timer4);
$logger->log(LOG_INFO,"[STATISTICS] Stats cleanup time: %s",sprintf('%.3fs',$timediff4)); $logger->log(LOG_INFO,"[STATISTICS] Stats cleanup time: %s",
sprintf('%.3fs',$timediff4)
);
} }
# Check if we need to pull config manager stats # Check if we need to pull config manager stats
...@@ -567,7 +598,7 @@ sub session_tick ...@@ -567,7 +598,7 @@ sub session_tick
} }
# Set delay on config updates # Set delay on config updates
$kernel->delay(tick => TICK_PERIOD); $kernel->delay('_tick' => TICK_PERIOD);
} }
...@@ -576,7 +607,7 @@ sub session_tick ...@@ -576,7 +607,7 @@ sub session_tick
# main:$iface:all - Interface total stats # main:$iface:all - Interface total stats
# main:$iface:classes - Interface classified traffic # main:$iface:classes - Interface classified traffic
# main:$iface:besteffort - Interface best effort traffic # main:$iface:besteffort - Interface best effort traffic
sub do_update sub _session_update
{ {
my ($kernel, $statsData) = @_[KERNEL, ARG0]; my ($kernel, $statsData) = @_[KERNEL, ARG0];
...@@ -591,24 +622,24 @@ sub do_update ...@@ -591,24 +622,24 @@ sub do_update
# Handle subscriptions to updates # Handle subscriptions to updates
sub do_subscribe sub _session_subscribe
{ {
my ($kernel, $handler, $handlerEvent, $item) = @_[KERNEL, ARG0, ARG1, ARG2]; my ($kernel, $handler, $handlerEvent, $item) = @_[KERNEL, ARG0, ARG1, ARG2];
$logger->log(LOG_INFO,"[STATISTICS] Got subscription request from '$handler' for '$item' via event '$handlerEvent'"); $logger->log(LOG_INFO,"[STATISTICS] Got subscription request from '%s' for '%s' via event '%s'",$handler,$item,$handlerEvent);
$subscribers->{$item}->{$handler}->{$handlerEvent} = $item; $subscribers->{$item}->{$handler}->{$handlerEvent} = $item;
} }
# Handle unsubscribes # Handle unsubscribes
sub do_unsubscribe sub _session_unsubscribe
{ {
my ($kernel, $handler, $handlerEvent, $item) = @_[KERNEL, ARG0, ARG1, ARG2]; my ($kernel, $handler, $handlerEvent, $item) = @_[KERNEL, ARG0, ARG1, ARG2];
$logger->log(LOG_INFO,"[STATISTICS] Got unsubscription request for '$handler' regarding '$item'"); $logger->log(LOG_INFO,"[STATISTICS] Got unsubscription request for '%s' regarding '%s'",$handler,$item);
delete($subscribers->{$item}->{$handler}->{$handlerEvent}); delete($subscribers->{$item}->{$handler}->{$handlerEvent});
} }
...@@ -650,7 +681,7 @@ sub getStatsBySID ...@@ -650,7 +681,7 @@ sub getStatsBySID
{ {
my $sid = shift; my $sid = shift;
return _getStatsBySID($sid); return _getStatsBySID($sid);
} }
...@@ -659,7 +690,7 @@ sub getStatsBasicBySID ...@@ -659,7 +690,7 @@ sub getStatsBasicBySID
{ {
my $sid = shift; my $sid = shift;
return _getStatsBasicBySID($sid); return _getStatsBasicBySID($sid);
} }
...@@ -669,7 +700,13 @@ sub getSIDFromCID ...@@ -669,7 +700,13 @@ sub getSIDFromCID
my ($iface,$cid) = @_; my ($iface,$cid) = @_;
my $identifier = "Class:$iface:$cid"; # Grab identifier based on class ID
my $identifier = _getIdentifierFromCID($iface,$cid);
if (!defined($identifier)) {
return undef;
}
# Return the SID fo the identifier
return _getSIDFromIdentifier($identifier); return _getSIDFromIdentifier($identifier);
} }
...@@ -680,46 +717,58 @@ sub setSIDFromCID ...@@ -680,46 +717,58 @@ sub setSIDFromCID
my ($iface,$cid) = @_; my ($iface,$cid) = @_;
my $identifier = "Class:$iface:$cid"; # See if we can get a SID from the CID
my $sid = _getSIDFromIdentifier($identifier); my $sid = getSIDFromCID($iface,$cid);
if (!defined($sid)) { if (!defined($sid)) {
# If not, grab the identifier
my $identifier = _getIdentifierFromCID($iface,$cid);
if (!defined($identifier)) {
return undef;
}
# And setup a new SID
$sid = _setSIDFromIdentifier($identifier); $sid = _setSIDFromIdentifier($identifier);
} }
return $sid; return $sid;
} }
# Get the stats ID from a LID # Get the stats ID from a PID
sub getSIDFromLID sub getSIDFromPID
{ {
my $lid = shift; my $pid = shift;
if (defined(my $username = getLimitUsername($lid))) { # Grab identifier from a PID
my $identifier = "Username:$username"; my $identifier = _getIdentifierFromPID($pid);
return _getSIDFromIdentifier($identifier); if (!defined($identifier)) {
return undef;
} }
return undef; # Return the SID for the PID
return _getSIDFromIdentifier($identifier);
} }
# Set the stats ID from a LID # Set the stats ID from a PID
sub setSIDFromLID sub setSIDFromPID
{ {
my $lid = shift; my $pid = shift;
if (defined(my $username = getLimitUsername($lid))) { # Try grab the SID for the PID
my $identifier = "Username:$username"; my $sid = getSIDFromPID($pid);
my $sid = _getSIDFromIdentifier($identifier); if (!defined($sid)) {
if (!defined($sid)) { # If we can't, grab the identifier instead
$sid = _setSIDFromIdentifier($identifier); my $identifier = _getIdentifierFromPID($pid);
if (!defined($identifier)) {
return undef;
} }
return $sid; # And setup the SID
$sid = _setSIDFromIdentifier($identifier);
} }
return undef; return $sid;
} }
...@@ -729,7 +778,13 @@ sub getSIDFromCounter ...@@ -729,7 +778,13 @@ sub getSIDFromCounter
my $counter = shift; my $counter = shift;
my $identifier = "Counter:$counter"; # Grab identifier from a counter
my $identifier = _getIdentifierFromCounter($counter);
if (!defined($identifier)) {
return undef;
}
# Return the SID for the counter
return _getSIDFromIdentifier($identifier); return _getSIDFromIdentifier($identifier);
} }
...@@ -740,11 +795,18 @@ sub setSIDFromCounter ...@@ -740,11 +795,18 @@ sub setSIDFromCounter
my $counter = shift; my $counter = shift;
my $identifier = "Counter:$counter"; # Try grab the SID for the counter
my $sid = _getSIDFromIdentifier($identifier); my $sid = getSIDFromCounter($counter);
if (!defined($sid)) { if (!defined($sid)) {
# If we can't, grab the identifier instead
my $identifier = _getIdentifierFromCounter($counter);
if (!defined($identifier)) {
return undef;
}
# And setup the SID
$sid = _setSIDFromIdentifier($identifier); $sid = _setSIDFromIdentifier($identifier);
} }
return $sid; return $sid;
} }
...@@ -752,12 +814,12 @@ sub setSIDFromCounter ...@@ -752,12 +814,12 @@ sub setSIDFromCounter
# Return traffic direction # Return traffic direction
sub getTrafficDirection sub getTrafficDirection
{ {
my ($lid,$interface) = @_; my ($pid,$interface) = @_;
# Grab the interfaces for this limit # Grab the interfaces for this limit
my $txInterface = getLimitTxInterface($lid); my $txInterface = getPoolTxInterface($pid);
my $rxInterface = getLimitRxInterface($lid); my $rxInterface = getPoolRxInterface($pid);
# Check what it matches... # Check what it matches...
if ($interface eq $txInterface) { if ($interface eq $txInterface) {
...@@ -773,22 +835,22 @@ sub getTrafficDirection ...@@ -773,22 +835,22 @@ sub getTrafficDirection
# Generate ConfigManager counters # Generate ConfigManager counters
sub getConfigManagerCounters sub getConfigManagerCounters
{ {
my @limits = getLimits(); my @poolList = getPools();
my $classes = getTrafficClasses(); my $classes = getAllTrafficClasses();
# Grab user count # Grab user count
my %counters; my %counters;
$counters{"ConfigManager:TotalLimits"} = @limits; $counters{"ConfigManager:TotalPools"} = @poolList;
# Start off with 0's # Zero the number of pools in each class to start off with
foreach my $cid (keys %{$classes}) { foreach my $cid (keys %{$classes}) {
$counters{"ConfigManager:ClassLimits:$cid"} = 0; $counters{"ConfigManager:ClassPools:$cid"} = 0;
} }
# Generate ClassID counts
foreach my $lid (@limits) { # Pull in each pool and bump up the class counter
my $limit = getLimit($lid); foreach my $pid (@poolList) {
my $cid = $limit->{'ClassID'}; my $cid = getPoolTrafficClassID($pid);
# Bump the class counter # Bump the class counter
$counters{"ConfigManager:ClassLimits:$cid"}++; $counters{"ConfigManager:ClassLimits:$cid"}++;
} }
...@@ -846,7 +908,7 @@ sub _getConfigManagerStats ...@@ -846,7 +908,7 @@ sub _getConfigManagerStats
my $statsData = { }; my $statsData = { };
# Loop through counters and create stats items # Loop through counters and create stats items
foreach my $item (%{$counters}) { foreach my $item (keys %{$counters}) {
my $identifierID = setSIDFromCounter($item); my $identifierID = setSIDFromCounter($item);
my $stat = { my $stat = {
'identifierid' => $identifierID, 'identifierid' => $identifierID,
...@@ -860,18 +922,47 @@ sub _getConfigManagerStats ...@@ -860,18 +922,47 @@ sub _getConfigManagerStats
} }
# Function to get a SID identifier from a class ID
sub _getIdentifierFromCID
{
my ($iface,$cid) = @_;
return sprintf("Class:%s:%s",$iface,$cid);
}
# Function to get a SID identifier from a pool ID
sub _getIdentifierFromPID
{
my $pid = shift;
my $pool = getPool($pid);
if (!defined($pool)) {
return undef;
}
return sprintf("Pool:%s",$pool->{'Identifier'});
}
# Function to get a SID identifier from a counter
sub _getIdentifierFromCounter
{
my $counter = shift;
return sprintf("Counter:%s",$counter);
}
# Return a cached SID if its cached # Return a cached SID if its cached
sub _getCachedSIDFromIdentifier sub _getCachedSIDFromIdentifier
{ {
my $identifier = shift; my $identifier = shift;
# If we don't have a user mapped return $statsDBIdentifierMap->{$identifier};
if (defined(my $sid = $statsDBIdentifierMap->{$identifier})) {
return $sid;
}
return undef;
} }
...@@ -894,8 +985,7 @@ sub _getSIDFromIdentifier ...@@ -894,8 +985,7 @@ sub _getSIDFromIdentifier
return $statsDBIdentifierMap->{$identifier} = $row->{'id'}; return $statsDBIdentifierMap->{$identifier} = $row->{'id'};
} }
} else { } else {
# FIXME $logger->log(LOG_ERR,"[STATISTICS] Failed to get SID from identifier '%s': %s",$identifier,$identifierGetSTH->errstr);
warn "FAILED TO EXECUTE GETUSER: ".$identifierGetSTH->errstr;
} }
return undef; return undef;
...@@ -913,8 +1003,7 @@ sub _setSIDFromIdentifier ...@@ -913,8 +1003,7 @@ sub _setSIDFromIdentifier
if (my $res = $identifierAddSTH->execute($identifier)) { if (my $res = $identifierAddSTH->execute($identifier)) {
return $statsDBIdentifierMap->{$identifier} = $dbh->last_insert_id("","","",""); return $statsDBIdentifierMap->{$identifier} = $dbh->last_insert_id("","","","");
} else { } else {
# FIXME $logger->log(LOG_ERR,"[STATISTICS] Failed to get SID from identifier '%s': %s",$identifier,$identifierAddSTH->errstr);
warn "DB ADD IDENTIFIER ERROR: ".$identifierAddSTH->errstr;
} }
return undef; return undef;
...@@ -963,8 +1052,8 @@ sub _getStatsBySID ...@@ -963,8 +1052,8 @@ sub _getStatsBySID
$direction = 'tx'; $direction = 'tx';
} elsif ($item->{'direction'} eq STATISTICS_DIR_RX) { } elsif ($item->{'direction'} eq STATISTICS_DIR_RX) {
$direction = 'rx'; $direction = 'rx';
# FIXME
} else { } else {
$logger->log(LOG_ERR,"[STATISTICS] Unknown direction when getting stats '%s'",$direction);
next; next;
} }
...@@ -1019,6 +1108,5 @@ sub _getStatsBasicBySID ...@@ -1019,6 +1108,5 @@ sub _getStatsBasicBySID
1; 1;
# vim: ts=4 # vim: ts=4
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment