-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHipacheBackends.py
More file actions
69 lines (52 loc) · 2.45 KB
/
HipacheBackends.py
File metadata and controls
69 lines (52 loc) · 2.45 KB
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
import redis
import re
class HipacheBackends(object):
def __init__(self, agentConfig, checksLogger, rawConfig):
self.agentConfig = agentConfig
self.checksLogger = checksLogger
self.rawConfig = rawConfig
def run(self):
sum_dead_backends = 0
sum_frontends_with_no_backends = 0
sum_frontends_with_deadbackends = 0
sum_locked_backends = 0
try:
try:
host = self.rawConfig['Main']['redis_host']
except (KeyError, TypeError):
host = 'localhost'
try:
port = int(self.rawConfig['Main']['redis_port'])
except (KeyError, TypeError):
port = 6379
r = redis.StrictRedis(host=host, port=port)
# Get all frontends with dead backends
frontends_with_deadbackends = r.keys('dead:*')
sum_frontends_with_deadbackends = len(frontends_with_deadbackends)
# Get all hchecker locked backends
sum_locked_backends = len([lb for lb in r.hgetall('hchecker') if re.match('\S+:\d+;\S+#\d+', lb)])
# For each frontend with dead backends
for f in frontends_with_deadbackends:
# Get frontend name
frontend = re.search('^dead:(\S*)', f).group(1)
# Count all backends for frontend
backends = len(r.lrange('frontend:{0}'.format(frontend), 0, -1)) - 1
# Count dead backends for frontend
dead_backends = len(r.smembers(f))
# Sum all dead backends
sum_dead_backends = sum_dead_backends + dead_backends
# Check if all backends are marked dead for given frontend
if backends <= dead_backends:
sum_frontends_with_no_backends = sum_frontends_with_no_backends + 1
except Exception as e:
self.checksLogger.error('HipacheBackends failed to collect data: {}'.format(e))
sum_dead_backends = -1
sum_frontends_with_no_backends = -1
sum_frontends_with_deadbackends = -1
sum_locked_backends = -1
result = {}
result['Frontends_with_no_alive_backends'] = sum_frontends_with_no_backends
result['Frontends_with_dead_backends'] = sum_frontends_with_deadbackends
result['Dead_backends'] = sum_dead_backends
result['Hchecker_locked_backends'] = sum_locked_backends
return result