mirror of
https://github.com/EDCD/EDDN.git
synced 2026-12-02 02:25:13 +03:00
Factor out common code into StatsCollector.
This commit is contained in:
1 parent
95e83333d7
commit
7c146a14c4
3 files changed
+16
-28
No files matched your search
+1
-14
@@ -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
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
},
|
||||
}
|
||||
Reference in new issue
Block a user