root / plugins / currency / zcash / zcash_flypool_hashrate_ @ 21341b5a
Historique | Voir | Annoter | Télécharger (2,58 ko)
| 1 | 21341b5a | Nils | #!/usr/bin/env python3 |
|---|---|---|---|
| 2 | 4d9a7e2c | Nils | |
| 3 | """ |
||
| 4 | =head1 NAME |
||
| 5 | |||
| 6 | zcash_flypool_hashrate_ - Munin plugin to monitor your zcash.flypool.org hashrate (H/s) |
||
| 7 | |||
| 8 | =head1 APPLICABLE SYSTEMS |
||
| 9 | |||
| 10 | 21341b5a | Nils | All systems with "python3" and "munin" |
| 11 | 4d9a7e2c | Nils | |
| 12 | =head1 CONFIGURATION |
||
| 13 | |||
| 14 | zcash_flypool_hashrate_<YOUR_ZCASH_ADDRESS>_<YOUR_WORKER_NAME> |
||
| 15 | |||
| 16 | =head1 SYNOPSIS |
||
| 17 | |||
| 18 | ln -s /usr/share/munin/plugins/zcash_flypool_hashrate_ \ |
||
| 19 | /etc/munin/plugins/zcash_flypool_hashrate_t1gMVWjGhdjvb71UU11JDrFmiZhgUf4x5TH_mine |
||
| 20 | |||
| 21 | =head1 INTERPRETATION |
||
| 22 | |||
| 23 | This plugin shows the zcash.flypool.org mining pool hashrate (H/s) of a given Zcasg address and rig name. |
||
| 24 | Hashrate is queried via Flypool API L<https://zcash.flypool.org>. |
||
| 25 | |||
| 26 | =head1 VERSION |
||
| 27 | |||
| 28 | 0.0.1 |
||
| 29 | |||
| 30 | =head1 AUTHOR |
||
| 31 | |||
| 32 | L<Nils Knieling|https://github.com/Cyclenerd> |
||
| 33 | |||
| 34 | =head1 LICENSE |
||
| 35 | |||
| 36 | GPLv2 |
||
| 37 | |||
| 38 | =head1 MAGIC MARKERS |
||
| 39 | |||
| 40 | #%# family=manual |
||
| 41 | |||
| 42 | =cut |
||
| 43 | """ |
||
| 44 | |||
| 45 | import sys |
||
| 46 | import json |
||
| 47 | import codecs |
||
| 48 | 21341b5a | Nils | from urllib.request import urlopen |
| 49 | from urllib.request import Request |
||
| 50 | 4d9a7e2c | Nils | |
| 51 | command = '' |
||
| 52 | if len(sys.argv) > 1: |
||
| 53 | command = sys.argv[1] |
||
| 54 | |||
| 55 | try: |
||
| 56 | zcash_address, miner = sys.argv[0].split("_")[3:]
|
||
| 57 | except ValueError: |
||
| 58 | print("The filename of this plugin (or its symlink) should follow this pattern: "
|
||
| 59 | "'zcash_flypool_hashrate_<YOUR_ZCASH_ADDRESS>_<YOUR_WORKER_NAME>'", file=sys.stderr) |
||
| 60 | sys.exit(9) |
||
| 61 | |||
| 62 | if command == 'config': |
||
| 63 | print("graph_title Flypool {}".format(miner))
|
||
| 64 | print("graph_info zcash.flypool.org Mining Pool Hashrate for {}_{}".format(zcash_address, miner))
|
||
| 65 | print("graph_vlabel Flypool Hashrate")
|
||
| 66 | print("graph_category other")
|
||
| 67 | print("flypool_hs_{}_{}.warning 200:".format(zcash_address, miner))
|
||
| 68 | print("flypool_hs_{}_{}.critical 100:".format(zcash_address, miner))
|
||
| 69 | print("flypool_hs_{}_{}.label H/s:".format(zcash_address, miner))
|
||
| 70 | sys.exit(0) |
||
| 71 | |||
| 72 | |||
| 73 | flypool_api_url = 'https://api-zcash.flypool.org/miner/' + zcash_address + '/worker/' + miner + '/currentStats' |
||
| 74 | |||
| 75 | mining_req = Request(flypool_api_url) |
||
| 76 | # User-Agent to bypass Cloudflare |
||
| 77 | mining_req.add_header('User-Agent', 'Flypool Munin Plugin/1.0')
|
||
| 78 | |||
| 79 | try: |
||
| 80 | mining_stats_raw = urlopen(mining_req, timeout=15) |
||
| 81 | except IOError as exc: |
||
| 82 | print("Failed to request Flypool API: {}".format(exc), file=sys.stderr)
|
||
| 83 | |||
| 84 | reader = codecs.getreader("utf-8")
|
||
| 85 | |||
| 86 | try: |
||
| 87 | mining_stats = json.load(reader(mining_stats_raw)) |
||
| 88 | except ValueError: |
||
| 89 | print("Failed to parse JSON responce.", file=sys.stderr)
|
||
| 90 | sys.exit(9) |
||
| 91 | |||
| 92 | try: |
||
| 93 | worker = mining_stats['data'] |
||
| 94 | except: |
||
| 95 | print("JSON result error!", file=sys.stderr)
|
||
| 96 | sys.exit(9) |
||
| 97 | |||
| 98 | try: |
||
| 99 | hash_rate = worker['currentHashrate'] |
||
| 100 | except: |
||
| 101 | print("No current Hashrate!", file=sys.stderr)
|
||
| 102 | sys.exit(9) |
||
| 103 | |||
| 104 | 21341b5a | Nils | print("flypool_hs_{}_{}.value {}".format(zcash_address, miner, hash_rate)) |
