Created
March 14, 2016 08:14
-
-
Save hrchu/2cf633fac749ba55d680 to your computer and use it in GitHub Desktop.
The mogstat collector of python-diamond collects utilization info from the mogilefs storage system.
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
import diamond.collector | |
import telnetlib | |
import time | |
class MogstatsCollector(diamond.collector.Collector): | |
def get_default_config_help(self): | |
config_help = super(MogstatsCollector, self).get_default_config_help() | |
config_help.update({ | |
}) | |
return config_help | |
def get_default_config(self): | |
""" | |
Returns the default collector settings | |
""" | |
config = super(MogstatsCollector, self).get_default_config() | |
config.update({ | |
'path': 'mogilefsd.stats' | |
}) | |
return config | |
def collect(self): | |
tn = telnetlib.Telnet("127.0.0.1", 7001, 3) | |
time.sleep(1) | |
tn.write( "!stats" + '\r\n' ) | |
out = tn.read_until('.', 3) | |
myvars = {} | |
for line in out.splitlines()[:-1]: | |
name, var = line.partition(" ")[::2] | |
myvars[name.strip()] = long(var) | |
for key, value in myvars.iteritems(): | |
# Set Metric Name | |
metric_name = key | |
# Set Metric Value | |
metric_value = value | |
# Publish Metric | |
self.publish(metric_name, metric_value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ref https://github.com/python-diamond/Diamond