2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01: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));

View File

@ -28,9 +28,10 @@ command = ''
if len(sys.argv) > 1:
command = sys.argv[1]
try:
eth_address = sys.argv[0][(sys.argv[0].rfind('_')+1):]
except ValueError:
api_action, eth_address = sys.argv[0].split("_")[1:]
if not eth_address:
print("The filename of this plugin (or its symlink) should follow this pattern: "
"'etherscan_balance_<YOUR_PUBLIC_ETHEREUM_ADDRESS>'", file=sys.stderr)
sys.exit(9)
@ -41,14 +42,14 @@ if command == 'config':
print("graph_info Ethereum Account Balance for Address {}".format(eth_address))
print("graph_title Ethereum Balance")
print("graph_title htc")
print("{}label eth".format(eth_address))
print("{}.label ETH".format(eth_address))
sys.exit(0)
ethercan_balance_api_url = 'https://api.etherscan.io/api?module=account&action=balance&tag=latest&address=' + eth_address
etherscan_req = urllib2.Request(ethercan_balance_api_url)
# User-Agent
etherscan_req.add_header('User-Agent', 'Mozilla/5.0')
# User-Agent to bypass Cloudflare
etherscan_req.add_header('User-Agent', 'Etherscan Munin Plugin/1.0')
try:
etherscan_balance_raw = urllib2.urlopen(etherscan_req, timeout=1.5 )
@ -64,8 +65,8 @@ except ValueError:
try:
float(etherscan_balance['result'])
except:
print("Result Error!", file=sys.stderr);
print("JSON result error!", file=sys.stderr);
sys.exit(9)
eth = float(etherscan_balance['result']) / 1000000000000000000
print("{}_{}.value %.2f".format(eth_address, eth));
print("{}.value {:.2f}".format(eth_address, eth));