1
0
mirror of https://github.com/craigerl/aprsd.git synced 2026-01-13 17:17:26 -05:00
aprsd/aprsd/threads/stats.py
Hemna 227ddbf148 Update StatsStore to use existing lock
The base class for StatsStore already creates a lock, use that instead.
2025-01-30 10:07:28 -08:00

40 lines
884 B
Python

import logging
import time
from oslo_config import cfg
from aprsd.stats import collector
from aprsd.threads import APRSDThread
from aprsd.utils import objectstore
CONF = cfg.CONF
LOG = logging.getLogger('APRSD')
class StatsStore(objectstore.ObjectStoreMixin):
"""Container to save the stats from the collector."""
def add(self, stats: dict):
with self.lock:
self.data = stats
class APRSDStatsStoreThread(APRSDThread):
"""Save APRSD Stats to disk periodically."""
# how often in seconds to write the file
save_interval = 10
def __init__(self):
super().__init__('StatsStore')
def loop(self):
if self.loop_count % self.save_interval == 0:
stats = collector.Collector().collect()
ss = StatsStore()
ss.add(stats)
ss.save()
time.sleep(1)
return True