Skip to content

Instantly share code, notes, and snippets.

@jaylett
Created July 27, 2012 10:24
Show Gist options
  • Save jaylett/3187313 to your computer and use it in GitHub Desktop.
Save jaylett/3187313 to your computer and use it in GitHub Desktop.
Redis plugin for munin
#!/usr/bin/python
# -*- python-mode -*-
import sys
import redis
c = redis.Redis() # if you need a password or to monitor non-defaults...
# We draw a number of graphs:
#
# blocked_clients, connected_clients, connected_slaved
# for each db: expires/keys
# total across all dbs: expires/keys
# used_cpu_sys, used_cpu_user
# used_memory, used_memory_rss, mem_fragmentation_ratio
# changes_since_last_save
# Others we could do but don't yet:
#
# hash_max_zipmap_entries, hash_max_zipmap_value
# keyspace_hits, keyspace_misses
# pubsub_channels, pubsub_patterns
# total_commands_processed, total_connections_received
# client_biggest_input_buf
# client_longest_output_list
info = c.info()
if len(sys.argv) > 1 and sys.argv[1] == 'config':
print """
multigraph redis_clients
graph_title Redis clients
graph_vlabel Clients
graph_category Other
connected.label Connected
connected.type GAUGE
slaves.label Slaves
slaves.type GAUGE
blocked.label Blocked
blocked.type GAUGE
multigraph redis_cpu
graph_title Redis CPU usage
graph_vlabel CPU usage in milliseconds
graph_category Other
graph_args --base 1000 -l 0
sys.label System
sys.type COUNTER
user.label User
user.type COUNTER
multigraph redis_mem
graph_title Redis memory usage
graph_vlabel Memory usage
graph_args --base 1024 -l 0
graph_category Other
used.label Used
used.type GAUGE
rss.label RSS
rss.type GAUGE
frag.label Fragmentation %
frag.type GAUGE
"""
for k in [ k for k in info.keys() if k.startswith('db') ]:
print """
multigraph redis_keys.db%(db)s
graph_title Redis keys (db %(db)s)
graph_vlabel Keys
graph_category Other
graph_args --base 1000 -l 0
expires.label Expires
expires.type GAUGE
keys.label Stored keys
keys.type GAUGE
""".strip() % {
'db': k[2:],
}
print
print """
multigraph redis_keys
graph_title Redis keys
graph_vlabel Keys
graph_args --base 1000 -l 0
graph_category Other
expires.label Expires
expires.type GAUGE
keys.label Stored keys
keys.type GAUGE
""".strip()
sys.exit(0)
print """
multigraph redis_clients
connected.value %(connected)s
slaves.value %(slaves)s
blocked.value %(blocked)s
multigraph redis_cpu
sys.value %(sys)s
user.value %(user)s
multigraph redis_mem
used.value %(used)s
rss.value %(rss)s
frag.value %(frag)s
""" % {
'connected': info['connected_clients'],
'slaves': info['connected_slaves'],
'blocked': info['blocked_clients'],
'sys': int(1000*info['used_cpu_sys']),
'user': int(1000*info['used_cpu_user']),
'used': info['used_memory'],
'rss': info['used_memory_rss'],
'frag': info['mem_fragmentation_ratio'],
}
expires = 0
keys = 0
for k in [ k for k in info.keys() if k.startswith('db') ]:
print """
multigraph redis_keys.db%(db)s
expires.value %(expires)s
keys.value %(keys)s
""".strip() % {
'db': k[2:],
'expires': info[k]['expires'],
'keys': info[k]['keys'],
}
expires += info[k]['expires']
keys += info[k]['keys']
print
print """
multigraph redis_keys
expires.value %(expires)s
keys.value %(keys)s
""".strip() % {
'expires': expires,
'keys': keys,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment