mirror of
https://github.com/munin-monitoring/contrib.git
synced 2018-11-08 00:59:34 +01:00
use print_function
This commit is contained in:
parent
2290efb3d3
commit
67746dcced
@ -15,6 +15,8 @@
|
|||||||
# ln -s /usr/share/munin/plugins/ethermine_ /etc/munin/plugins/ethermine_3257bde8cf067ae6f1ddc0e4b140fe02e3c5e44f_mine
|
# ln -s /usr/share/munin/plugins/ethermine_ /etc/munin/plugins/ethermine_3257bde8cf067ae6f1ddc0e4b140fe02e3c5e44f_mine
|
||||||
#
|
#
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import urllib2
|
import urllib2
|
||||||
@ -28,62 +30,37 @@ if len(sys.argv) > 1:
|
|||||||
command = sys.argv[1]
|
command = sys.argv[1]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
OPTIONS[1]
|
ETH_ADDRESS, MINER = sys.argv[0].split("_")[1:]
|
||||||
except IndexError:
|
except ValueError:
|
||||||
print "Ethereum address missing!"
|
print("The filename of this plugin (or its symlink) should follow this pattern: "
|
||||||
sys.exit(9)
|
"'<YOUR_PUBLIC_ETHEREUM_ADDRESS>_<YOUR_RIG_NAME>'", file=sys.stderr)
|
||||||
|
sys.exit(0)
|
||||||
ETH_ADDRESS = OPTIONS[1]
|
|
||||||
|
|
||||||
if ETH_ADDRESS == "":
|
|
||||||
print "Ethereum address missing!"
|
|
||||||
sys.exit(9)
|
|
||||||
|
|
||||||
try:
|
|
||||||
OPTIONS[2]
|
|
||||||
except IndexError:
|
|
||||||
print "Rig name missing!"
|
|
||||||
sys.exit(9)
|
|
||||||
|
|
||||||
MINER = OPTIONS[2]
|
|
||||||
|
|
||||||
if MINER == "":
|
|
||||||
print "Rig name missing!"
|
|
||||||
sys.exit(9)
|
|
||||||
|
|
||||||
if command == 'config':
|
if command == 'config':
|
||||||
print "graph_title Ethermine " + MINER
|
print("graph_title Ethermine {}".format(ETH_ADDRESS))
|
||||||
print "graph_info Ethermine Hashrate " + ETH_ADDRESS +"/" + MINER
|
print("graph_info Ethermine Hashrate {}/{}".format(ETH_ADDRESS, MINER))
|
||||||
print "graph_vlabel Ethermine Hashrate"
|
print("graph_vlabel Ethermine Hashrate")
|
||||||
print "graph_category htc"
|
print("graph_category htc")
|
||||||
print ETH_ADDRESS + "_" + MINER + ".warning 20:"
|
print("{}_{}.warning 20:".format(ETH_ADDRESS, MINER));
|
||||||
print ETH_ADDRESS + "_" + MINER + ".critical 10:"
|
print("{}_{}.critical 10:".format(ETH_ADDRESS, MINER));
|
||||||
print ETH_ADDRESS + "_" + MINER + ".label MH/s"
|
print("{}_{}.label MH/s:".format(ETH_ADDRESS, MINER));
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
POOL_URL = 'https://ethermine.org/api/miner_new'
|
ETHERMINE_API_URL = 'https://ethermine.org/api/miner_new/' + ETH_ADDRESS
|
||||||
STATS = POOL_URL + '/' + ETH_ADDRESS
|
|
||||||
|
|
||||||
mining_req = urllib2.Request(STATS)
|
mining_req = urllib2.Request(ETHERMINE_API_URL)
|
||||||
mining_req.add_header('User-Agent', 'Mozilla/5.0')
|
mining_req.add_header('User-Agent', 'Mozilla/5.0')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mining_stats_raw = urllib2.urlopen(mining_req, None, 1.5 )
|
mining_stats_raw = urllib2.urlopen(mining_req, timeout=1.5 )
|
||||||
except urllib2.HTTPError as e:
|
except IOError as exc:
|
||||||
print "HTTP Error!"
|
print("Failed to request ethermine.org API: {}".format(exc), file=sys.stderr)
|
||||||
sys.exit(9)
|
|
||||||
except urllib2.URLError:
|
|
||||||
print "HTTP URL Error!"
|
|
||||||
sys.exit(9)
|
|
||||||
except socket.timeout:
|
|
||||||
print "HTTP Timed out!"
|
|
||||||
sys.exit(9)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mining_stats = json.load(mining_stats_raw)
|
mining_stats = json.load(mining_stats_raw)
|
||||||
except:
|
except ValueError:
|
||||||
print "JSON Error!"
|
print("Failed to parse JSON responce.", file=sys.stderr);
|
||||||
sys.exit(9)
|
sys.exit(9)
|
||||||
|
|
||||||
workers = mining_stats['workers']
|
workers = mining_stats['workers']
|
||||||
@ -93,4 +70,4 @@ for worker in workers:
|
|||||||
if workers[worker]['worker'] == MINER:
|
if workers[worker]['worker'] == MINER:
|
||||||
hash_rate = workers[worker]['hashrate']
|
hash_rate = workers[worker]['hashrate']
|
||||||
hash_rate = hash_rate.replace(" MH/s", "")
|
hash_rate = hash_rate.replace(" MH/s", "")
|
||||||
print ETH_ADDRESS + "_" + MINER + ".value %s " % hash_rate
|
print("{}_{}.value %s".format(ETH_ADDRESS, MINER, hash_rate));
|
Loading…
Reference in New Issue
Block a user