1
2
3
4
5
6
7
8
9
10
11
12
13
14 import logging
15 log = logging.getLogger('zen.thresholds')
16
18 "Class for holding multiple Thresholds, used in most collectors"
19
21 self.byKey = {}
22 self.byFilename = {}
23 self.byDevice = {}
24
26 d = self.byDevice.get(threshold.context().deviceName, None)
27 if d and threshold.key() in d:
28 del d[threshold.key()]
29 doomed = self.byKey.get(threshold.key(), None)
30 if doomed:
31 del self.byKey[doomed.key()]
32 ctx = doomed.context()
33 for dp in doomed.dataPoints():
34 lst = self.byFilename[ctx.fileKey(dp)]
35 if (doomed, dp) in lst:
36 lst.remove( (doomed, dp) )
37 if not lst:
38 del self.byFilename[ctx.fileKey(dp)]
39 return doomed
40
41 - def add(self, threshold):
42 self.byKey[threshold.key()] = threshold
43 d = self.byDevice.setdefault(threshold.context().deviceName, {})
44 d[threshold.key()] = threshold
45 ctx = threshold.context()
46 for dp in threshold.dataPoints():
47 self.byFilename.setdefault(ctx.fileKey(dp), []).append((threshold, dp))
48
50 "Store a threshold instance for future computation"
51 log.debug("Updating threshold %r", threshold.key())
52 doomed = self.remove(threshold)
53 if doomed:
54 threshold.count = doomed.count
55 self.add(threshold)
56
58 "Store a threshold instance for future computation"
59 for threshold in thresholds:
60 self.update(threshold)
61
64
74
75 - def check(self, filename, timeAt, value):
83
86
87 if __name__ == '__main__':
88 test()
89