-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathNetworkLHCOPNCollector.py
51 lines (38 loc) · 1.21 KB
/
NetworkLHCOPNCollector.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
#!/usr/bin/env python
# TO BE RUN ONLY AT CERN
import threading
# from threading import Thread
import copy
import json
# import hashlib
import collector
class NetworkLHCOPNCollector(collector.Collector):
def __init__(self):
self.TOPIC = "/topic/netflow.lhcopn"
self.INDEX = 'ps_lhcopn_write'
super(NetworkLHCOPNCollector, self).__init__()
def eventCreator(self, message):
m = json.loads(message)
data = {
}
if 'data' not in m:
print(threading.current_thread().name, 'no data in this message!')
return
source = m['data']['src_site']
destination = m['data']['dst_site']
data['MA'] = 'capc.cern'
data['src_interface'] = source
data['dest_interface'] = destination
ts = m['data']['timestamp']
th = m['data']['throughput']
data['_index'] = self.INDEX
data['timestamp'] = int(float(ts) * 1000)
data['_id'] = self.calculateId(m, data['timestamp'])
data['utilization'] = int(th)
# print(data)
self.aLotOfData.append(copy.copy(data))
def main():
collector = NetworkLHCOPNCollector()
collector.start()
if __name__ == "__main__":
main()