You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
2 years ago
|
from twisted.internet.task import LoopingCall
|
||
2 years ago
|
|
||
2 years ago
|
import main
|
||
|
|
||
2 years ago
|
|
||
7 years ago
|
def event(name, eventType):
|
||
2 years ago
|
if "local" not in main.counters.keys():
|
||
7 years ago
|
main.counters["local"] = {}
|
||
2 years ago
|
if "global" not in main.counters.keys():
|
||
7 years ago
|
main.counters["global"] = {}
|
||
2 years ago
|
if name not in main.counters["local"].keys():
|
||
7 years ago
|
main.counters["local"][name] = {}
|
||
|
if eventType not in main.counters["local"][name].keys():
|
||
|
main.counters["local"][name][eventType] = 0
|
||
7 years ago
|
|
||
7 years ago
|
if eventType not in main.counters["global"]:
|
||
|
main.counters["global"][eventType] = 0
|
||
7 years ago
|
|
||
7 years ago
|
main.counters["local"][name][eventType] += 1
|
||
|
main.counters["global"][eventType] += 1
|
||
5 years ago
|
main.runningSample += 1
|
||
7 years ago
|
|
||
2 years ago
|
|
||
7 years ago
|
def getEvents(name=None):
|
||
2 years ago
|
if name is None:
|
||
7 years ago
|
if "global" in main.counters.keys():
|
||
|
return main.counters["global"]
|
||
7 years ago
|
else:
|
||
|
return None
|
||
|
else:
|
||
7 years ago
|
if name in main.counters["local"].keys():
|
||
|
return main.counters["local"][name]
|
||
7 years ago
|
else:
|
||
|
return None
|
||
5 years ago
|
|
||
2 years ago
|
|
||
5 years ago
|
def takeSample():
|
||
|
main.lastMinuteSample = main.runningSample
|
||
|
main.runningSample = 0
|
||
|
|
||
2 years ago
|
|
||
5 years ago
|
def setupCounterLoop():
|
||
|
lc = LoopingCall(takeSample)
|
||
|
lc.start(60)
|