Last active
January 18, 2019 08:18
-
-
Save anviar/22c98af55e2a532cb572b285b142a6f7 to your computer and use it in GitHub Desktop.
Redis statistics extractor for collectd exec plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/opt/rh/rh-python36/root/usr/bin/python3 -u | |
from redis import Redis | |
from os import getenv | |
from platform import node | |
from time import sleep | |
hostname = getenv('COLLECTD_HOSTNAME', default=node()) | |
interval = int(float(getenv('COLLECTD_INTERVAL', default=60))) | |
r = Redis(host='localhost', port=6379, db=0, password='some_secret') | |
required_items = { | |
'connected_clients': 'memcached_connections-clients', | |
'used_memory': 'memory', | |
'instantaneous_ops_per_sec': 'memcached_ops' | |
} | |
while True: | |
info_data = r.info() | |
for item, value in info_data.items(): | |
if item in required_items: | |
print('PUTVAL "{}/redis/{}" interval={} N:{}'.format( | |
hostname, required_items[item], interval, value | |
), flush=True) | |
sleep(interval) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment