Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
98119316
Commit
98119316
authored
Apr 08, 2016
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(netflow, flowd agg) add vacuum, change poll interval
parent
78069d8f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
7 deletions
+18
-7
flowd_aggregate.py
src/opnsense/scripts/netflow/flowd_aggregate.py
+13
-5
aggregate.py
src/opnsense/scripts/netflow/lib/aggregate.py
+5
-2
No files found.
src/opnsense/scripts/netflow/flowd_aggregate.py
View file @
98119316
...
...
@@ -44,8 +44,9 @@ MAX_FILE_SIZE_MB=10
MAX_LOGS
=
10
def
aggregate_flowd
():
def
aggregate_flowd
(
do_vacuum
=
False
):
""" aggregate collected flowd data
:param do_vacuum: vacuum database after cleanup
:return: None
"""
# init metadata (progress maintenance)
...
...
@@ -53,7 +54,6 @@ def aggregate_flowd():
# register aggregate classes to stream data to
stream_agg_objects
=
list
()
resolutions
=
[
60
,
60
*
5
]
for
agg_class
in
lib
.
aggregates
.
get_aggregators
():
for
resolution
in
agg_class
.
resolutions
():
stream_agg_objects
.
append
(
agg_class
(
resolution
))
...
...
@@ -74,7 +74,7 @@ def aggregate_flowd():
# expire old data
for
stream_agg_object
in
stream_agg_objects
:
stream_agg_object
.
cleanup
()
stream_agg_object
.
cleanup
(
do_vacuum
)
del
stream_agg_object
del
metadata
...
...
@@ -122,13 +122,21 @@ class Main(object):
""" run, endless loop, until sigterm is received
:return: None
"""
vacuum_interval
=
(
60
*
60
*
8
)
# 8 hour vacuum cycle
vacuum_countdown
=
None
while
self
.
running
:
# should we perform a vacuum
if
not
vacuum_countdown
or
vacuum_countdown
<
time
.
time
():
vacuum_countdown
=
time
.
time
()
+
vacuum_interval
do_vacuum
=
True
else
:
do_vacuum
=
False
# run aggregate
aggregate_flowd
()
aggregate_flowd
(
do_vacuum
)
# rotate if needed
check_rotate
()
# wait for next pass, exit on sigterm
for
i
in
range
(
12
0
):
for
i
in
range
(
3
0
):
if
self
.
running
:
time
.
sleep
(
0.5
)
else
:
...
...
src/opnsense/scripts/netflow/lib/aggregate.py
View file @
98119316
...
...
@@ -230,9 +230,10 @@ class BaseFlowAggregator(object):
# next start time
start_time
+=
self
.
resolution
def
cleanup
(
self
):
def
cleanup
(
self
,
do_vacuum
=
False
):
""" cleanup timeserie table
:param expire: cleanup table, remove data older then [expire] seconds
:param do_vacuum: vacuum database
:return: None
"""
if
self
.
is_db_open
()
and
'timeserie'
in
self
.
_known_targets
\
...
...
@@ -244,7 +245,9 @@ class BaseFlowAggregator(object):
expire_timestamp
=
last_timestamp
-
datetime
.
timedelta
(
seconds
=
expire
)
self
.
_update_cur
.
execute
(
'delete from timeserie where mtime < :expire'
,
{
'expire'
:
expire_timestamp
})
self
.
commit
()
# todo: might need vacuum at some point.
if
do_vacuum
:
# vacuum database if requested
self
.
_update_cur
.
execute
(
'vacuum'
)
def
get_data
(
self
,
start_time
,
end_time
,
fields
):
""" fetch data from aggregation source, groups by mtime and selected fields
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment