2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00

Zcash Flypool Hashrate

Munin plugin to monitor your zcash.flypool.org hashrate.
This commit is contained in:
Nils 2018-03-27 11:36:14 +02:00
parent 6b42464ca7
commit 4d9a7e2cab

View File

@ -0,0 +1,113 @@
#!/usr/bin/env python
"""
=head1 NAME
zcash_flypool_hashrate_ - Munin plugin to monitor your zcash.flypool.org hashrate (H/s)
=head1 APPLICABLE SYSTEMS
All systems with "python" and "munin"
=head1 CONFIGURATION
zcash_flypool_hashrate_<YOUR_ZCASH_ADDRESS>_<YOUR_WORKER_NAME>
=head1 SYNOPSIS
ln -s /usr/share/munin/plugins/zcash_flypool_hashrate_ \
/etc/munin/plugins/zcash_flypool_hashrate_t1gMVWjGhdjvb71UU11JDrFmiZhgUf4x5TH_mine
=head1 INTERPRETATION
This plugin shows the zcash.flypool.org mining pool hashrate (H/s) of a given Zcasg address and rig name.
Hashrate is queried via Flypool API L<https://zcash.flypool.org>.
=head1 VERSION
0.0.1
=head1 AUTHOR
L<Nils Knieling|https://github.com/Cyclenerd>
=head1 LICENSE
GPLv2
=head1 MAGIC MARKERS
#%# family=manual
=cut
"""
from __future__ import print_function
import sys
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:
command = sys.argv[1]
try:
zcash_address, miner = sys.argv[0].split("_")[3:]
except ValueError:
print("The filename of this plugin (or its symlink) should follow this pattern: "
"'zcash_flypool_hashrate_<YOUR_ZCASH_ADDRESS>_<YOUR_WORKER_NAME>'", file=sys.stderr)
sys.exit(9)
if command == 'config':
print("graph_title Flypool {}".format(miner))
print("graph_info zcash.flypool.org Mining Pool Hashrate for {}_{}".format(zcash_address, miner))
print("graph_vlabel Flypool Hashrate")
print("graph_category other")
print("flypool_hs_{}_{}.warning 200:".format(zcash_address, miner))
print("flypool_hs_{}_{}.critical 100:".format(zcash_address, miner))
print("flypool_hs_{}_{}.label H/s:".format(zcash_address, miner))
sys.exit(0)
flypool_api_url = 'https://api-zcash.flypool.org/miner/' + zcash_address + '/worker/' + miner + '/currentStats'
mining_req = Request(flypool_api_url)
# User-Agent to bypass Cloudflare
mining_req.add_header('User-Agent', 'Flypool Munin Plugin/1.0')
try:
mining_stats_raw = urlopen(mining_req, timeout=15)
except IOError as exc:
print("Failed to request Flypool API: {}".format(exc), file=sys.stderr)
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)
sys.exit(9)
try:
worker = mining_stats['data']
except:
print("JSON result error!", file=sys.stderr)
sys.exit(9)
try:
hash_rate = worker['currentHashrate']
except:
print("No current Hashrate!", file=sys.stderr)
sys.exit(9)
print("flypool_hs_{}_{}.value {}".format(zcash_address, miner, hash_rate))