From 72b060db91735ec56f1f355f74969decd67a04d1 Mon Sep 17 00:00:00 2001 From: Nils Date: Tue, 27 Jun 2017 19:06:01 +0200 Subject: [PATCH 01/23] New plugin ethermine_ Munin plugin to monitor your ethermine.org hashrate. --- plugins/ethereum/ethermine_ | 96 +++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100755 plugins/ethereum/ethermine_ diff --git a/plugins/ethereum/ethermine_ b/plugins/ethereum/ethermine_ new file mode 100755 index 00000000..fdd87596 --- /dev/null +++ b/plugins/ethereum/ethermine_ @@ -0,0 +1,96 @@ +#!/usr/bin/env python + +# +# ethermine_ +# +# Munin plugin to monitor your ethermine.org hashrate. +# +# Author: Nils Knieling - https://github.com/Cyclenerd +# Licence: GPLv2 +# +# USAGE +# ethermine__ +# +# EXAMPLE +# ln -s /usr/share/munin/plugins/ethermine_ /etc/munin/plugins/ethermine_3257bde8cf067ae6f1ddc0e4b140fe02e3c5e44f_mine +# + +import os, sys, urllib2, socket, json + +OPTIONS = sys.argv[0].split('_') + +command = '' +if len(sys.argv) > 1: + command = sys.argv[1] + +if command == 'suggest': + print "ethermine__" + sys.exit(0) + +try: + OPTIONS[1] +except IndexError: + print "Ethereum address missing!" + sys.exit(9) + +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': + print "graph_title Ethermine " + MINER + print "graph_info Ethermine Hashrate " + ETH_ADDRESS +"/" + MINER + print "graph_vlabel Ethermine Hashrate" + print "graph_category htc" + print ETH_ADDRESS + "_" + MINER + ".warning 20:" + print ETH_ADDRESS + "_" + MINER + ".critical 10:" + print ETH_ADDRESS + "_" + MINER + ".label MH/s" + sys.exit(0) + + +POOL_URL = 'https://ethermine.org/api/miner_new' +STATS = POOL_URL + '/' + ETH_ADDRESS + +mining_req = urllib2.Request(STATS) +mining_req.add_header('User-Agent', 'Mozilla/5.0') + +try: + mining_stats_raw = urllib2.urlopen(mining_req, None, 1.5 ) +except urllib2.HTTPError as e: + print "HTTP Error!" + sys.exit(9) +except urllib2.URLError: + print "HTTP URL Error!" + sys.exit(9) +except socket.timeout: + print "HTTP Timed out!" + sys.exit(9) + +try: + mining_stats = json.load(mining_stats_raw) +except: + print "JSON Error!" + sys.exit(9) + +workers = mining_stats['workers'] + +# 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 ETH_ADDRESS + "_" + MINER + ".value %s " % hash_rate \ No newline at end of file From 6db40b77deefe27b3706b9ff0d6ce9a747c8e1ef Mon Sep 17 00:00:00 2001 From: Nils Date: Tue, 27 Jun 2017 19:06:23 +0200 Subject: [PATCH 02/23] New plugin etherscan_balance_ Munin plugin to monitor your ethereum (ETH) balance. --- plugins/ethereum/etherscan_balance_ | 83 +++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100755 plugins/ethereum/etherscan_balance_ diff --git a/plugins/ethereum/etherscan_balance_ b/plugins/ethereum/etherscan_balance_ new file mode 100755 index 00000000..4c98378f --- /dev/null +++ b/plugins/ethereum/etherscan_balance_ @@ -0,0 +1,83 @@ +#!/usr/bin/env python + +# +# etherscan_balance_ +# +# Munin plugin to monitor your ethereum (ETH) balance. +# Account balance is queried via etherscan.io API (https://etherscan.io/apis). +# +# Author: Nils Knieling - https://github.com/Cyclenerd +# Licence: GPLv2 +# +# USAGE +# etherscan_balance_ +# +# EXAMPLE +# ln -s /usr/share/munin/plugins/etherscan_balance_ /etc/munin/plugins/etherscan_balance_0x3257bde8cf067ae6f1ddc0e4b140fe02e3c5e44f +# + +import os, sys, urllib2, socket, json + +OPTIONS = sys.argv[0].split('_') + +command = '' +if len(sys.argv) > 1: + command = sys.argv[1] + +if command == 'suggest': + print "etherscan_balance_" + sys.exit(0) + +try: + OPTIONS[2] +except IndexError: + print "Ethereum address missing!" + sys.exit(9) + +ETH_ADDRESS = OPTIONS[2] + +if ETH_ADDRESS == "": + print "Ethereum address missing!" + sys.exit(9) + +if command == 'config': + print "graph_title ETH " + ETH_ADDRESS + print "graph_info Ethereum Address " + ETH_ADDRESS + print "graph_vlabel Ethereum Balance" + print "graph_category htc" + print ETH_ADDRESS + ".label ETH" + sys.exit(0) + + +URL = 'https://api.etherscan.io/api?module=account&action=balance&tag=latest' +STATS = URL + '&address=' + ETH_ADDRESS + +mining_req = urllib2.Request(STATS) +mining_req.add_header('User-Agent', 'Mozilla/5.0') + +try: + mining_stats_raw = urllib2.urlopen(mining_req, None, 1.5 ) +except urllib2.HTTPError: + print "HTTP Error!" + sys.exit(9) +except urllib2.URLError: + print "HTTP URL Error!" + sys.exit(9) +except socket.timeout: + print "HTTP Timed out!" + sys.exit(9) + +try: + mining_stats = json.load(mining_stats_raw) +except: + print "JSON Error!" + sys.exit(9) + +try: + float(mining_stats['result']) +except: + print "Result Error!" + sys.exit(9) + +ETH = float(mining_stats['result']) / 1000000000000000000 +print ETH_ADDRESS + ".value %.2f" % ETH \ No newline at end of file From c4fce6fcd7dcd220381092c7f2551b866ebba83a Mon Sep 17 00:00:00 2001 From: Nils Date: Tue, 27 Jun 2017 19:30:32 +0200 Subject: [PATCH 03/23] Fix broken Travis build Sys-Virt-0.9.8 does not exist anymore. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index dd210c31..7e320b2e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,7 +52,7 @@ install: - cpanm --notest nvidia::ml - cpanm --notest experimental # - Sys::Virt version matching the test system's libvirt-dev - - cpanm --notest DANBERR/Sys-Virt-0.9.8.tar.gz + - cpanm --notest DANBERR/Sys-Virt-1.3.0.tar.gz # Modules used by plugins, but missing on cpan # - File::Tail::Multi # - Sun::Solaris::Kstat From 288b76d6f92b9e0f2abb2b196aa18cf894a57056 Mon Sep 17 00:00:00 2001 From: Nils Date: Tue, 27 Jun 2017 19:47:01 +0200 Subject: [PATCH 04/23] Revert "Fix broken Travis build" This reverts commit c4fce6fcd7dcd220381092c7f2551b866ebba83a. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7e320b2e..dd210c31 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,7 +52,7 @@ install: - cpanm --notest nvidia::ml - cpanm --notest experimental # - Sys::Virt version matching the test system's libvirt-dev - - cpanm --notest DANBERR/Sys-Virt-1.3.0.tar.gz + - cpanm --notest DANBERR/Sys-Virt-0.9.8.tar.gz # Modules used by plugins, but missing on cpan # - File::Tail::Multi # - Sun::Solaris::Kstat From b10d8677c7752794356dc7ac33026a0e1fe65c19 Mon Sep 17 00:00:00 2001 From: Nils Date: Tue, 27 Jun 2017 21:21:41 +0200 Subject: [PATCH 05/23] Please use one import per line --- plugins/ethereum/ethermine_ | 6 +++++- plugins/ethereum/etherscan_balance_ | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/plugins/ethereum/ethermine_ b/plugins/ethereum/ethermine_ index fdd87596..32eff03f 100755 --- a/plugins/ethereum/ethermine_ +++ b/plugins/ethereum/ethermine_ @@ -15,7 +15,11 @@ # ln -s /usr/share/munin/plugins/ethermine_ /etc/munin/plugins/ethermine_3257bde8cf067ae6f1ddc0e4b140fe02e3c5e44f_mine # -import os, sys, urllib2, socket, json +import os +import sys +import urllib2 +import socket +import json OPTIONS = sys.argv[0].split('_') diff --git a/plugins/ethereum/etherscan_balance_ b/plugins/ethereum/etherscan_balance_ index 4c98378f..4f248b05 100755 --- a/plugins/ethereum/etherscan_balance_ +++ b/plugins/ethereum/etherscan_balance_ @@ -16,7 +16,11 @@ # ln -s /usr/share/munin/plugins/etherscan_balance_ /etc/munin/plugins/etherscan_balance_0x3257bde8cf067ae6f1ddc0e4b140fe02e3c5e44f # -import os, sys, urllib2, socket, json +import os +import sys +import urllib2 +import socket +import json OPTIONS = sys.argv[0].split('_') From 2290efb3d3a0a64dc848af58ceea1070eeb44c06 Mon Sep 17 00:00:00 2001 From: Nils Date: Tue, 27 Jun 2017 21:22:25 +0200 Subject: [PATCH 06/23] remove suggest --- plugins/ethereum/ethermine_ | 4 ---- plugins/ethereum/etherscan_balance_ | 4 ---- 2 files changed, 8 deletions(-) diff --git a/plugins/ethereum/ethermine_ b/plugins/ethereum/ethermine_ index 32eff03f..20716e9b 100755 --- a/plugins/ethereum/ethermine_ +++ b/plugins/ethereum/ethermine_ @@ -27,10 +27,6 @@ command = '' if len(sys.argv) > 1: command = sys.argv[1] -if command == 'suggest': - print "ethermine__" - sys.exit(0) - try: OPTIONS[1] except IndexError: diff --git a/plugins/ethereum/etherscan_balance_ b/plugins/ethereum/etherscan_balance_ index 4f248b05..75382158 100755 --- a/plugins/ethereum/etherscan_balance_ +++ b/plugins/ethereum/etherscan_balance_ @@ -28,10 +28,6 @@ command = '' if len(sys.argv) > 1: command = sys.argv[1] -if command == 'suggest': - print "etherscan_balance_" - sys.exit(0) - try: OPTIONS[2] except IndexError: From 67746dcced5a43072cb8ea9df775ca9ddd12e8df Mon Sep 17 00:00:00 2001 From: Nils Date: Tue, 27 Jun 2017 21:35:36 +0200 Subject: [PATCH 07/23] use print_function --- plugins/ethereum/ethermine_ | 67 ++++++++++++------------------------- 1 file changed, 22 insertions(+), 45 deletions(-) diff --git a/plugins/ethereum/ethermine_ b/plugins/ethereum/ethermine_ index 20716e9b..be5fc794 100755 --- a/plugins/ethereum/ethermine_ +++ b/plugins/ethereum/ethermine_ @@ -15,6 +15,8 @@ # ln -s /usr/share/munin/plugins/ethermine_ /etc/munin/plugins/ethermine_3257bde8cf067ae6f1ddc0e4b140fe02e3c5e44f_mine # +from __future__ import print_function + import os import sys import urllib2 @@ -28,62 +30,37 @@ if len(sys.argv) > 1: command = sys.argv[1] try: - OPTIONS[1] -except IndexError: - print "Ethereum address missing!" - sys.exit(9) - -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) + ETH_ADDRESS, MINER = sys.argv[0].split("_")[1:] +except ValueError: + print("The filename of this plugin (or its symlink) should follow this pattern: " + "'_'", file=sys.stderr) + sys.exit(0) if command == 'config': - print "graph_title Ethermine " + MINER - print "graph_info Ethermine Hashrate " + ETH_ADDRESS +"/" + MINER - print "graph_vlabel Ethermine Hashrate" - print "graph_category htc" - print ETH_ADDRESS + "_" + MINER + ".warning 20:" - print ETH_ADDRESS + "_" + MINER + ".critical 10:" - print ETH_ADDRESS + "_" + MINER + ".label MH/s" + print("graph_title Ethermine {}".format(ETH_ADDRESS)) + print("graph_info Ethermine Hashrate {}/{}".format(ETH_ADDRESS, MINER)) + print("graph_vlabel Ethermine Hashrate") + print("graph_category htc") + print("{}_{}.warning 20:".format(ETH_ADDRESS, MINER)); + print("{}_{}.critical 10:".format(ETH_ADDRESS, MINER)); + print("{}_{}.label MH/s:".format(ETH_ADDRESS, MINER)); sys.exit(0) -POOL_URL = 'https://ethermine.org/api/miner_new' -STATS = POOL_URL + '/' + ETH_ADDRESS +ETHERMINE_API_URL = 'https://ethermine.org/api/miner_new/' + ETH_ADDRESS -mining_req = urllib2.Request(STATS) +mining_req = urllib2.Request(ETHERMINE_API_URL) mining_req.add_header('User-Agent', 'Mozilla/5.0') try: - mining_stats_raw = urllib2.urlopen(mining_req, None, 1.5 ) -except urllib2.HTTPError as e: - print "HTTP Error!" - sys.exit(9) -except urllib2.URLError: - print "HTTP URL Error!" - sys.exit(9) -except socket.timeout: - print "HTTP Timed out!" - sys.exit(9) + mining_stats_raw = urllib2.urlopen(mining_req, timeout=1.5 ) +except IOError as exc: + print("Failed to request ethermine.org API: {}".format(exc), file=sys.stderr) try: mining_stats = json.load(mining_stats_raw) -except: - print "JSON Error!" +except ValueError: + print("Failed to parse JSON responce.", file=sys.stderr); sys.exit(9) workers = mining_stats['workers'] @@ -93,4 +70,4 @@ for worker in workers: if workers[worker]['worker'] == MINER: hash_rate = workers[worker]['hashrate'] hash_rate = hash_rate.replace(" MH/s", "") - print ETH_ADDRESS + "_" + MINER + ".value %s " % hash_rate \ No newline at end of file + print("{}_{}.value %s".format(ETH_ADDRESS, MINER, hash_rate)); \ No newline at end of file From 60c8aba7bcf9deac724f35d6c63a2f82c305a7ec Mon Sep 17 00:00:00 2001 From: Nils Date: Tue, 27 Jun 2017 21:53:16 +0200 Subject: [PATCH 08/23] use print_function --- plugins/ethereum/etherscan_balance_ | 67 ++++++++++++----------------- 1 file changed, 27 insertions(+), 40 deletions(-) diff --git a/plugins/ethereum/etherscan_balance_ b/plugins/ethereum/etherscan_balance_ index 75382158..3a63211b 100755 --- a/plugins/ethereum/etherscan_balance_ +++ b/plugins/ethereum/etherscan_balance_ @@ -16,68 +16,55 @@ # ln -s /usr/share/munin/plugins/etherscan_balance_ /etc/munin/plugins/etherscan_balance_0x3257bde8cf067ae6f1ddc0e4b140fe02e3c5e44f # +from __future__ import print_function + import os import sys import urllib2 import socket import json -OPTIONS = sys.argv[0].split('_') - command = '' if len(sys.argv) > 1: command = sys.argv[1] try: - OPTIONS[2] -except IndexError: - print "Ethereum address missing!" - sys.exit(9) - -ETH_ADDRESS = OPTIONS[2] - -if ETH_ADDRESS == "": - print "Ethereum address missing!" + eth_address = sys.argv[0].split("_")[1:] +except ValueError: + print("The filename of this plugin (or its symlink) should follow this pattern: " + "''", file=sys.stderr) sys.exit(9) if command == 'config': - print "graph_title ETH " + ETH_ADDRESS - print "graph_info Ethereum Address " + ETH_ADDRESS - print "graph_vlabel Ethereum Balance" - print "graph_category htc" - print ETH_ADDRESS + ".label ETH" + print("graph_title eth {}".format(eth_address)) + print("graph_title Ethereum Address {}".format(eth_address)) + 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)) sys.exit(0) +ethercan_balance_api_url = 'https://api.etherscan.io/api?module=account&action=balance&tag=latest&address=' + eth_address -URL = 'https://api.etherscan.io/api?module=account&action=balance&tag=latest' -STATS = URL + '&address=' + ETH_ADDRESS - -mining_req = urllib2.Request(STATS) -mining_req.add_header('User-Agent', 'Mozilla/5.0') +etherscan_req = urllib2.Request(ethercan_balance_api_url) +etherscan_req.add_header('User-Agent', 'Mozilla/5.0') try: - mining_stats_raw = urllib2.urlopen(mining_req, None, 1.5 ) -except urllib2.HTTPError: - print "HTTP Error!" - sys.exit(9) -except urllib2.URLError: - print "HTTP URL Error!" - sys.exit(9) -except socket.timeout: - print "HTTP Timed out!" + etherscan_balance_raw = urllib2.urlopen(etherscan_req, timeout=1.5 ) +except IOError as exc: + print("Failed to request etherscan.io API: {}".format(exc), file=sys.stderr) + +try: + etherscan_balance = json.load(etherscan_balance_raw) +except ValueError: + print("Failed to parse JSON responce.", file=sys.stderr); sys.exit(9) try: - mining_stats = json.load(mining_stats_raw) + float(etherscan_balance['result']) except: - print "JSON Error!" + print("Result Error!", file=sys.stderr); sys.exit(9) -try: - float(mining_stats['result']) -except: - print "Result Error!" - sys.exit(9) - -ETH = float(mining_stats['result']) / 1000000000000000000 -print ETH_ADDRESS + ".value %.2f" % ETH \ No newline at end of file +eth = float(etherscan_balance['result']) / 1000000000000000000 +print("{}_{}.value %.2f".format(eth_address, eth)); From 32c7266651fd5884c551a3f45c3bc4d92be8d2ef Mon Sep 17 00:00:00 2001 From: Nils Date: Tue, 27 Jun 2017 21:53:50 +0200 Subject: [PATCH 09/23] variable names --- plugins/ethereum/ethermine_ | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/plugins/ethereum/ethermine_ b/plugins/ethereum/ethermine_ index be5fc794..5a58129a 100755 --- a/plugins/ethereum/ethermine_ +++ b/plugins/ethereum/ethermine_ @@ -23,33 +23,31 @@ import urllib2 import socket import json -OPTIONS = sys.argv[0].split('_') - command = '' 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("_")[1:] except ValueError: print("The filename of this plugin (or its symlink) should follow this pattern: " "'_'", file=sys.stderr) - sys.exit(0) + sys.exit(9) if command == 'config': - print("graph_title Ethermine {}".format(ETH_ADDRESS)) - print("graph_info Ethermine Hashrate {}/{}".format(ETH_ADDRESS, MINER)) + print("graph_title Ethermine {}".format(eth_address)) + print("graph_info Ethermine Hashrate {}/{}".format(eth_address, miner)) print("graph_vlabel Ethermine Hashrate") print("graph_category htc") - print("{}_{}.warning 20:".format(ETH_ADDRESS, MINER)); - print("{}_{}.critical 10:".format(ETH_ADDRESS, MINER)); - print("{}_{}.label MH/s:".format(ETH_ADDRESS, MINER)); + print("{}_{}.warning 20:".format(eth_address, miner)); + print("{}_{}.critical 10:".format(eth_address, miner)); + print("{}_{}.label MH/s:".format(eth_address, miner)); sys.exit(0) -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') try: @@ -67,7 +65,7 @@ workers = mining_stats['workers'] # 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: + 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 %s".format(eth_address, miner, hash_rate)); \ No newline at end of file From 497e66ddcbfcd2be6f0565d9027b82add7e7828e Mon Sep 17 00:00:00 2001 From: Nils Date: Tue, 27 Jun 2017 22:25:05 +0200 Subject: [PATCH 10/23] rename --- plugins/ethereum/{ethermine_ => ethermine_hashrate_} | 8 ++++---- plugins/ethereum/etherscan_balance_ | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) rename plugins/ethereum/{ethermine_ => ethermine_hashrate_} (84%) diff --git a/plugins/ethereum/ethermine_ b/plugins/ethereum/ethermine_hashrate_ similarity index 84% rename from plugins/ethereum/ethermine_ rename to plugins/ethereum/ethermine_hashrate_ index 5a58129a..9dc068e9 100755 --- a/plugins/ethereum/ethermine_ +++ b/plugins/ethereum/ethermine_hashrate_ @@ -1,7 +1,7 @@ #!/usr/bin/env python # -# ethermine_ +# ethermine_hashrate_ # # Munin plugin to monitor your ethermine.org hashrate. # @@ -9,10 +9,10 @@ # Licence: GPLv2 # # USAGE -# ethermine__ +# ethermine_hashrate__ # # EXAMPLE -# ln -s /usr/share/munin/plugins/ethermine_ /etc/munin/plugins/ethermine_3257bde8cf067ae6f1ddc0e4b140fe02e3c5e44f_mine +# ln -s /usr/share/munin/plugins/ethermine_hashrate_ /etc/munin/plugins/ethermine_hashrate_3257bde8cf067ae6f1ddc0e4b140fe02e3c5e44f_mine # from __future__ import print_function @@ -31,7 +31,7 @@ try: eth_address, miner = sys.argv[0].split("_")[1:] except ValueError: print("The filename of this plugin (or its symlink) should follow this pattern: " - "'_'", file=sys.stderr) + "'ethermine_hashrate__'", file=sys.stderr) sys.exit(9) if command == 'config': diff --git a/plugins/ethereum/etherscan_balance_ b/plugins/ethereum/etherscan_balance_ index 3a63211b..b3fe0f5c 100755 --- a/plugins/ethereum/etherscan_balance_ +++ b/plugins/ethereum/etherscan_balance_ @@ -29,14 +29,14 @@ if len(sys.argv) > 1: command = sys.argv[1] try: - eth_address = sys.argv[0].split("_")[1:] + eth_address = sys.argv[0][(sys.argv[0].rfind('_')+1):] except ValueError: print("The filename of this plugin (or its symlink) should follow this pattern: " - "''", file=sys.stderr) + "'etherscan_balance_'", file=sys.stderr) sys.exit(9) if command == 'config': - print("graph_title eth {}".format(eth_address)) + print("graph_title ETH {}".format(eth_address)) print("graph_title Ethereum Address {}".format(eth_address)) print("graph_info Ethereum Account Balance for Address {}".format(eth_address)) print("graph_title Ethereum Balance") @@ -47,6 +47,7 @@ if command == 'config': 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') try: From 4f148679691d6c66cf23ccf28ab27e1e650324cf Mon Sep 17 00:00:00 2001 From: Nils Date: Wed, 28 Jun 2017 20:33:58 +0200 Subject: [PATCH 11/23] better user agent and some small fixes --- plugins/ethereum/ethermine_hashrate_ | 13 +++++++++---- plugins/ethereum/etherscan_balance_ | 17 +++++++++-------- 2 files changed, 18 insertions(+), 12 deletions(-) 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)); From f117dddc11f12a150dadd9e06d0789301654b9ee Mon Sep 17 00:00:00 2001 From: Nils Date: Wed, 28 Jun 2017 20:49:32 +0200 Subject: [PATCH 12/23] plain old documentation --- plugins/ethereum/ethermine_hashrate_ | 47 +++++++++++++++++++-------- plugins/ethereum/etherscan_balance_ | 48 +++++++++++++++++++--------- 2 files changed, 66 insertions(+), 29 deletions(-) diff --git a/plugins/ethereum/ethermine_hashrate_ b/plugins/ethereum/ethermine_hashrate_ index e3f4f8e4..485f5e34 100755 --- a/plugins/ethereum/ethermine_hashrate_ +++ b/plugins/ethereum/ethermine_hashrate_ @@ -1,19 +1,38 @@ #!/usr/bin/env python -# -# ethermine_hashrate_ -# -# Munin plugin to monitor your ethermine.org hashrate. -# -# Author: Nils Knieling - https://github.com/Cyclenerd -# Licence: GPLv2 -# -# USAGE -# ethermine_hashrate__ -# -# EXAMPLE -# ln -s /usr/share/munin/plugins/ethermine_hashrate_ /etc/munin/plugins/ethermine_hashrate_3257bde8cf067ae6f1ddc0e4b140fe02e3c5e44f_mine -# +""" +=head1 NAME + +ethermine_hashrate_ - Munin plugin to monitor your ethermine.org hashrate (MH/s) + +=head1 CONFIGURATION + +ethermine_hashrate__ + +=head1 SYNOPSIS + + ln -s /usr/share/munin/plugins/ethermine_hashrate_ \ + /etc/munin/plugins/ethermine_hashrate_3257bde8cf067ae6f1ddc0e4b140fe02e3c5e44f_mine + +=head1 DESCRIPTION + +This plugin shows the ethermine.org mining pool hashrate (MH/s) of a given ethereum address and rig name. +Hashrate is queried via ethermine.org API L. + +=head1 VERSION + +0.0.1 + +=head1 AUTHOR + +L + +=head1 LICENSE + +GPLv2 + +=cut +""" from __future__ import print_function diff --git a/plugins/ethereum/etherscan_balance_ b/plugins/ethereum/etherscan_balance_ index 5e211fac..379679c5 100755 --- a/plugins/ethereum/etherscan_balance_ +++ b/plugins/ethereum/etherscan_balance_ @@ -1,20 +1,38 @@ #!/usr/bin/env python -# -# etherscan_balance_ -# -# Munin plugin to monitor your ethereum (ETH) balance. -# Account balance is queried via etherscan.io API (https://etherscan.io/apis). -# -# Author: Nils Knieling - https://github.com/Cyclenerd -# Licence: GPLv2 -# -# USAGE -# etherscan_balance_ -# -# EXAMPLE -# ln -s /usr/share/munin/plugins/etherscan_balance_ /etc/munin/plugins/etherscan_balance_0x3257bde8cf067ae6f1ddc0e4b140fe02e3c5e44f -# +""" +=head1 NAME + +etherscan_balance_ - Munin plugin to monitor your ethereum (ETH) balance + +=head1 CONFIGURATION + +etherscan_balance_ + +=head1 SYNOPSIS + + ln -s /usr/share/munin/plugins/etherscan_balance_ \ + /etc/munin/plugins/etherscan_balance_0x3257bde8cf067ae6f1ddc0e4b140fe02e3c5e44f + +=head1 DESCRIPTION + +This plugin shows the balance (ETH) of a given ethereum address. +Account balance is queried via etherscan.io API L. + +=head1 VERSION + +0.0.1 + +=head1 AUTHOR + +L + +=head1 LICENSE + +GPLv2 + +=cut +""" from __future__ import print_function From 91ca13859e5b6662e002c3843131e4aa7cb3d049 Mon Sep 17 00:00:00 2001 From: Nils Date: Wed, 28 Jun 2017 20:55:55 +0200 Subject: [PATCH 13/23] magic markers --- plugins/ethereum/ethermine_hashrate_ | 10 +++++++++- plugins/ethereum/etherscan_balance_ | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/plugins/ethereum/ethermine_hashrate_ b/plugins/ethereum/ethermine_hashrate_ index 485f5e34..fdace8ae 100755 --- a/plugins/ethereum/ethermine_hashrate_ +++ b/plugins/ethereum/ethermine_hashrate_ @@ -5,6 +5,10 @@ ethermine_hashrate_ - Munin plugin to monitor your ethermine.org hashrate (MH/s) +=head1 APPLICABLE SYSTEMS + +All systems with "python" and "munin" + =head1 CONFIGURATION ethermine_hashrate__ @@ -14,7 +18,7 @@ ethermine_hashrate__ ln -s /usr/share/munin/plugins/ethermine_hashrate_ \ /etc/munin/plugins/ethermine_hashrate_3257bde8cf067ae6f1ddc0e4b140fe02e3c5e44f_mine -=head1 DESCRIPTION +=head1 INTERPRETATION This plugin shows the ethermine.org mining pool hashrate (MH/s) of a given ethereum address and rig name. Hashrate is queried via ethermine.org API L. @@ -31,6 +35,10 @@ L GPLv2 +=head1 MAGIC MARKERS + + #%# family=manual + =cut """ diff --git a/plugins/ethereum/etherscan_balance_ b/plugins/ethereum/etherscan_balance_ index 379679c5..96e14c9c 100755 --- a/plugins/ethereum/etherscan_balance_ +++ b/plugins/ethereum/etherscan_balance_ @@ -5,6 +5,10 @@ etherscan_balance_ - Munin plugin to monitor your ethereum (ETH) balance +=head1 APPLICABLE SYSTEMS + +All systems with "python" and "munin" + =head1 CONFIGURATION etherscan_balance_ @@ -14,7 +18,7 @@ etherscan_balance_ ln -s /usr/share/munin/plugins/etherscan_balance_ \ /etc/munin/plugins/etherscan_balance_0x3257bde8cf067ae6f1ddc0e4b140fe02e3c5e44f -=head1 DESCRIPTION +=head1 INTERPRETATION This plugin shows the balance (ETH) of a given ethereum address. Account balance is queried via etherscan.io API L. @@ -31,6 +35,10 @@ L GPLv2 +=head1 MAGIC MARKERS + + #%# family=manual + =cut """ From 6373ccf7978ff67961e12b4d7f3b33635cfe37d5 Mon Sep 17 00:00:00 2001 From: Nils Date: Wed, 28 Jun 2017 22:34:12 +0200 Subject: [PATCH 14/23] python3 and 2 with working config --- plugins/ethereum/ethermine_hashrate_ | 37 +++++++++++++++++----------- plugins/ethereum/etherscan_balance_ | 30 +++++++++++++--------- 2 files changed, 42 insertions(+), 25 deletions(-) diff --git a/plugins/ethereum/ethermine_hashrate_ b/plugins/ethereum/ethermine_hashrate_ index fdace8ae..baab79dd 100755 --- a/plugins/ethereum/ethermine_hashrate_ +++ b/plugins/ethereum/ethermine_hashrate_ @@ -44,11 +44,18 @@ GPLv2 from __future__ import print_function -import os import sys -import urllib2 -import socket import json +import codecs + +try: + # python3 + from urllib.request import urlopen + from urllib.request import Request +except ImportError: + # python2 + from urllib2 import urlopen + from urllib2 import Request command = '' if len(sys.argv) > 1: @@ -62,37 +69,39 @@ except ValueError: sys.exit(9) if command == 'config': - print("graph_title Ethermine {}".format(eth_address)) - print("graph_info Ethermine Hashrate {}/{}".format(eth_address, miner)) + print("graph_title Ethermine {}".format(miner)) + print("graph_info ethermine.org Mining Pool Hashrate for {}_{}".format(eth_address, miner)) print("graph_vlabel Ethermine Hashrate") print("graph_category htc") - print("{}_{}.warning 20:".format(eth_address, miner)); - print("{}_{}.critical 10:".format(eth_address, miner)); - print("{}_{}.label MH/s:".format(eth_address, miner)); + print("{}_{}.warning 20:".format(eth_address, miner)) + print("{}_{}.critical 10:".format(eth_address, miner)) + print("{}_{}.label MH/s:".format(eth_address, miner)) sys.exit(0) ethermine_api_url = 'https://ethermine.org/api/miner_new/' + eth_address -mining_req = urllib2.Request(ethermine_api_url) +mining_req = Request(ethermine_api_url) # 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 ) + mining_stats_raw = urlopen(mining_req, timeout=15) except IOError as exc: print("Failed to request ethermine.org API: {}".format(exc), file=sys.stderr) +reader = codecs.getreader("utf-8") + try: - mining_stats = json.load(mining_stats_raw) + mining_stats = json.load(reader(mining_stats_raw)) except ValueError: - print("Failed to parse JSON responce.", file=sys.stderr); + print("Failed to parse JSON responce.", file=sys.stderr) sys.exit(9) try: workers = mining_stats['workers'] except: - print("JSON result error!", file=sys.stderr); + 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. @@ -100,4 +109,4 @@ for worker in workers: if workers[worker]['worker'] == miner: hash_rate = workers[worker]['hashrate'] hash_rate = hash_rate.replace(" MH/s", "") - print("{}_{}.value {}".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 96e14c9c..2926b949 100755 --- a/plugins/ethereum/etherscan_balance_ +++ b/plugins/ethereum/etherscan_balance_ @@ -44,11 +44,18 @@ GPLv2 from __future__ import print_function -import os import sys -import urllib2 -import socket import json +import codecs + +try: + # python3 + from urllib.request import urlopen + from urllib.request import Request +except ImportError: + # python2 + from urllib2 import urlopen + from urllib2 import Request command = '' if len(sys.argv) > 1: @@ -64,34 +71,35 @@ if not eth_address: if command == 'config': print("graph_title ETH {}".format(eth_address)) - print("graph_title Ethereum Address {}".format(eth_address)) print("graph_info Ethereum Account Balance for Address {}".format(eth_address)) - print("graph_title Ethereum Balance") - print("graph_title htc") + print("graph_vlabel Ethereum Balance") + print("graph_category htc") 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) +etherscan_req = Request(ethercan_balance_api_url) # 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 ) + etherscan_balance_raw = urlopen(etherscan_req, timeout=15) except IOError as exc: print("Failed to request etherscan.io API: {}".format(exc), file=sys.stderr) +reader = codecs.getreader("utf-8") + try: - etherscan_balance = json.load(etherscan_balance_raw) + etherscan_balance = json.load(reader(etherscan_balance_raw)) except ValueError: - print("Failed to parse JSON responce.", file=sys.stderr); + print("Failed to parse JSON responce.", file=sys.stderr) sys.exit(9) try: float(etherscan_balance['result']) except: - print("JSON result error!", file=sys.stderr); + print("JSON result error!", file=sys.stderr) sys.exit(9) eth = float(etherscan_balance['result']) / 1000000000000000000 From 88cf4c454169bec7fecff28807026937011d5938 Mon Sep 17 00:00:00 2001 From: Nils Date: Thu, 29 Jun 2017 07:28:15 +0200 Subject: [PATCH 15/23] new currency folder --- plugins/{ => currency}/ethereum/ethermine_hashrate_ | 0 plugins/{ => currency}/ethereum/etherscan_balance_ | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename plugins/{ => currency}/ethereum/ethermine_hashrate_ (100%) rename plugins/{ => currency}/ethereum/etherscan_balance_ (100%) diff --git a/plugins/ethereum/ethermine_hashrate_ b/plugins/currency/ethereum/ethermine_hashrate_ similarity index 100% rename from plugins/ethereum/ethermine_hashrate_ rename to plugins/currency/ethereum/ethermine_hashrate_ diff --git a/plugins/ethereum/etherscan_balance_ b/plugins/currency/ethereum/etherscan_balance_ similarity index 100% rename from plugins/ethereum/etherscan_balance_ rename to plugins/currency/ethereum/etherscan_balance_ From 2820f32d15ebcc47c5c91d07329dbcb65a06e629 Mon Sep 17 00:00:00 2001 From: Nils Date: Fri, 30 Jun 2017 08:47:45 +0200 Subject: [PATCH 16/23] response typo --- plugins/currency/ethereum/ethermine_hashrate_ | 2 +- plugins/currency/ethereum/etherscan_balance_ | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/currency/ethereum/ethermine_hashrate_ b/plugins/currency/ethereum/ethermine_hashrate_ index baab79dd..9fc60452 100755 --- a/plugins/currency/ethereum/ethermine_hashrate_ +++ b/plugins/currency/ethereum/ethermine_hashrate_ @@ -95,7 +95,7 @@ reader = codecs.getreader("utf-8") try: mining_stats = json.load(reader(mining_stats_raw)) except ValueError: - print("Failed to parse JSON responce.", file=sys.stderr) + print("Failed to parse JSON response.", file=sys.stderr) sys.exit(9) try: diff --git a/plugins/currency/ethereum/etherscan_balance_ b/plugins/currency/ethereum/etherscan_balance_ index 2926b949..38ad62ee 100755 --- a/plugins/currency/ethereum/etherscan_balance_ +++ b/plugins/currency/ethereum/etherscan_balance_ @@ -93,7 +93,7 @@ reader = codecs.getreader("utf-8") try: etherscan_balance = json.load(reader(etherscan_balance_raw)) except ValueError: - print("Failed to parse JSON responce.", file=sys.stderr) + print("Failed to parse JSON response.", file=sys.stderr) sys.exit(9) try: From 25db9a778e20667ff455678da9aa8a6746e12c53 Mon Sep 17 00:00:00 2001 From: Nils Date: Fri, 30 Jun 2017 08:49:26 +0200 Subject: [PATCH 17/23] exit on ioerror --- plugins/currency/ethereum/ethermine_hashrate_ | 1 + plugins/currency/ethereum/etherscan_balance_ | 1 + 2 files changed, 2 insertions(+) diff --git a/plugins/currency/ethereum/ethermine_hashrate_ b/plugins/currency/ethereum/ethermine_hashrate_ index 9fc60452..12b159a1 100755 --- a/plugins/currency/ethereum/ethermine_hashrate_ +++ b/plugins/currency/ethereum/ethermine_hashrate_ @@ -89,6 +89,7 @@ try: mining_stats_raw = urlopen(mining_req, timeout=15) except IOError as exc: print("Failed to request ethermine.org API: {}".format(exc), file=sys.stderr) + sys.exit(9) reader = codecs.getreader("utf-8") diff --git a/plugins/currency/ethereum/etherscan_balance_ b/plugins/currency/ethereum/etherscan_balance_ index 38ad62ee..4dc758fb 100755 --- a/plugins/currency/ethereum/etherscan_balance_ +++ b/plugins/currency/ethereum/etherscan_balance_ @@ -87,6 +87,7 @@ try: etherscan_balance_raw = urlopen(etherscan_req, timeout=15) except IOError as exc: print("Failed to request etherscan.io API: {}".format(exc), file=sys.stderr) + sys.exit(9) reader = codecs.getreader("utf-8") From 311888d3b825b441d3c3dedf5de7055fb6701462 Mon Sep 17 00:00:00 2001 From: Nils Date: Fri, 30 Jun 2017 08:55:51 +0200 Subject: [PATCH 18/23] category change s/htc/other/ --- plugins/currency/ethereum/ethermine_hashrate_ | 2 +- plugins/currency/ethereum/etherscan_balance_ | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/currency/ethereum/ethermine_hashrate_ b/plugins/currency/ethereum/ethermine_hashrate_ index 12b159a1..42cc7eba 100755 --- a/plugins/currency/ethereum/ethermine_hashrate_ +++ b/plugins/currency/ethereum/ethermine_hashrate_ @@ -72,7 +72,7 @@ if command == 'config': print("graph_title Ethermine {}".format(miner)) print("graph_info ethermine.org Mining Pool Hashrate for {}_{}".format(eth_address, miner)) print("graph_vlabel Ethermine Hashrate") - print("graph_category htc") + print("graph_category other") print("{}_{}.warning 20:".format(eth_address, miner)) print("{}_{}.critical 10:".format(eth_address, miner)) print("{}_{}.label MH/s:".format(eth_address, miner)) diff --git a/plugins/currency/ethereum/etherscan_balance_ b/plugins/currency/ethereum/etherscan_balance_ index 4dc758fb..b00eac76 100755 --- a/plugins/currency/ethereum/etherscan_balance_ +++ b/plugins/currency/ethereum/etherscan_balance_ @@ -73,7 +73,7 @@ if command == 'config': print("graph_title ETH {}".format(eth_address)) print("graph_info Ethereum Account Balance for Address {}".format(eth_address)) print("graph_vlabel Ethereum Balance") - print("graph_category htc") + print("graph_category other") print("{}.label ETH".format(eth_address)) sys.exit(0) From 73d11530ae48f340f3c15254b4d25413d786a3f9 Mon Sep 17 00:00:00 2001 From: Nils Date: Sat, 1 Jul 2017 09:04:23 +0200 Subject: [PATCH 19/23] wei to ether comment --- plugins/currency/ethereum/etherscan_balance_ | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/currency/ethereum/etherscan_balance_ b/plugins/currency/ethereum/etherscan_balance_ index b00eac76..53ecd34a 100755 --- a/plugins/currency/ethereum/etherscan_balance_ +++ b/plugins/currency/ethereum/etherscan_balance_ @@ -103,5 +103,13 @@ except: print("JSON result error!", file=sys.stderr) sys.exit(9) +""" +API result is in Wei. Convert Wei to Ether (ETH). +1 : Wei +10^12 : Szabo +10^15 : Finney +10^18 : Ether +233874700000000000000000 Wei = 233,874.7 Ether +""" eth = float(etherscan_balance['result']) / 1000000000000000000 print("{}.value {:.2f}".format(eth_address, eth)); From 17a2e236865e81069a6064ee7b8b6ea1c9c14cb5 Mon Sep 17 00:00:00 2001 From: Nils Date: Sat, 1 Jul 2017 09:34:50 +0200 Subject: [PATCH 20/23] ValueError comment --- plugins/currency/ethereum/ethermine_hashrate_ | 1 + plugins/currency/ethereum/etherscan_balance_ | 1 + 2 files changed, 2 insertions(+) diff --git a/plugins/currency/ethereum/ethermine_hashrate_ b/plugins/currency/ethereum/ethermine_hashrate_ index 42cc7eba..8a210413 100755 --- a/plugins/currency/ethereum/ethermine_hashrate_ +++ b/plugins/currency/ethereum/ethermine_hashrate_ @@ -96,6 +96,7 @@ reader = codecs.getreader("utf-8") try: mining_stats = json.load(reader(mining_stats_raw)) except ValueError: + # Error in decoding operation or in JSON parsing throw a ValueError print("Failed to parse JSON response.", file=sys.stderr) sys.exit(9) diff --git a/plugins/currency/ethereum/etherscan_balance_ b/plugins/currency/ethereum/etherscan_balance_ index 53ecd34a..dd80be5f 100755 --- a/plugins/currency/ethereum/etherscan_balance_ +++ b/plugins/currency/ethereum/etherscan_balance_ @@ -94,6 +94,7 @@ reader = codecs.getreader("utf-8") try: etherscan_balance = json.load(reader(etherscan_balance_raw)) except ValueError: + # Error in decoding operation or in JSON parsing throw a ValueError print("Failed to parse JSON response.", file=sys.stderr) sys.exit(9) From 3298c34c7451c9d3f7cd26714d4558810c77f78c Mon Sep 17 00:00:00 2001 From: Nils Date: Sat, 1 Jul 2017 17:22:28 +0200 Subject: [PATCH 21/23] convert wei to ether (ETH) via 'fieldname.cdef' --- plugins/currency/ethereum/etherscan_balance_ | 26 ++++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/plugins/currency/ethereum/etherscan_balance_ b/plugins/currency/ethereum/etherscan_balance_ index dd80be5f..d6d1db31 100755 --- a/plugins/currency/ethereum/etherscan_balance_ +++ b/plugins/currency/ethereum/etherscan_balance_ @@ -20,7 +20,7 @@ etherscan_balance_ =head1 INTERPRETATION -This plugin shows the balance (ETH) of a given ethereum address. +This plugin shows the ether balance (ETH) of a given ethereum address. Account balance is queried via etherscan.io API L. =head1 VERSION @@ -69,12 +69,21 @@ if not eth_address: "'etherscan_balance_'", file=sys.stderr) sys.exit(9) +""" +API result is in Wei. Convert Wei to Ether (ETH) via 'fieldname.cdef' +1 : Wei +10^12 : Szabo +10^15 : Finney +10^18 : Ether +233874700000000000000000 Wei = 233,874.7 Ether +""" if command == 'config': print("graph_title ETH {}".format(eth_address)) print("graph_info Ethereum Account Balance for Address {}".format(eth_address)) print("graph_vlabel Ethereum Balance") print("graph_category other") - print("{}.label ETH".format(eth_address)) + print("wei_balance_{0}.cdef wei_balance_{0},1000000000000000000,/".format(eth_address)) + print("wei_balance_{}.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 @@ -99,18 +108,9 @@ except ValueError: sys.exit(9) try: - float(etherscan_balance['result']) + eth = int(etherscan_balance['result']) except: print("JSON result error!", file=sys.stderr) sys.exit(9) -""" -API result is in Wei. Convert Wei to Ether (ETH). -1 : Wei -10^12 : Szabo -10^15 : Finney -10^18 : Ether -233874700000000000000000 Wei = 233,874.7 Ether -""" -eth = float(etherscan_balance['result']) / 1000000000000000000 -print("{}.value {:.2f}".format(eth_address, eth)); +print("wei_balance_{}.value {}".format(eth_address, eth)); From 1fe90e4cacf2e03e78f0f3136417f1bc3decac74 Mon Sep 17 00:00:00 2001 From: Nils Date: Sat, 1 Jul 2017 17:32:08 +0200 Subject: [PATCH 22/23] better field name to avoid errors --- plugins/currency/ethereum/ethermine_hashrate_ | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/currency/ethereum/ethermine_hashrate_ b/plugins/currency/ethereum/ethermine_hashrate_ index 8a210413..ca0bc038 100755 --- a/plugins/currency/ethereum/ethermine_hashrate_ +++ b/plugins/currency/ethereum/ethermine_hashrate_ @@ -73,9 +73,9 @@ if command == 'config': print("graph_info ethermine.org Mining Pool Hashrate for {}_{}".format(eth_address, miner)) print("graph_vlabel Ethermine Hashrate") print("graph_category other") - print("{}_{}.warning 20:".format(eth_address, miner)) - print("{}_{}.critical 10:".format(eth_address, miner)) - print("{}_{}.label MH/s:".format(eth_address, miner)) + print("ethermine_mhs_{}_{}.warning 20:".format(eth_address, miner)) + print("ethermine_mhs_{}_{}.critical 10:".format(eth_address, miner)) + print("ethermine_mhs_{}_{}.label MH/s:".format(eth_address, miner)) sys.exit(0) @@ -111,4 +111,4 @@ for worker in workers: if workers[worker]['worker'] == miner: hash_rate = workers[worker]['hashrate'] hash_rate = hash_rate.replace(" MH/s", "") - print("{}_{}.value {}".format(eth_address, miner, hash_rate)) \ No newline at end of file + print("ethermine_mhs_{}_{}.value {}".format(eth_address, miner, hash_rate)) \ No newline at end of file From f5715e5eba9d9e6bb5c77e49e7dc863a0e240484 Mon Sep 17 00:00:00 2001 From: Nils Date: Sat, 1 Jul 2017 17:41:06 +0200 Subject: [PATCH 23/23] more beautiful title --- plugins/currency/ethereum/etherscan_balance_ | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/currency/ethereum/etherscan_balance_ b/plugins/currency/ethereum/etherscan_balance_ index d6d1db31..2445b7f6 100755 --- a/plugins/currency/ethereum/etherscan_balance_ +++ b/plugins/currency/ethereum/etherscan_balance_ @@ -78,7 +78,7 @@ API result is in Wei. Convert Wei to Ether (ETH) via 'fieldname.cdef' 233874700000000000000000 Wei = 233,874.7 Ether """ if command == 'config': - print("graph_title ETH {}".format(eth_address)) + print("graph_title Ether {}".format(eth_address)) print("graph_info Ethereum Account Balance for Address {}".format(eth_address)) print("graph_vlabel Ethereum Balance") print("graph_category other")