Skip to content

Commit

Permalink
Merge pull request powdahound#23 from RedWhiteMiko/master
Browse files Browse the repository at this point in the history
Support sending multiple values for same keys in redis.conf
  • Loading branch information
powdahound committed Mar 7, 2016
2 parents f512bc9 + 75ed71b commit 284b1da
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ You can configure to monitor multiple redis instances by the same machine by rep
Redis_used_memory_peak "bytes"
Redis_master_repl_offset "gauge"
</Module>
<Module redis_info>
Host "127.0.0.1"
Port 9102
Expand Down Expand Up @@ -135,6 +135,23 @@ This will result in metric names like: ```collectd.redis_info.redis-prod.bytes.u

```Instance``` can be empty, in this case the name of the metric will not contain any reference to the host/port. If it is omitted, the host:port value is added to the metric name.

### Multiple Data source types
You can send multiple data source types from same key by specifying it in the Module:

```
...
<Module redis_info>
Host "localhost"
Port 6379
Redis_total_net_input_bytes "bytes"
Redis_total_net_output_bytes "bytes"
Redis_total_net_input_bytes "derive"
Redis_total_net_output_bytes "derive"
</Module>
...
```

Graph examples
--------------
These graphs were created using collectd's [rrdtool plugin](http://collectd.org/wiki/index.php/Plugin:RRDtool) and [drraw](http://web.taranis.org/drraw/).
Expand Down
21 changes: 13 additions & 8 deletions redis_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@
CONFIGS = []
REDIS_INFO = {}

def fetch_info( conf ):

def fetch_info(conf):
"""Connect to Redis server and request info"""
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((conf['host'], conf['port']))
log_verbose('Connected to Redis at %s:%s' % (conf[ 'host' ], conf['port']))
log_verbose('Connected to Redis at %s:%s' % (conf['host'], conf['port']))
except socket.error, e:
collectd.error('redis_info plugin: Error connecting to %s:%d - %r'
% (conf['host'], conf['port'], e))
Expand Down Expand Up @@ -115,6 +116,7 @@ def parse_info(info_lines):

return info


def configure_callback(conf):
"""Receive configuration block"""
host = None
Expand All @@ -126,7 +128,7 @@ def configure_callback(conf):
key = node.key.lower()
val = node.values[0]
log_verbose('Analyzing config %s key (value: %s)' % (key, val))
searchObj = re.search( r'redis_(.*)$', key, re.M|re.I)
searchObj = re.search(r'redis_(.*)$', key, re.M|re.I)

if key == 'host':
host = val
Expand All @@ -142,7 +144,7 @@ def configure_callback(conf):
elif searchObj:
log_verbose('Matching expression found: key: %s - value: %s' % (searchObj.group(1), val))
global REDIS_INFO
REDIS_INFO[searchObj.group(1)] = val
REDIS_INFO[searchObj.group(1), val] = True
else:
collectd.warning('redis_info plugin: Unknown config key: %s.' % key )
continue
Expand All @@ -153,6 +155,8 @@ def configure_callback(conf):

def dispatch_value(info, key, type, plugin_instance=None, type_instance=None):
"""Read a key from info response data and dispatch a value"""


if key not in info:
collectd.warning('redis_info plugin: Info key not found: %s' % key)
return
Expand Down Expand Up @@ -193,11 +197,12 @@ def get_metrics( conf ):
if plugin_instance is None:
plugin_instance = '{host}:{port}'.format(host=conf['host'], port=conf['port'])

for key, val in REDIS_INFO.iteritems():
#log_verbose('key: %s - value: %s' % (key, val))
if key == 'total_connections_received':
for keyTuple, val in REDIS_INFO.iteritems():
key, val = keyTuple

if key == 'total_connections_received' and val == 'counter':
dispatch_value(info, 'total_connections_received', 'counter', plugin_instance, 'connections_received')
elif key == 'total_commands_processed':
elif key == 'total_commands_processed' and val == 'counter':
dispatch_value(info, 'total_commands_processed', 'counter', plugin_instance, 'commands_processed')
else:
dispatch_value(info, key, val, plugin_instance)
Expand Down

0 comments on commit 284b1da

Please sign in to comment.