mirror of
https://github.com/craigerl/aprsd.git
synced 2026-04-26 18:03:59 -04:00
feat: Add configurable stats_store_interval for stats file saves
Add stats_store_interval config option to control how frequently the statsstore.json file is written to disk. Default remains 10 seconds for backward compatibility. This allows reducing disk I/O in production deployments and can help avoid potential file corruption issues when external processes read the stats file.
This commit is contained in:
parent
27413ab8cf
commit
490ff41cdc
@ -133,6 +133,12 @@ aprsd_opts = [
|
|||||||
help='Enable the Callsign seen list tracking feature. This allows aprsd to keep track of '
|
help='Enable the Callsign seen list tracking feature. This allows aprsd to keep track of '
|
||||||
'callsigns that have been seen and when they were last seen.',
|
'callsigns that have been seen and when they were last seen.',
|
||||||
),
|
),
|
||||||
|
cfg.IntOpt(
|
||||||
|
'stats_store_interval',
|
||||||
|
default=10,
|
||||||
|
help='Interval in seconds between stats file saves to disk. '
|
||||||
|
'Lower values provide more frequent updates but increase disk I/O.',
|
||||||
|
),
|
||||||
cfg.BoolOpt(
|
cfg.BoolOpt(
|
||||||
'enable_packet_logging',
|
'enable_packet_logging',
|
||||||
default=True,
|
default=True,
|
||||||
|
|||||||
@ -32,10 +32,11 @@ class APRSDStatsStoreThread(APRSDThread):
|
|||||||
"""Save APRSD Stats to disk periodically."""
|
"""Save APRSD Stats to disk periodically."""
|
||||||
|
|
||||||
daemon = False
|
daemon = False
|
||||||
period = 10
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__('StatsStore')
|
super().__init__('StatsStore')
|
||||||
|
# Use config value for period, default to 10 seconds
|
||||||
|
self.period = CONF.stats_store_interval
|
||||||
|
|
||||||
def loop(self):
|
def loop(self):
|
||||||
stats = collector.Collector().collect()
|
stats = collector.Collector().collect()
|
||||||
|
|||||||
@ -72,11 +72,20 @@ class TestAPRSDStatsStoreThread(unittest.TestCase):
|
|||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
"""Test APRSDStatsStoreThread initialization."""
|
"""Test APRSDStatsStoreThread initialization."""
|
||||||
thread = APRSDStatsStoreThread()
|
with mock.patch('aprsd.threads.stats.CONF') as mock_conf:
|
||||||
self.assertEqual(thread.name, 'StatsStore')
|
mock_conf.stats_store_interval = 10
|
||||||
self.assertEqual(thread.period, 10)
|
thread = APRSDStatsStoreThread()
|
||||||
self.assertFalse(thread.daemon)
|
self.assertEqual(thread.name, 'StatsStore')
|
||||||
self.assertTrue(hasattr(thread, 'loop_count'))
|
self.assertEqual(thread.period, 10)
|
||||||
|
self.assertFalse(thread.daemon)
|
||||||
|
self.assertTrue(hasattr(thread, 'loop_count'))
|
||||||
|
|
||||||
|
def test_init_with_custom_interval(self):
|
||||||
|
"""Test APRSDStatsStoreThread uses stats_store_interval from config."""
|
||||||
|
with mock.patch('aprsd.threads.stats.CONF') as mock_conf:
|
||||||
|
mock_conf.stats_store_interval = 60
|
||||||
|
thread = APRSDStatsStoreThread()
|
||||||
|
self.assertEqual(thread.period, 60)
|
||||||
|
|
||||||
def test_loop_with_save(self):
|
def test_loop_with_save(self):
|
||||||
"""Test loop method saves stats every call."""
|
"""Test loop method saves stats every call."""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user