mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-26 02:48:28 +00:00
better user agent and some small fixes
This commit is contained in:
parent
497e66ddcb
commit
4f14867969
2 changed files with 18 additions and 12 deletions
|
@ -28,7 +28,7 @@ if len(sys.argv) > 1:
|
||||||
command = sys.argv[1]
|
command = sys.argv[1]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
eth_address, miner = sys.argv[0].split("_")[1:]
|
eth_address, miner = sys.argv[0].split("_")[2:]
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print("The filename of this plugin (or its symlink) should follow this pattern: "
|
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)
|
"'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
|
ethermine_api_url = 'https://ethermine.org/api/miner_new/' + eth_address
|
||||||
|
|
||||||
mining_req = urllib2.Request(ethermine_api_url)
|
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:
|
try:
|
||||||
mining_stats_raw = urllib2.urlopen(mining_req, timeout=1.5 )
|
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);
|
print("Failed to parse JSON responce.", file=sys.stderr);
|
||||||
sys.exit(9)
|
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.
|
# ethermine.org sometimes has caching errors. You can see data from other miner. Always check your rig name.
|
||||||
for worker in workers:
|
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("{}_{}.value %s".format(eth_address, miner, hash_rate));
|
print("{}_{}.value {}".format(eth_address, miner, hash_rate));
|
|
@ -28,9 +28,10 @@ command = ''
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
command = sys.argv[1]
|
command = sys.argv[1]
|
||||||
|
|
||||||
try:
|
|
||||||
eth_address = sys.argv[0][(sys.argv[0].rfind('_')+1):]
|
api_action, eth_address = sys.argv[0].split("_")[1:]
|
||||||
except ValueError:
|
|
||||||
|
if not eth_address:
|
||||||
print("The filename of this plugin (or its symlink) should follow this pattern: "
|
print("The filename of this plugin (or its symlink) should follow this pattern: "
|
||||||
"'etherscan_balance_<YOUR_PUBLIC_ETHEREUM_ADDRESS>'", file=sys.stderr)
|
"'etherscan_balance_<YOUR_PUBLIC_ETHEREUM_ADDRESS>'", file=sys.stderr)
|
||||||
sys.exit(9)
|
sys.exit(9)
|
||||||
|
@ -41,14 +42,14 @@ if command == 'config':
|
||||||
print("graph_info Ethereum Account Balance for Address {}".format(eth_address))
|
print("graph_info Ethereum Account Balance for Address {}".format(eth_address))
|
||||||
print("graph_title Ethereum Balance")
|
print("graph_title Ethereum Balance")
|
||||||
print("graph_title htc")
|
print("graph_title htc")
|
||||||
print("{}label eth".format(eth_address))
|
print("{}.label ETH".format(eth_address))
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
ethercan_balance_api_url = 'https://api.etherscan.io/api?module=account&action=balance&tag=latest&address=' + eth_address
|
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)
|
etherscan_req = urllib2.Request(ethercan_balance_api_url)
|
||||||
# User-Agent
|
# User-Agent to bypass Cloudflare
|
||||||
etherscan_req.add_header('User-Agent', 'Mozilla/5.0')
|
etherscan_req.add_header('User-Agent', 'Etherscan Munin Plugin/1.0')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
etherscan_balance_raw = urllib2.urlopen(etherscan_req, timeout=1.5 )
|
etherscan_balance_raw = urllib2.urlopen(etherscan_req, timeout=1.5 )
|
||||||
|
@ -64,8 +65,8 @@ except ValueError:
|
||||||
try:
|
try:
|
||||||
float(etherscan_balance['result'])
|
float(etherscan_balance['result'])
|
||||||
except:
|
except:
|
||||||
print("Result Error!", file=sys.stderr);
|
print("JSON result error!", file=sys.stderr);
|
||||||
sys.exit(9)
|
sys.exit(9)
|
||||||
|
|
||||||
eth = float(etherscan_balance['result']) / 1000000000000000000
|
eth = float(etherscan_balance['result']) / 1000000000000000000
|
||||||
print("{}_{}.value %.2f".format(eth_address, eth));
|
print("{}.value {:.2f}".format(eth_address, eth));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue