6
6
import logging
7
7
8
8
# this monitors your kiln stats every N seconds
9
- # if there are bad_check_limit failures , an alert is sent to a slack channel
9
+ # if X checks fail , an alert is sent to a slack channel
10
10
# configure an incoming web hook on the slack channel
11
11
# set slack_hook_url to that
12
12
13
+ logging .basicConfig (level = logging .INFO )
13
14
log = logging .getLogger (__name__ )
14
15
15
16
class Watcher (object ):
@@ -31,30 +32,30 @@ def get_stats(self):
31
32
return {}
32
33
33
34
def send_alert (self ,msg ):
34
- log .error ("ERR sending alert: %s" % msg )
35
+ log .error ("sending alert: %s" % msg )
35
36
try :
36
37
r = requests .post (self .slack_hook_url , json = {'text' : msg })
37
38
except :
38
39
pass
39
40
40
41
def has_errors (self ):
41
42
if 'time' not in self .stats :
42
- log .error ("ERR no data" )
43
+ log .error ("no data" )
43
44
return True
44
45
if 'err' in self .stats :
45
46
if abs (self .stats ['err' ]) > self .temp_error_limit :
46
- log .error ("ERR temp out of whack %0.2f" % self .stats ['err' ])
47
+ log .error ("temp out of whack %0.2f" % self .stats ['err' ])
47
48
return True
48
49
return False
49
50
50
51
def run (self ):
51
- log .info ("OK started watching %s" % self .kiln_url )
52
+ log .info ("started watching %s" % self .kiln_url )
52
53
while (True ):
53
54
self .stats = self .get_stats ()
54
55
if self .has_errors ():
55
56
self .bad_checks = self .bad_checks + 1
56
57
else :
57
- log .info ("OK %s" % datetime .datetime .now ())
58
+ log .info ("%s" % datetime .datetime .now ())
58
59
59
60
if self .bad_checks >= self .bad_check_limit :
60
61
msg = "error kiln needs help. %s" % json .dumps (self .stats ,indent = 2 , sort_keys = True )
0 commit comments