root / plugins / ethereum / etherscan_balance_ @ 2290efb3
Historique | Voir | Annoter | Télécharger (1,8 ko)
| 1 |
#!/usr/bin/env python |
|---|---|
| 2 |
|
| 3 |
# |
| 4 |
# etherscan_balance_ |
| 5 |
# |
| 6 |
# Munin plugin to monitor your ethereum (ETH) balance. |
| 7 |
# Account balance is queried via etherscan.io API (https://etherscan.io/apis). |
| 8 |
# |
| 9 |
# Author: Nils Knieling - https://github.com/Cyclenerd |
| 10 |
# Licence: GPLv2 |
| 11 |
# |
| 12 |
# USAGE |
| 13 |
# etherscan_balance_<YOUR_PUBLIC_ETHEREUM_ADDRESS> |
| 14 |
# |
| 15 |
# EXAMPLE |
| 16 |
# ln -s /usr/share/munin/plugins/etherscan_balance_ /etc/munin/plugins/etherscan_balance_0x3257bde8cf067ae6f1ddc0e4b140fe02e3c5e44f |
| 17 |
# |
| 18 |
|
| 19 |
import os |
| 20 |
import sys |
| 21 |
import urllib2 |
| 22 |
import socket |
| 23 |
import json |
| 24 |
|
| 25 |
OPTIONS = sys.argv[0].split('_')
|
| 26 |
|
| 27 |
command = '' |
| 28 |
if len(sys.argv) > 1: |
| 29 |
command = sys.argv[1] |
| 30 |
|
| 31 |
try: |
| 32 |
OPTIONS[2] |
| 33 |
except IndexError: |
| 34 |
print "Ethereum address missing!" |
| 35 |
sys.exit(9) |
| 36 |
|
| 37 |
ETH_ADDRESS = OPTIONS[2] |
| 38 |
|
| 39 |
if ETH_ADDRESS == "": |
| 40 |
print "Ethereum address missing!" |
| 41 |
sys.exit(9) |
| 42 |
|
| 43 |
if command == 'config': |
| 44 |
print "graph_title ETH " + ETH_ADDRESS |
| 45 |
print "graph_info Ethereum Address " + ETH_ADDRESS |
| 46 |
print "graph_vlabel Ethereum Balance" |
| 47 |
print "graph_category htc" |
| 48 |
print ETH_ADDRESS + ".label ETH" |
| 49 |
sys.exit(0) |
| 50 |
|
| 51 |
|
| 52 |
URL = 'https://api.etherscan.io/api?module=account&action=balance&tag=latest' |
| 53 |
STATS = URL + '&address=' + ETH_ADDRESS |
| 54 |
|
| 55 |
mining_req = urllib2.Request(STATS) |
| 56 |
mining_req.add_header('User-Agent', 'Mozilla/5.0')
|
| 57 |
|
| 58 |
try: |
| 59 |
mining_stats_raw = urllib2.urlopen(mining_req, None, 1.5 ) |
| 60 |
except urllib2.HTTPError: |
| 61 |
print "HTTP Error!" |
| 62 |
sys.exit(9) |
| 63 |
except urllib2.URLError: |
| 64 |
print "HTTP URL Error!" |
| 65 |
sys.exit(9) |
| 66 |
except socket.timeout: |
| 67 |
print "HTTP Timed out!" |
| 68 |
sys.exit(9) |
| 69 |
|
| 70 |
try: |
| 71 |
mining_stats = json.load(mining_stats_raw) |
| 72 |
except: |
| 73 |
print "JSON Error!" |
| 74 |
sys.exit(9) |
| 75 |
|
| 76 |
try: |
| 77 |
float(mining_stats['result']) |
| 78 |
except: |
| 79 |
print "Result Error!" |
| 80 |
sys.exit(9) |
| 81 |
|
| 82 |
ETH = float(mining_stats['result']) / 1000000000000000000 |
| 83 |
print ETH_ADDRESS + ".value %.2f" % ETH |
