root / plugins / ethereum / ethermine_hashrate_ @ 497e66dd
Historique | Voir | Annoter | Télécharger (2,11 ko)
| 1 |
#!/usr/bin/env python |
|---|---|
| 2 |
|
| 3 |
# |
| 4 |
# ethermine_hashrate_ |
| 5 |
# |
| 6 |
# Munin plugin to monitor your ethermine.org hashrate. |
| 7 |
# |
| 8 |
# Author: Nils Knieling - https://github.com/Cyclenerd |
| 9 |
# Licence: GPLv2 |
| 10 |
# |
| 11 |
# USAGE |
| 12 |
# ethermine_hashrate_<YOUR_PUBLIC_ETHEREUM_ADDRESS>_<YOUR_RIG_NAME> |
| 13 |
# |
| 14 |
# EXAMPLE |
| 15 |
# ln -s /usr/share/munin/plugins/ethermine_hashrate_ /etc/munin/plugins/ethermine_hashrate_3257bde8cf067ae6f1ddc0e4b140fe02e3c5e44f_mine |
| 16 |
# |
| 17 |
|
| 18 |
from __future__ import print_function |
| 19 |
|
| 20 |
import os |
| 21 |
import sys |
| 22 |
import urllib2 |
| 23 |
import socket |
| 24 |
import json |
| 25 |
|
| 26 |
command = '' |
| 27 |
if len(sys.argv) > 1: |
| 28 |
command = sys.argv[1] |
| 29 |
|
| 30 |
try: |
| 31 |
eth_address, miner = sys.argv[0].split("_")[1:]
|
| 32 |
except ValueError: |
| 33 |
print("The filename of this plugin (or its symlink) should follow this pattern: "
|
| 34 |
"'ethermine_hashrate_<YOUR_PUBLIC_ETHEREUM_ADDRESS>_<YOUR_RIG_NAME>'", file=sys.stderr) |
| 35 |
sys.exit(9) |
| 36 |
|
| 37 |
if command == 'config': |
| 38 |
print("graph_title Ethermine {}".format(eth_address))
|
| 39 |
print("graph_info Ethermine Hashrate {}/{}".format(eth_address, miner))
|
| 40 |
print("graph_vlabel Ethermine Hashrate")
|
| 41 |
print("graph_category htc")
|
| 42 |
print("{}_{}.warning 20:".format(eth_address, miner));
|
| 43 |
print("{}_{}.critical 10:".format(eth_address, miner));
|
| 44 |
print("{}_{}.label MH/s:".format(eth_address, miner));
|
| 45 |
sys.exit(0) |
| 46 |
|
| 47 |
|
| 48 |
ethermine_api_url = 'https://ethermine.org/api/miner_new/' + eth_address |
| 49 |
|
| 50 |
mining_req = urllib2.Request(ethermine_api_url) |
| 51 |
mining_req.add_header('User-Agent', 'Mozilla/5.0')
|
| 52 |
|
| 53 |
try: |
| 54 |
mining_stats_raw = urllib2.urlopen(mining_req, timeout=1.5 ) |
| 55 |
except IOError as exc: |
| 56 |
print("Failed to request ethermine.org API: {}".format(exc), file=sys.stderr)
|
| 57 |
|
| 58 |
try: |
| 59 |
mining_stats = json.load(mining_stats_raw) |
| 60 |
except ValueError: |
| 61 |
print("Failed to parse JSON responce.", file=sys.stderr);
|
| 62 |
sys.exit(9) |
| 63 |
|
| 64 |
workers = mining_stats['workers'] |
| 65 |
|
| 66 |
# ethermine.org sometimes has caching errors. You can see data from other miner. Always check your rig name. |
| 67 |
for worker in workers: |
| 68 |
if workers[worker]['worker'] == miner: |
| 69 |
hash_rate = workers[worker]['hashrate'] |
| 70 |
hash_rate = hash_rate.replace(" MH/s", "")
|
| 71 |
print("{}_{}.value %s".format(eth_address, miner, hash_rate));
|
