Created
July 23, 2012 23:28
-
-
Save nnfuzzy/3166916 to your computer and use it in GitHub Desktop.
redis2.6 ganglia
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
https://github.com/ganglia/gmond_python_modules/tree/master/redis | |
I got some problems, so I changed the metric handler | |
def metric_handler(name): | |
# Update from Redis. Don't thrash. | |
if 15 < time.time() - metric_handler.timestamp: | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.connect((metric_handler.host, metric_handler.port)) | |
s.settimeout(5) # set socket timeout as to not block gmond | |
# if the password is set from parameters | |
if metric_handler.password != None: | |
s.send("AUTH {0}\r\n".format(metric_handler.password)) | |
s.recv(4096) # TODO check if auth is valid | |
s.send("INFO\r\n") | |
info = s.recv(4096) | |
print info | |
if "$" != info[0]: | |
return 0 | |
len = int(info[1:info.find("\n")]) | |
if 4096 < len: | |
info += s.recv(len - 4096) | |
metric_handler.info = {} | |
""" very small fix by Chr.Schulz """ | |
for line in info.splitlines()[1:]: | |
if str(line).startswith('#')==True or str(line) =="": | |
continue | |
print "debug:", line | |
n, v = line.split(":") | |
if n in metric_handler.descriptors: | |
metric_handler.info[n] = int(v) # TODO Use value_type. | |
s.close() | |
metric_handler.timestamp = time.time() | |
return metric_handler.info.get(name, 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment