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

* If we have somehow gotten duplicate sessions and we roll over to midnight,...

* If we have somehow gotten duplicate sessions and we roll over to midnight, we must not rollunder to -4G and record 4G minus the difference in usage as the new session usage. Lets record 0 instead.

parent a896e382
No related branches found
No related tags found
No related merge requests found
......@@ -458,12 +458,14 @@ sub acct_log
my $totalOutputBytes = Math::BigInt->new();
$totalOutputBytes->badd($template->{'request'}->{'Acct-Output-Gigawords'})->bmul(UINT_MAX);
$totalOutputBytes->badd($template->{'request'}->{'Acct-Output-Octets'});
# Packets, no conversion
my $totalInputPackets = Math::BigInt->new($template->{'request'}->{'Acct-Input-Packets'});
my $totalOutputPackets = Math::BigInt->new($template->{'request'}->{'Acct-Output-Packets'});
# We don't need bigint here, but why not ... lets keep everything standard
my $totalSessionTime = Math::BigInt->new($template->{'request'}->{'Acct-Session-Time'});
# Loop through previous records and subtract them from our session totals
my $startNewPeriod = 0;
$template->{'query'}->{'InputPackets'} = $template->{'request'}->{'Acct-Input-Packets'};
$template->{'query'}->{'OutputPackets'} = $template->{'request'}->{'Acct-Output-Packets'};
$template->{'query'}->{'SessionTime'} = $template->{'request'}->{'Acct-Session-Time'};
while (my $sessionPart = $sth->fetchrow_hashref()) {
$sessionPart = hashifyLCtoMC(
$sessionPart,
......@@ -477,25 +479,22 @@ sub acct_log
my $sessionOutputBytes = Math::BigInt->new();
$sessionOutputBytes->badd($sessionPart->{'OutputGigawods'})->bmul(UINT_MAX);
$sessionOutputBytes->badd($sessionPart->{'OutputOctets'});
# And packets
my $sessionInputPackets = Math::BigInt->new($sessionPart->{'InputPackets'});
my $sessionOutputPackets = Math::BigInt->new($sessionPart->{'OutputPackets'});
# Finally session time
my $sessionSessionTime = Math::BigInt->new($sessionPart->{'SessionTime'});
# Check if this record is from an earlier period
$startNewPeriod = 0;
if (defined($sessionPart->{'PeriodKey'}) && $sessionPart->{'PeriodKey'} ne $periodKey) {
# Subtract from our total
# Subtract from our total, we can hit NEG!!! ... we check for that below
$totalInputBytes->bsub($sessionInputBytes);
$totalOutputBytes->bsub($sessionOutputBytes);
# Subtract other usage
if (defined($sessionPart->{'InputPackets'}) && $sessionPart->{'InputPackets'} > 0) {
$template->{'query'}->{'InputPackets'} -= $sessionPart->{'InputPackets'};
}
if (defined($sessionPart->{'OutputPackets'}) && $sessionPart->{'OutputPackets'} > 0) {
$template->{'query'}->{'OutputPackets'} -= $sessionPart->{'OutputPackets'};
}
if (defined($sessionPart->{'SessionTime'}) && $sessionPart->{'SessionTime'} > 0) {
$template->{'query'}->{'SessionTime'} -= $sessionPart->{'SessionTime'};
}
$totalInputPackets->bsub($sessionInputPackets);
$totalOutputPackets->bsub($sessionOutputPackets);
$totalSessionTime->bsub($sessionSessionTime);
# We need to continue this session in a new entry
$startNewPeriod = 1;
......@@ -503,6 +502,23 @@ sub acct_log
}
DBFreeRes($sth);
# Sanitize
if ($totalInputBytes->is_neg()) {
$totalInputBytes->bzero();
}
if ($totalOutputBytes->is_neg()) {
$totalOutputBytes->bzero();
}
if ($totalInputPackets->is_neg()) {
$totalInputPackets->bzero();
}
if ($totalOutputPackets->is_neg()) {
$totalOutputPackets->bzero();
}
if ($totalSessionTime->is_neg()) {
$totalSessionTime->bzero();
}
# Re-calculate
my ($inputGigawordsStr,$inputOctetsStr) = $totalInputBytes->bdiv(UINT_MAX);
my ($outputGigawordsStr,$outputOctetsStr) = $totalOutputBytes->bdiv(UINT_MAX);
......@@ -513,6 +529,11 @@ sub acct_log
$template->{'query'}->{'OutputGigawords'} = $outputGigawordsStr->bstr();
$template->{'query'}->{'OutputOctets'} = $outputOctetsStr->bstr();
$template->{'query'}->{'InputPackets'} = $totalInputPackets->bstr();
$template->{'query'}->{'OutputPackets'} = $totalOutputPackets->bstr();
$template->{'query'}->{'SessionTime'} = $totalSessionTime->bstr();
# Check if we doing an update
if ($startNewPeriod == 0) {
# Replace template entries
......
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