-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.py
53 lines (41 loc) · 1.38 KB
/
index.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
import redis
import sys
import time
import socket
import boundary_plugin
params = boundary_plugin.parse_params()
redis_server = params.get('redis_hostname', None) or 'localhost'
redis_port = int(params.get('redis_port', None) or 6379)
redis_password = params.get('redis_password', None) or None
if not redis_password:
redis_password = None
r = redis.Redis(redis_server, redis_port, password=redis_password)
_accum = dict()
def accum(stat_name, new_value):
global _accum
try:
old_value = _accum[stat_name]
except KeyError:
old_value = new_value
diff = new_value - old_value
_accum[stat_name] = new_value
return diff
# List of values returned from Redis' info call to report to Boundary.
# Each value has a boolean specifying whether to aggregate data (i.e. report
# only delta from the previous value) or report the metric as-is.
values_to_report = (
('connected_clients', False),
('keyspace_hits', True),
('keyspace_misses', True),
('expired_keys', True),
('evicted_keys', True),
('total_commands_processed', True),
('total_connections_received', True),
('used_memory_rss', False),
)
while True:
info = r.info()
for v,aggregate in values_to_report:
val = accum(v, info[v]) if aggregate else info[v]
boundary_plugin.boundary_report_metric('REDIS_' + v.upper(), val)
boundary_plugin.sleep_interval()