Rip out the old method of collecting stats in favour of the generic way.

This commit is contained in:
James Muscat 2015-04-13 18:32:32 +01:00
parent 384a4f40fe
commit 7d7f977cea
3 changed files with 7 additions and 37 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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] = {