Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
smradius
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
shail
smradius
Commits
69dc75df
Commit
69dc75df
authored
14 years ago
by
Nigel Kukard
Browse files
Options
Downloads
Patches
Plain Diff
Added caching support for mod_accounting_sql
parent
d42585b6
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
smradius/modules/accounting/mod_accounting_sql.pm
+39
-0
39 additions, 0 deletions
smradius/modules/accounting/mod_accounting_sql.pm
smradiusd.conf
+7
-0
7 additions, 0 deletions
smradiusd.conf
with
46 additions
and
0 deletions
smradius/modules/accounting/mod_accounting_sql.pm
+
39
−
0
View file @
69dc75df
...
...
@@ -22,6 +22,7 @@ use warnings;
# Modules we need
use
smradius::
constants
;
use
awitpt::
cache
;
use
awitpt::db::
dblayer
;
use
smradius::
logging
;
use
smradius::
util
;
...
...
@@ -228,6 +229,9 @@ sub init
ID = %{query.DuplicateID}
';
$config
->
{'
accounting_usage_cache_time
'}
=
300
;
# Setup SQL queries
if
(
defined
(
$scfg
->
{'
mod_accounting_sql
'}))
{
# Pull in queries
...
...
@@ -294,6 +298,25 @@ sub init
$config
->
{'
accounting_delete_duplicates_query
'}
=
$scfg
->
{'
mod_accounting_sql
'}
->
{'
accounting_delete_duplicates_query
'};
}
}
if
(
defined
(
$scfg
->
{'
mod_accounting_sql
'}
->
{'
accounting_usage_cache_time
'}))
{
if
(
$scfg
->
{'
mod_accounting_sql
'}{'
accounting_usage_cache_time
'}
=~
/^\s*(yes|true|1)\s*$/i
)
{
# Default?
}
elsif
(
$scfg
->
{'
mod_accounting_sql
'}{'
accounting_usage_cache_time
'}
=~
/^\s*(no|false|0)\s*$/i
)
{
$config
->
{'
mod_accounting_sql
'}{'
accounting_usage_cache_time
'}
=
undef
;
}
elsif
(
$scfg
->
{'
mod_accounting_sql
'}{'
accounting_usage_cache_time
'}
=~
/^[0-9]+$/
)
{
$scfg
->
{'
mod_accounting_sql
'}{'
accounting_usage_cache_time
'}
=
$scfg
->
{'
mod_accounting_sql
'}{'
accounting_usage_cache_time
'};
}
else
{
$server
->
log
(
LOG_NOTICE
,"
[MOD_ACCOUNTING_SQL] Value for 'accounting_usage_cache_time' is invalid
");
}
}
}
# Log this for info sake
if
(
$config
->
{'
mod_accounting_sql
'}
->
{'
accounting_usage_cache_time
'})
{
$server
->
log
(
LOG_NOTICE
,"
[MOD_ACCOUNTING_SQL] getUsage caching ENABLED, cache time is %ds.
",
$config
->
{'
mod_accounting_sql
'}
->
{'
accounting_usage_cache_time
'});
}
else
{
$server
->
log
(
LOG_NOTICE
,"
[MOD_ACCOUNTING_SQL] getUsage caching DISABLED
");
}
}
...
...
@@ -314,6 +337,14 @@ sub getUsage
my
$now
=
DateTime
->
now
->
set_time_zone
(
$server
->
{'
smradius
'}
->
{'
event_timezone
'});
$template
->
{'
query
'}
->
{'
PeriodKey
'}
=
$now
->
strftime
("
%Y-%m
");
# If we using caching, check how old the result is
if
(
defined
(
$config
->
{'
accounting_usage_cache_time
'}))
{
my
(
$res
,
$val
)
=
cacheGetKeyPair
('
mod_accounting_sql(getUsage)
',
$user
->
{'
Username
'}
.
"
/
"
.
$template
->
{'
query
'}
->
{'
PeriodKey
'});
if
(
defined
(
$val
)
&&
$val
->
{'
CachedUntil
'}
<
$now
)
{
return
$val
;
}
}
# Replace template entries
my
(
@dbDoParams
)
=
templateReplace
(
$config
->
{'
accounting_usage_query
'},
$template
);
...
...
@@ -371,6 +402,14 @@ sub getUsage
$res
{'
TotalDataUsage
'}
=
$totalData
->
bdiv
('
1024
')
->
bdiv
('
1024
')
->
bceil
()
->
bstr
();
$res
{'
TotalSessionTime
'}
=
$totalTime
->
bdiv
('
60
')
->
bceil
()
->
bstr
();
# If we using caching and got here, it means that we must cache the result
if
(
defined
(
$config
->
{'
accounting_usage_cache_time
'}))
{
$res
{'
CachedUntil
'}
=
$now
+
$config
->
{'
accounting_usage_cache_time
'};
# Cache the result
cacheStoreKeyPair
('
mod_accounting_sql(getUsage)
',
$user
->
{'
Username
'}
.
"
/
"
.
$template
->
{'
query
'}
->
{'
PeriodKey
'},
\
%res
);
}
return
\
%res
;
}
...
...
This diff is collapsed.
Click to expand it.
smradiusd.conf
+
7
−
0
View file @
69dc75df
...
...
@@ -407,6 +407,13 @@ accounting_delete_duplicates_query=<<EOT
ID
= %{
query
.
DuplicateID
}
EOT
# This is how long we going to cache the usage query for
# Default: 300 (seconds)
#
# You can use "no", "0", "false" to disable, specify a number > 1, or use
# "yes", "1", "true" to enable with the default value
accounting_usage_cache_time
=
300
# MOD_USERDB_SQL
[
mod_userdb_sql
]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment