Factor out common code into StatsCollector.

This commit is contained in:
James Muscat committed 2015-04-13 18:04:33 +01:00
1 parent 95e83333d7
commit 7c146a14c4
3 files changed
+16 -28

No files matched your search

+1 -14
View File
@@ -180,20 +180,7 @@ def health_check():
@get('/stats/')
def stats():
return simplejson.dumps(
{
"inbound": {
"1min": statsCollector.getInboundCount(1),
"5min": statsCollector.getInboundCount(5),
"60min": statsCollector.getInboundCount(60)
},
"outbound": {
"1min": statsCollector.getOutboundCount(1),
"5min": statsCollector.getOutboundCount(5),
"60min": statsCollector.getOutboundCount(60)
},
}
)
return simplejson.dumps(statsCollector.getSummary())
class MalformedUploadError(Exception):
+1 -14
View File
@@ -26,20 +26,7 @@ statsCollector.start()
@get('/stats/')
def stats():
return simplejson.dumps(
{
"inbound": {
"1min": statsCollector.getInboundCount(1),
"5min": statsCollector.getInboundCount(5),
"60min": statsCollector.getInboundCount(60)
},
"outbound": {
"1min": statsCollector.getOutboundCount(1),
"5min": statsCollector.getOutboundCount(5),
"60min": statsCollector.getOutboundCount(60)
},
}
)
return simplejson.dumps(statsCollector.getSummary())
class Relay(Thread):
+14
View File
@@ -46,3 +46,17 @@ class StatsCollector(Thread):
def getOutboundCount(self, minutes):
return sum(islice(self.outboundHistory, 0, max(minutes, self.max_minutes)))
def getSummary(self):
return {
"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)
},
}