Update stats every 10 seconds, keeping the last 10 minutes

This commit is contained in:
Nicolas Mowen 2024-04-01 07:10:35 -06:00
parent 8295a0d11a
commit bf8d4adfc5

View File

@ -1,5 +1,6 @@
"""Emit stats to listeners."""
import itertools
import json
import logging
import threading
@ -52,13 +53,20 @@ class StatsEmitter(threading.Thread):
def run(self) -> None:
time.sleep(10)
while not self.stop_event.wait(self.config.mqtt.stats_interval):
for counter in itertools.cycle(range(self.config.record.expire_interval)):
if self.stop_event.wait(5):
break
logger.debug("Starting stats collection")
stats = stats_snapshot(
self.config, self.stats_tracking, self.hwaccel_errors
)
self.stats_history.append(stats)
self.stats_history = self.stats_history[-MAX_STATS_POINTS:]
if counter == 0:
self.requestor.send_data("stats", json.dumps(stats))
logger.debug("Finished stats collection")
logger.info("Exiting stats emitter...")