diff --git a/plugins/ethereum/ethermine_hashrate_ b/plugins/ethereum/ethermine_hashrate_ index 9dc068e9..e3f4f8e4 100755 --- a/plugins/ethereum/ethermine_hashrate_ +++ b/plugins/ethereum/ethermine_hashrate_ @@ -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__'", 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)); \ No newline at end of file + print("{}_{}.value {}".format(eth_address, miner, hash_rate)); \ No newline at end of file diff --git a/plugins/ethereum/etherscan_balance_ b/plugins/ethereum/etherscan_balance_ index b3fe0f5c..5e211fac 100755 --- a/plugins/ethereum/etherscan_balance_ +++ b/plugins/ethereum/etherscan_balance_ @@ -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_'", 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));