-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdaq_alarms.py
75 lines (52 loc) · 1.88 KB
/
daq_alarms.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
67
68
69
70
71
72
73
74
75
from pagerduty_api import Alert
import subprocess
import os
import sys
import time
import pymongo
EB_SERVERS = ['eb0', 'eb1', 'eb2']
def get_db(host, db='untriggered'):
client = pymongo.MongoClient("mongodb://daq:%s@%s:27000/admin" % (os.environ.get('MONGO_PASSWORD'), host))
return client[db]
def get_daq_buffer_info():
data = {'name' : 'daq_buffer',
'time' : datetime.datetime.utcnow()}
for eb in EB_SERVERS:
data[eb] = get_db(eb).command({'dbstats': 1})
if data[eb]['dataSize'] > max_size:
max_size = data[eb]['dataSize']
return data, max_size
def db_size(resolve = False):
db = get_db(host='gw', db='run')
collection = db['pipeline_status']
collection.create_index("time", expireAfterSeconds=86400)
collection.insert(data)
my_key = 'PAGERDUTY_API_KEY_DAQ_BUFFER_SIZE'
if os.environ.get(my_key) is None:
print("Set environmental variable", my_key)
sys.exit()
data, max_size = get_max_size()
if max_size > 1e11:
alert = Alert(service_key=os.environ.get(my_key))
alert.trigger(
description='DAQ buffer is overflowing (more than 100 gigabyte)',
client='pipeline_alarms',
client_url='https://github.com/XENON1T/pipeline_alarms',
details=data
)
1e11
return
# my_key = 'PAGERDUTY_API_KEY_DAQ'
# if os.environ.get(my_key) is None:
# print("Set environmental variable", my_key)
# sys.exit()
# alert = Alert(service_key=os.environ.get(my_key))
# alert.trigger(
# description='Midway is not running massive cax',
# client='data_manager_alarms',
# client_url='https://github.com/XENON1T/data_manager_alarms',
# details={'ps output': output},
# )
while 1:
db_size()
time.sleep(60*60)