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))

Formats disponibles : Unified diff