-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRedisStatus.py
More file actions
34 lines (25 loc) · 904 Bytes
/
RedisStatus.py
File metadata and controls
34 lines (25 loc) · 904 Bytes
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
import redis
from redis.exceptions import ConnectionError
class Redis(object):
def __init__(self, agentConfig, checksLogger, rawConfig):
self.agentConfig = agentConfig
self.checksLogger = checksLogger
self.rawConfig = rawConfig
def run(self):
info = {'running': 0}
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)
try:
info = r.info()
info['running'] = 1
info['keys_on_db0'] = r.info()['db0']['keys']
except ConnectionError as e:
self.checksLogger.error('Failed to collect data: {}'.format(e))
return info