mirror of
https://github.com/craigerl/aprsd.git
synced 2024-11-18 06:11:49 -05:00
Changed Stats Collector registration
This patch changes the stats Collector object registration to take a class name instead of an object. This allows the app to start up and fetch the configuration correctly so that when objects are created the CONF has the proper values. This is so singleton objects can assign settings values at creation time.
This commit is contained in:
parent
4542c0a643
commit
dc4879a367
@ -67,10 +67,6 @@ class PacketList(objectstore.ObjectStoreMixin):
|
||||
def copy(self):
|
||||
return self.data.copy()
|
||||
|
||||
@wrapt.synchronized(lock)
|
||||
def set_maxlen(self, maxlen):
|
||||
self.maxlen = maxlen
|
||||
|
||||
@wrapt.synchronized(lock)
|
||||
def find(self, packet):
|
||||
return self.data["packets"][packet.key]
|
||||
|
@ -9,12 +9,12 @@ from aprsd.threads import aprsd
|
||||
# Create the collector and register all the objects
|
||||
# that APRSD has that implement the stats protocol
|
||||
stats_collector = collector.Collector()
|
||||
stats_collector.register_producer(app.APRSDStats())
|
||||
stats_collector.register_producer(packet_list.PacketList())
|
||||
stats_collector.register_producer(watch_list.WatchList())
|
||||
stats_collector.register_producer(tracker.PacketTrack())
|
||||
stats_collector.register_producer(plugin.PluginManager())
|
||||
stats_collector.register_producer(aprsd.APRSDThreadList())
|
||||
stats_collector.register_producer(email.EmailStats())
|
||||
stats_collector.register_producer(aprs_client.APRSClientStats())
|
||||
stats_collector.register_producer(seen_list.SeenList())
|
||||
stats_collector.register_producer(app.APRSDStats)
|
||||
stats_collector.register_producer(packet_list.PacketList)
|
||||
stats_collector.register_producer(watch_list.WatchList)
|
||||
stats_collector.register_producer(tracker.PacketTrack)
|
||||
stats_collector.register_producer(plugin.PluginManager)
|
||||
stats_collector.register_producer(aprsd.APRSDThreadList)
|
||||
stats_collector.register_producer(email.EmailStats)
|
||||
stats_collector.register_producer(aprs_client.APRSClientStats)
|
||||
stats_collector.register_producer(seen_list.SeenList)
|
||||
|
@ -1,8 +1,9 @@
|
||||
from typing import Protocol
|
||||
from typing import Callable, Protocol, runtime_checkable
|
||||
|
||||
from aprsd.utils import singleton
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
class StatsProducer(Protocol):
|
||||
"""The StatsProducer protocol is used to define the interface for collecting stats."""
|
||||
def stats(self, serializeable=False) -> dict:
|
||||
@ -14,17 +15,17 @@ class StatsProducer(Protocol):
|
||||
class Collector:
|
||||
"""The Collector class is used to collect stats from multiple StatsProducer instances."""
|
||||
def __init__(self):
|
||||
self.producers: dict[str, StatsProducer] = {}
|
||||
self.producers: list[Callable] = []
|
||||
|
||||
def collect(self, serializable=False) -> dict:
|
||||
stats = {}
|
||||
for name, producer in self.producers.items():
|
||||
# No need to put in empty stats
|
||||
tmp_stats = producer.stats(serializable=serializable)
|
||||
if tmp_stats:
|
||||
stats[name] = tmp_stats
|
||||
for name in self.producers:
|
||||
cls = name()
|
||||
if isinstance(cls, StatsProducer):
|
||||
stats[cls.__class__.__name__] = cls.stats(serializable=serializable)
|
||||
else:
|
||||
raise TypeError(f"{cls} is not an instance of StatsProducer")
|
||||
return stats
|
||||
|
||||
def register_producer(self, producer: StatsProducer):
|
||||
name = producer.__class__.__name__
|
||||
self.producers[name] = producer
|
||||
def register_producer(self, producer_name: Callable):
|
||||
self.producers.append(producer_name)
|
||||
|
Loading…
Reference in New Issue
Block a user