Last active
October 10, 2018 21:33
-
-
Save iMilnb/eb79dd24e1bac491b9d7188fdddcfe39 to your computer and use it in GitHub Desktop.
collectd-python plugin to read data from ethermine.org
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
<Plugin python> | |
ModulePath "/home/imil/collectd" | |
Import "ethermine" | |
<Module ethermine> | |
wallet "0xf00f00f00" | |
interval "300" | |
url "https://ethermine.org/api/miner_new" | |
</Module> | |
</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
from __future__ import division | |
import requests | |
import collectd | |
cfg = { | |
'wallet': '0xf00b', | |
'interval': '300', | |
'url': 'http://localhost' | |
} | |
def readconf(config): | |
for node in config.children: | |
for k in ['wallet', 'interval', 'url']: | |
if node.key == k: | |
cfg[k] = node.values[0] | |
collectd.info('{0} set to: {1}'.format(k, cfg[k])) | |
cfg['url'] = '{0}/{1}'.format(cfg['url'], cfg['wallet'][2:]) | |
def readvals(): | |
collectd.info('calling {0}'.format(cfg['url'])) | |
try: | |
j = requests.get(cfg['url']).json() | |
except ValueError, e: | |
collectd.info(str(e)) | |
return | |
val = [ | |
{ | |
'k': 'reportedHashRate', | |
'v': j['reportedHashRate'].split()[0], | |
't': 'gauge' | |
}, | |
{ | |
'k': 'unpaid', | |
'v': float(j['unpaid']) / 1000000000000000000, | |
't': 'gauge' | |
}, | |
{ 'k': 'usdPerMin', 'v': j['usdPerMin'], 't': 'gauge' } | |
] | |
for v in val: | |
c = collectd.Values(type = v['t']) | |
c.plugin = v['k'] | |
c.dispatch(values = [v['v']]) | |
collectd.register_config(readconf) | |
collectd.register_read(readvals, int(cfg['interval'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jedimstr did you have a look to the logs? Usually
collectd
logs tosyslog
and has pretty comprehensive output