mirror of https://github.com/craigerl/aprsd.git
syncronize the add for StatsStore
This commit is contained in:
parent
f59b65d13c
commit
026dc6e376
|
@ -62,6 +62,7 @@ class PacketList(objectstore.ObjectStoreMixin):
|
||||||
self.data["packets"].popitem(last=False)
|
self.data["packets"].popitem(last=False)
|
||||||
self.data["packets"][packet.key] = packet
|
self.data["packets"][packet.key] = packet
|
||||||
|
|
||||||
|
@wrapt.synchronized(lock)
|
||||||
def copy(self):
|
def copy(self):
|
||||||
return self.data.copy()
|
return self.data.copy()
|
||||||
|
|
||||||
|
@ -73,6 +74,7 @@ class PacketList(objectstore.ObjectStoreMixin):
|
||||||
def find(self, packet):
|
def find(self, packet):
|
||||||
return self.data["packets"][packet.key]
|
return self.data["packets"][packet.key]
|
||||||
|
|
||||||
|
@wrapt.synchronized(lock)
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self.data["packets"])
|
return len(self.data["packets"])
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
import wrapt
|
||||||
|
|
||||||
from aprsd.stats import collector
|
from aprsd.stats import collector
|
||||||
from aprsd.threads import APRSDThread
|
from aprsd.threads import APRSDThread
|
||||||
|
@ -18,6 +19,10 @@ class StatsStore(objectstore.ObjectStoreMixin):
|
||||||
lock = threading.Lock()
|
lock = threading.Lock()
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
|
@wrapt.synchronized(lock)
|
||||||
|
def add(self, stats: dict):
|
||||||
|
self.data = stats
|
||||||
|
|
||||||
|
|
||||||
class APRSDStatsStoreThread(APRSDThread):
|
class APRSDStatsStoreThread(APRSDThread):
|
||||||
"""Save APRSD Stats to disk periodically."""
|
"""Save APRSD Stats to disk periodically."""
|
||||||
|
@ -32,7 +37,7 @@ class APRSDStatsStoreThread(APRSDThread):
|
||||||
if self.loop_count % self.save_interval == 0:
|
if self.loop_count % self.save_interval == 0:
|
||||||
stats = collector.Collector().collect()
|
stats = collector.Collector().collect()
|
||||||
ss = StatsStore()
|
ss = StatsStore()
|
||||||
ss.data = stats
|
ss.add(stats)
|
||||||
ss.save()
|
ss.save()
|
||||||
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
|
@ -70,8 +70,8 @@ class ObjectStoreMixin:
|
||||||
"""Save any queued to disk?"""
|
"""Save any queued to disk?"""
|
||||||
if not CONF.enable_save:
|
if not CONF.enable_save:
|
||||||
return
|
return
|
||||||
|
save_filename = self._save_filename()
|
||||||
if len(self) > 0:
|
if len(self) > 0:
|
||||||
save_filename = self._save_filename()
|
|
||||||
LOG.info(
|
LOG.info(
|
||||||
f"{self.__class__.__name__}::Saving"
|
f"{self.__class__.__name__}::Saving"
|
||||||
f" {len(self)} entries to disk at "
|
f" {len(self)} entries to disk at "
|
||||||
|
@ -83,7 +83,7 @@ class ObjectStoreMixin:
|
||||||
LOG.debug(
|
LOG.debug(
|
||||||
"{} Nothing to save, flushing old save file '{}'".format(
|
"{} Nothing to save, flushing old save file '{}'".format(
|
||||||
self.__class__.__name__,
|
self.__class__.__name__,
|
||||||
self._save_filename(),
|
save_filename,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
self.flush()
|
self.flush()
|
||||||
|
|
Loading…
Reference in New Issue