From 3bf0c91b92416501e2c14919d44178159b8d0060 Mon Sep 17 00:00:00 2001 From: deveth0 Date: Tue, 28 Jan 2014 23:40:35 +0100 Subject: [PATCH] Update slush_hashrate_ Moved from filename to env parameter for the api key. This way the api key is no longer displayed as the chart name --- plugins/bitcoin/slush_hashrate_ | 71 +++++++++++++++++---------------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/plugins/bitcoin/slush_hashrate_ b/plugins/bitcoin/slush_hashrate_ index f2089f15..9201c917 100644 --- a/plugins/bitcoin/slush_hashrate_ +++ b/plugins/bitcoin/slush_hashrate_ @@ -1,34 +1,37 @@ -#!/usr/bin/python -# based on https://github.com/pdbrown/munin-custom/blob/master/plugins/hashrate -# improved by @deveth0 (donation to 1GzHgp9hsDRsf96MnVk2oo6EG1VmWP9jGs :) ) -# usage: link to slush_hashrate_YOURAPIKEY -import sys -import urllib2 -import json - -SLUSH_URL = 'https://mining.bitcoin.cz/accounts/profile/json/' -API_KEY = sys.argv[0][(sys.argv[0].rfind('_')+1):] -SLUSH_STATS = SLUSH_URL + API_KEY - -mining_stats_raw = urllib2.urlopen(SLUSH_STATS) -mining_stats = json.load(mining_stats_raw) -workers = mining_stats['workers'] - -command = '' -if len(sys.argv) > 1: - command = sys.argv[1] - -if command == 'config': - print "graph_title Slush Hashrate" - print "graph_args --upper-limit 3000 -l 0" - print "graph_vlabel MHash/s" - print "graph_category Bitcoin" - for worker in workers: - label = worker.replace(".","_") - print label + ".label " +label - sys.exit(0) - -for worker in workers: - hash_rate = workers[worker]['hashrate'] - label = worker.replace(".","_") - print label + ".value %d" % int(hash_rate) +#!/usr/bin/python +# based on https://github.com/pdbrown/munin-custom/blob/master/plugins/hashrate +# improved by @deveth0 (donation to 1GzHgp9hsDRsf96MnVk2oo6EG1VmWP9jGs :) ) +# usage: set your api key in node-config, eg +# [slush_*] +# env.apikey foobar +import sys +import urllib2 +import json +import os + +SLUSH_URL = 'https://mining.bitcoin.cz/accounts/profile/json/' +API_KEY = os.getenv('apikey') +SLUSH_STATS = SLUSH_URL + API_KEY + +mining_stats_raw = urllib2.urlopen(SLUSH_STATS) +mining_stats = json.load(mining_stats_raw) +workers = mining_stats['workers'] + +command = '' +if len(sys.argv) > 1: + command = sys.argv[1] + +if command == 'config': + print "graph_title Slush Hashrate" + print "graph_args --upper-limit 3000 -l 0" + print "graph_vlabel MHash/s" + print "graph_category Bitcoin" + for worker in workers: + label = worker.replace(".","_") + print label + ".label " +label + sys.exit(0) + +for worker in workers: + hash_rate = workers[worker]['hashrate'] + label = worker.replace(".","_") + print label + ".value %d" % int(hash_rate)