Projet

Général

Profil

Révision 6373ccf7

ID6373ccf7978ff67961e12b4d7f3b33635cfe37d5
Parent 91ca1385
Enfant 88cf4c45

Ajouté par Nils il y a plus de 8 ans

python3 and 2 with working config

Voir les différences:

plugins/ethereum/ethermine_hashrate_
44 44

  
45 45
from __future__ import print_function
46 46

  
47
import os
48 47
import sys
49
import urllib2
50
import socket
51 48
import json
49
import codecs
50

  
51
try:
52
    # python3
53
    from urllib.request import urlopen
54
    from urllib.request import Request
55
except ImportError:
56
    # python2
57
    from urllib2 import urlopen
58
    from urllib2 import Request
52 59

  
53 60
command = ''
54 61
if len(sys.argv) > 1:
......
62 69
    sys.exit(9)
63 70

  
64 71
if command == 'config':
65
    print("graph_title Ethermine {}".format(eth_address))
66
    print("graph_info Ethermine Hashrate {}/{}".format(eth_address, miner))
72
    print("graph_title Ethermine {}".format(miner))
73
    print("graph_info ethermine.org Mining Pool Hashrate for {}_{}".format(eth_address, miner))
67 74
    print("graph_vlabel Ethermine Hashrate")
68 75
    print("graph_category htc")
69
    print("{}_{}.warning 20:".format(eth_address, miner));
70
    print("{}_{}.critical 10:".format(eth_address, miner));
71
    print("{}_{}.label MH/s:".format(eth_address, miner));
76
    print("{}_{}.warning 20:".format(eth_address, miner))
77
    print("{}_{}.critical 10:".format(eth_address, miner))
78
    print("{}_{}.label MH/s:".format(eth_address, miner))
72 79
    sys.exit(0)
73 80

  
74 81

  
75 82
ethermine_api_url = 'https://ethermine.org/api/miner_new/' + eth_address
76 83

  
77
mining_req = urllib2.Request(ethermine_api_url)
84
mining_req = Request(ethermine_api_url)
78 85
# User-Agent to bypass Cloudflare
79 86
mining_req.add_header('User-Agent', 'Ethermine Munin Plugin/1.0')
80 87

  
81 88
try:
82
    mining_stats_raw = urllib2.urlopen(mining_req, timeout=1.5 )
89
    mining_stats_raw = urlopen(mining_req, timeout=15)
83 90
except IOError as exc:
84 91
    print("Failed to request ethermine.org API: {}".format(exc), file=sys.stderr)
85 92

  
93
reader = codecs.getreader("utf-8")
94

  
86 95
try:
87
    mining_stats = json.load(mining_stats_raw)
96
    mining_stats = json.load(reader(mining_stats_raw))
88 97
except ValueError:
89
    print("Failed to parse JSON responce.", file=sys.stderr);
98
    print("Failed to parse JSON responce.", file=sys.stderr)
90 99
    sys.exit(9)
91 100

  
92 101
try:
93 102
    workers = mining_stats['workers']
94 103
except:
95
    print("JSON result error!", file=sys.stderr);
104
    print("JSON result error!", file=sys.stderr)
96 105
    sys.exit(9)
97 106

  
98 107
# ethermine.org sometimes has caching errors. You can see data from other miner. Always check your rig name.
......
100 109
    if workers[worker]['worker'] == miner:
101 110
        hash_rate = workers[worker]['hashrate']
102 111
        hash_rate = hash_rate.replace(" MH/s", "")
103
        print("{}_{}.value {}".format(eth_address, miner, hash_rate));
112
        print("{}_{}.value {}".format(eth_address, miner, hash_rate))
plugins/ethereum/etherscan_balance_
44 44

  
45 45
from __future__ import print_function
46 46

  
47
import os
48 47
import sys
49
import urllib2
50
import socket
51 48
import json
49
import codecs
50

  
51
try:
52
    # python3
53
    from urllib.request import urlopen
54
    from urllib.request import Request
55
except ImportError:
56
    # python2
57
    from urllib2 import urlopen
58
    from urllib2 import Request
52 59

  
53 60
command = ''
54 61
if len(sys.argv) > 1:
......
64 71

  
65 72
if command == 'config':
66 73
    print("graph_title ETH {}".format(eth_address))
67
    print("graph_title Ethereum Address {}".format(eth_address))
68 74
    print("graph_info Ethereum Account Balance for Address {}".format(eth_address))
69
    print("graph_title Ethereum Balance")
70
    print("graph_title htc")
75
    print("graph_vlabel Ethereum Balance")
76
    print("graph_category htc")
71 77
    print("{}.label ETH".format(eth_address))
72 78
    sys.exit(0)
73 79

  
74 80
ethercan_balance_api_url = 'https://api.etherscan.io/api?module=account&action=balance&tag=latest&address=' + eth_address
75 81

  
76
etherscan_req = urllib2.Request(ethercan_balance_api_url)
82
etherscan_req = Request(ethercan_balance_api_url)
77 83
# User-Agent to bypass Cloudflare
78 84
etherscan_req.add_header('User-Agent', 'Etherscan Munin Plugin/1.0')
79 85

  
80 86
try:
81
    etherscan_balance_raw = urllib2.urlopen(etherscan_req, timeout=1.5 )
87
    etherscan_balance_raw = urlopen(etherscan_req, timeout=15)
82 88
except IOError as exc:
83 89
    print("Failed to request etherscan.io API: {}".format(exc), file=sys.stderr)
84 90

  
91
reader = codecs.getreader("utf-8")
92

  
85 93
try:
86
    etherscan_balance = json.load(etherscan_balance_raw)
94
    etherscan_balance = json.load(reader(etherscan_balance_raw))
87 95
except ValueError:
88
    print("Failed to parse JSON responce.", file=sys.stderr);
96
    print("Failed to parse JSON responce.", file=sys.stderr)
89 97
    sys.exit(9)
90 98

  
91 99
try:
92 100
    float(etherscan_balance['result'])
93 101
except:
94
    print("JSON result error!", file=sys.stderr);
102
    print("JSON result error!", file=sys.stderr)
95 103
    sys.exit(9)
96 104

  
97 105
eth = float(etherscan_balance['result']) / 1000000000000000000

Formats disponibles : Unified diff