From 7d7f977cea4a9b4d3d59be54b0262f0673519a4b Mon Sep 17 00:00:00 2001 From: James Muscat Date: Mon, 13 Apr 2015 18:32:32 +0100 Subject: [PATCH] Rip out the old method of collecting stats in favour of the generic way. --- src/eddn/Gateway.py | 4 ++-- src/eddn/Relay.py | 4 ++-- src/eddn/StatsCollector.py | 36 +++--------------------------------- 3 files changed, 7 insertions(+), 37 deletions(-) diff --git a/src/eddn/Gateway.py b/src/eddn/Gateway.py index 5182fd8..4b10763 100644 --- a/src/eddn/Gateway.py +++ b/src/eddn/Gateway.py @@ -50,7 +50,7 @@ def push_message(string_message): # announcers. compressed_msg = zlib.compress(string_message) sender.send(compressed_msg) - statsCollector.tallyOutbound() + statsCollector.tally("outbound") def get_remote_address(): @@ -164,7 +164,7 @@ def upload(): logger.error("Error to %s: %s" % (get_remote_address(), exc.message)) return exc.message - statsCollector.tallyInbound() + statsCollector.tally("inbound") return parse_and_error_handle(message_body) diff --git a/src/eddn/Relay.py b/src/eddn/Relay.py index 72f8ace..567b8f9 100644 --- a/src/eddn/Relay.py +++ b/src/eddn/Relay.py @@ -63,7 +63,7 @@ class Relay(Thread): message = zlib.decompress(message) sender.send(message) - statsCollector.tallyOutbound() + statsCollector.tally("outbound") logger.info("Relay is now listening for order data.") @@ -71,7 +71,7 @@ class Relay(Thread): # For each incoming message, spawn a greenlet using the relay_worker # function. inboundMessage = receiver.recv() - statsCollector.tallyInbound() + statsCollector.tally("inbound") gevent.spawn(relay_worker, inboundMessage) diff --git a/src/eddn/StatsCollector.py b/src/eddn/StatsCollector.py index 559e02c..59e4540 100644 --- a/src/eddn/StatsCollector.py +++ b/src/eddn/StatsCollector.py @@ -6,22 +6,15 @@ from time import sleep class StatsCollector(Thread): ''' - Collects simple statistics - number of inbound vs. outbound messages - and - aggregates them over the number of minutes you choose, up to one hour. + Collects simple statistics and aggregates them over the number of minutes + you choose, up to one hour. ''' max_minutes = 60 - inboundMessages = 0 - outboundMessages = 0 - current = {} - history = {} - inboundHistory = deque(maxlen=max_minutes) - outboundHistory = deque(maxlen=max_minutes) - lock = Lock() def __init__(self): @@ -32,24 +25,12 @@ class StatsCollector(Thread): while True: sleep(60) with self.lock: - self.inboundHistory.appendleft(self.inboundMessages) - self.outboundHistory.appendleft(self.outboundMessages) - self.inboundMessages = 0 - self.outboundMessages = 0 for key in self.current.keys(): if key not in self.history: self.history[key] = deque(maxlen=self.max_minutes) self.history[key].appendleft(self.current[key]) self.current[key] = 0 - def tallyInbound(self): - with self.lock: - self.inboundMessages += 1 - - def tallyOutbound(self): - with self.lock: - self.outboundMessages += 1 - def tally(self, key): with self.lock: if key not in self.current: @@ -69,18 +50,7 @@ class StatsCollector(Thread): return 0 def getSummary(self): - summary = { - "inbound": { - "1min": self.getInboundCount(1), - "5min": self.getInboundCount(5), - "60min": self.getInboundCount(60), - }, - "outbound": { - "1min": self.getOutboundCount(1), - "5min": self.getOutboundCount(5), - "60min": self.getOutboundCount(60) - } - } + summary = {} for key in self.current.keys(): summary[key] = {