monolith/legacy/modules/counters.py

44 lines
1.1 KiB
Python
Raw Permalink Normal View History

2022-07-21 12:40:09 +00:00
import main
2022-09-05 06:20:30 +00:00
from twisted.internet.task import LoopingCall
2022-07-21 12:40:09 +00:00
2022-07-21 12:39:41 +00:00
def event(name, eventType):
2022-07-21 12:40:05 +00:00
if "local" not in main.counters.keys():
main.counters["local"] = {}
2022-07-21 12:40:05 +00:00
if "global" not in main.counters.keys():
main.counters["global"] = {}
2022-07-21 12:40:05 +00:00
if name not in main.counters["local"].keys():
main.counters["local"][name] = {}
if eventType not in main.counters["local"][name].keys():
main.counters["local"][name][eventType] = 0
if eventType not in main.counters["global"]:
main.counters["global"][eventType] = 0
main.counters["local"][name][eventType] += 1
main.counters["global"][eventType] += 1
main.runningSample += 1
2022-07-21 12:39:41 +00:00
def getEvents(name=None):
2022-07-21 12:40:05 +00:00
if name is None:
if "global" in main.counters.keys():
return main.counters["global"]
else:
return None
else:
if name in main.counters["local"].keys():
return main.counters["local"][name]
else:
return None
2022-07-21 12:39:41 +00:00
def takeSample():
main.lastMinuteSample = main.runningSample
main.runningSample = 0
2022-07-21 12:39:41 +00:00
def setupCounterLoop():
lc = LoopingCall(takeSample)
lc.start(60)