Last active
December 7, 2016 18:41
-
-
Save mash/8571829 to your computer and use it in GitHub Desktop.
dstat redis plugin
This file contains hidden or 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
### Author: Masakazu Ohtsuka <[email protected]> | |
class Config(): | |
def __init__(self): | |
import ConfigParser | |
self.conf = ConfigParser.ConfigParser() | |
import inspect | |
this_file = inspect.getfile(inspect.currentframe()) | |
conf_file = this_file + ".conf" | |
try: | |
with open(conf_file): | |
self.conf.read(conf_file) | |
except IOError: | |
print "conf file "+conf_file+" not found, using only ENV" | |
# prioritize ENV variable > conf file | |
def get(self,key): | |
ret = os.getenv("DSTAT_REDIS_" + key.upper()) | |
if not ret: | |
try: | |
ret = self.conf.get("DEFAULT",key) | |
except: pass | |
return ret | |
config = Config() | |
global redis_info_keys | |
redis_info_keys = config.get("info_keys") | |
if not redis_info_keys: raise Exception, "provide conf file or DSTAT_REDIS_INFO_KEYS env" | |
redis_info_keys = redis_info_keys.split(',') | |
global column_width | |
column_width = config.get("column_width") or 10 | |
global redis_host | |
redis_host = config.get("host") or '127.0.0.1' | |
global redis_port | |
redis_port = config.get("port") or 6379 | |
global redis_db | |
redis_db = config.get("db") or 0 | |
class dstat_plugin(dstat): | |
""" | |
Redis info plugin. | |
""" | |
def __init__(self): | |
self.name = 'redis' | |
self.nick = ('') | |
self.vars = redis_info_keys | |
self.type = 'f' | |
self.width = column_width | |
self.scale = 0 | |
def check(self): | |
try: | |
import redis | |
self.r = redis.Redis(host=redis_host,port=redis_port,db=redis_db) | |
except: | |
raise Exception, 'Plugin needs the redis module' | |
def extract(self): | |
info = self.r.info() | |
for key in self.vars: | |
self.val[key] = info[key] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment