mirror of
https://github.com/craigerl/aprsd.git
synced 2026-03-30 19:55:44 -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 '
|
||||
'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(
|
||||
'enable_packet_logging',
|
||||
default=True,
|
||||
|
||||
@ -32,10 +32,11 @@ class APRSDStatsStoreThread(APRSDThread):
|
||||
"""Save APRSD Stats to disk periodically."""
|
||||
|
||||
daemon = False
|
||||
period = 10
|
||||
|
||||
def __init__(self):
|
||||
super().__init__('StatsStore')
|
||||
# Use config value for period, default to 10 seconds
|
||||
self.period = CONF.stats_store_interval
|
||||
|
||||
def loop(self):
|
||||
stats = collector.Collector().collect()
|
||||
|
||||
@ -72,11 +72,20 @@ class TestAPRSDStatsStoreThread(unittest.TestCase):
|
||||
|
||||
def test_init(self):
|
||||
"""Test APRSDStatsStoreThread initialization."""
|
||||
thread = APRSDStatsStoreThread()
|
||||
self.assertEqual(thread.name, 'StatsStore')
|
||||
self.assertEqual(thread.period, 10)
|
||||
self.assertFalse(thread.daemon)
|
||||
self.assertTrue(hasattr(thread, 'loop_count'))
|
||||
with mock.patch('aprsd.threads.stats.CONF') as mock_conf:
|
||||
mock_conf.stats_store_interval = 10
|
||||
thread = APRSDStatsStoreThread()
|
||||
self.assertEqual(thread.name, 'StatsStore')
|
||||
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):
|
||||
"""Test loop method saves stats every call."""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user