-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitoring.py
66 lines (58 loc) · 1.81 KB
/
monitoring.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class Monitoring:
def __init__(self, window, sla, reducer=lambda x: sum(x)/len(x)):
self.reducer = reducer
self.window = window
self.sla = sla
self.reset()
def tick(self, t, rt, users, cores):
for i in range(1, len(self.time)+1):
if t - self.time[-i] > self.window:
try:
del self.rts[-i]
del self.users[-i]
except:
break
self.time.append(t)
self.rts.append(rt)
self.users.append(users)
self.allRts.append(self.getRT())
self.allUsers.append(self.getUsers())
self.allCores.append(cores)
def getUsers(self):
if not len(self.users): return 0
return self.reducer(self.users)
def getRT(self):
if not len(self.rts): return 0
return self.reducer(self.rts)
def getViolations(self):
def appendViolation(rts):
if self.reducer(rts) > self.sla:
return 1
else:
return 0
second = int(self.time[0])
violations = []
rts = []
for (t, rt) in zip(self.time, self.allRts):
if int(t) != second:
violations.append(appendViolation(rts))
rts = []
second = int(t)
rts.append(rt)
violations.append(appendViolation(rts))
return sum(violations)
def getAllRTs(self):
return self.allRts
def getAllUsers(self):
return self.allUsers
def getAllCores(self):
return self.allCores
def getAllTimes(self):
return self.time
def reset(self):
self.allRts = []
self.allUsers = []
self.allCores = []
self.rts = []
self.users = []
self.time = []