1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-08-07 14:43:13 +00:00

better user agent and some small fixes

This commit is contained in:
Nils 2017-06-28 20:33:58 +02:00
parent 497e66ddcb
commit 4f14867969
2 changed files with 18 additions and 12 deletions

View file

@ -28,7 +28,7 @@ if len(sys.argv) > 1:
command = sys.argv[1]
try:
eth_address, miner = sys.argv[0].split("_")[1:]
eth_address, miner = sys.argv[0].split("_")[2:]
except ValueError:
print("The filename of this plugin (or its symlink) should follow this pattern: "
"'ethermine_hashrate_<YOUR_PUBLIC_ETHEREUM_ADDRESS>_<YOUR_RIG_NAME>'", file=sys.stderr)
@ -48,7 +48,8 @@ if command == 'config':
ethermine_api_url = 'https://ethermine.org/api/miner_new/' + eth_address
mining_req = urllib2.Request(ethermine_api_url)
mining_req.add_header('User-Agent', 'Mozilla/5.0')
# User-Agent to bypass Cloudflare
mining_req.add_header('User-Agent', 'Ethermine Munin Plugin/1.0')
try:
mining_stats_raw = urllib2.urlopen(mining_req, timeout=1.5 )
@ -61,11 +62,15 @@ except ValueError:
print("Failed to parse JSON responce.", file=sys.stderr);
sys.exit(9)
workers = mining_stats['workers']
try:
workers = mining_stats['workers']
except:
print("JSON result error!", file=sys.stderr);
sys.exit(9)
# ethermine.org sometimes has caching errors. You can see data from other miner. Always check your rig name.
for worker in workers:
if workers[worker]['worker'] == miner:
hash_rate = workers[worker]['hashrate']
hash_rate = hash_rate.replace(" MH/s", "")
print("{}_{}.value %s".format(eth_address, miner, hash_rate));
print("{}_{}.value {}".format(eth_address, miner, hash_rate));