-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathwatcher.py
executable file
·54 lines (44 loc) · 1.33 KB
/
watcher.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
#!/usr/bin/env python
import requests
import json
import time
import datetime
# this monitors your kiln stats every N seconds
# if X checks fail, an alert is sent to a slack channel
# configure an incoming web hook on the slack channel
# set slack_hook_url to that
def get_stats():
try:
r = requests.get(kiln_url,timeout=1)
return r.json()
except:
return {}
def send_alert(msg):
try:
r = requests.post(slack_hook_url, json={'text': msg })
except:
pass
if __name__ == "__main__":
kiln_url = "http://0.0.0.0:8081/api/stats"
slack_hook_url = "you must set this"
bad_check_limit = 6
bad_checks = 0
temp_error_limit = 10
sleepfor = 10
while(True):
stats = get_stats()
if 'time' not in stats:
bad_checks = bad_checks + 1
print("no data")
if 'err' in stats:
if abs(stats['err']) > temp_error_limit:
bad_checks = bad_checks + 1
print ("temp out of whack")
if bad_checks >= bad_check_limit:
print("ERR sending alert")
msg = "error kiln needs help. %s" % json.dumps(stats,indent=2, sort_keys=True)
send_alert(msg)
bad_checks = 0
else:
print("OK %s" % datetime.datetime.now())
time.sleep(sleepfor)