Skip to content

Instantly share code, notes, and snippets.

@hrchu
Created March 14, 2016 08:14
Show Gist options
  • Save hrchu/2cf633fac749ba55d680 to your computer and use it in GitHub Desktop.
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.
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)
@hrchu
Copy link
Author

hrchu commented Mar 14, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment