From 4d9a7e2cabc970d65ba12cf446236c6499ff77a0 Mon Sep 17 00:00:00 2001 From: Nils Date: Tue, 27 Mar 2018 11:36:14 +0200 Subject: [PATCH] Zcash Flypool Hashrate Munin plugin to monitor your zcash.flypool.org hashrate. --- .../currency/zcash/zcash_flypool_hashrate_ | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100755 plugins/currency/zcash/zcash_flypool_hashrate_ diff --git a/plugins/currency/zcash/zcash_flypool_hashrate_ b/plugins/currency/zcash/zcash_flypool_hashrate_ new file mode 100755 index 00000000..d11fb7fb --- /dev/null +++ b/plugins/currency/zcash/zcash_flypool_hashrate_ @@ -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__ + +=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. + +=head1 VERSION + +0.0.1 + +=head1 AUTHOR + +L + +=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__'", 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)) \ No newline at end of file