mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-21 18:41:03 +00:00
move bitcoin to currency folder
This commit is contained in:
parent
f5715e5eba
commit
f81bdebc3b
4 changed files with 0 additions and 0 deletions
241
plugins/currency/bitcoin/bitcoind_
Executable file
241
plugins/currency/bitcoin/bitcoind_
Executable file
|
@ -0,0 +1,241 @@
|
|||
#!/usr/bin/env python
|
||||
# bitcoind_ Munin plugin for Bitcoin Server Variables
|
||||
#
|
||||
# by Mike Koss
|
||||
# Feb 14, 2012, MIT License
|
||||
#
|
||||
# You need to be able to authenticate to the bitcoind server to issue rpc's.
|
||||
# This plugin supporst 2 ways to do that:
|
||||
#
|
||||
# 1) In /etc/munin/plugin-conf.d/bitcoin.conf place:
|
||||
#
|
||||
# [bitcoind_*]
|
||||
# user your-username
|
||||
#
|
||||
# Then be sure your $HOME/.bitcoin/bitcoin.conf has the correct authentication info:
|
||||
# rpcconnect, rpcport, rpcuser, rpcpassword
|
||||
#
|
||||
# 2) Place your bitcoind authentication directly in /etc/munin/plugin-conf.d/bitcoin.conf
|
||||
#
|
||||
# [bitcoind_*]
|
||||
# env.rpcport 8332
|
||||
# env.rpcconnect 127.0.0.1
|
||||
# env.rpcuser your-username-here
|
||||
# env.rpcpassword your-password-here
|
||||
#
|
||||
# To install all available graphs:
|
||||
#
|
||||
# sudo munin-node-configure --libdir=. --suggest --shell | sudo bash
|
||||
#
|
||||
# Leave out the "| bash" to get a list of commands you can select from to install
|
||||
# individual graphs.
|
||||
#
|
||||
# Munin plugin tags:
|
||||
#
|
||||
#%# family=auto
|
||||
#%# capabilities=autoconf suggest
|
||||
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import re
|
||||
import urllib2
|
||||
import json
|
||||
|
||||
|
||||
DEBUG = False
|
||||
|
||||
|
||||
def main():
|
||||
# getinfo variable is read from command name - probably the sym-link name.
|
||||
request_var = sys.argv[0].split('_', 1)[1] or 'balance'
|
||||
command = sys.argv[1] if len(sys.argv) > 1 else None
|
||||
request_labels = {'balance': ('Wallet Balance', 'BTC'),
|
||||
'connections': ('Peer Connections', 'Connections'),
|
||||
'fees': ("Tip Offered", "BTC"),
|
||||
'transactions': ("Transactions", "Transactions",
|
||||
('confirmed', 'waiting')),
|
||||
'block_age': ("Last Block Age", "Seconds"),
|
||||
'difficulty': ("Difficulty", ""),
|
||||
}
|
||||
labels = request_labels[request_var]
|
||||
if len(labels) < 3:
|
||||
line_labels = [request_var]
|
||||
else:
|
||||
line_labels = labels[2]
|
||||
|
||||
if command == 'suggest':
|
||||
for var_name in request_labels.keys():
|
||||
print var_name
|
||||
return
|
||||
|
||||
if command == 'config':
|
||||
print 'graph_category htc'
|
||||
print 'graph_title Bitcoin %s' % labels[0]
|
||||
print 'graph_vlabel %s' % labels[1]
|
||||
for label in line_labels:
|
||||
print '%s.label %s' % (label, label)
|
||||
return
|
||||
|
||||
# Munin should send connection options via environment vars
|
||||
bitcoin_options = get_env_options('rpcconnect', 'rpcport', 'rpcuser', 'rpcpassword')
|
||||
bitcoin_options.rpcconnect = bitcoin_options.get('rpcconnect', '127.0.0.1')
|
||||
bitcoin_options.rpcport = bitcoin_options.get('rpcport', '8332')
|
||||
|
||||
if bitcoin_options.get('rpcuser') is None:
|
||||
conf_file = os.path.join(os.path.expanduser('~/.bitcoin'), 'bitcoin.conf')
|
||||
bitcoin_options = parse_conf(conf_file)
|
||||
|
||||
bitcoin_options.require('rpcuser', 'rpcpassword')
|
||||
|
||||
bitcoin = ServiceProxy('http://%s:%s' % (bitcoin_options.rpcconnect,
|
||||
bitcoin_options.rpcport),
|
||||
username=bitcoin_options.rpcuser,
|
||||
password=bitcoin_options.rpcpassword)
|
||||
|
||||
(info, error) = bitcoin.getinfo()
|
||||
|
||||
if error:
|
||||
if command == 'autoconf':
|
||||
print 'no'
|
||||
return
|
||||
else:
|
||||
# TODO: Better way to report errors to Munin-node.
|
||||
raise ValueError("Could not connect to Bitcoin server.")
|
||||
|
||||
if request_var in ('transactions', 'block_age'):
|
||||
(info, error) = bitcoin.getblockhash(info['blocks'])
|
||||
(info, error) = bitcoin.getblock(info)
|
||||
info['block_age'] = int(time.time()) - info['time']
|
||||
info['confirmed'] = len(info['tx'])
|
||||
|
||||
if request_var in ('fees', 'transactions'):
|
||||
(memory_pool, error) = bitcoin.getrawmempool()
|
||||
if memory_pool:
|
||||
info['waiting'] = len(memory_pool)
|
||||
|
||||
if command == 'autoconf':
|
||||
print 'yes'
|
||||
return
|
||||
|
||||
for label in line_labels:
|
||||
print "%s.value %s" % (label, info[label])
|
||||
|
||||
|
||||
def parse_conf(filename):
|
||||
""" Bitcoin config file parser. """
|
||||
|
||||
options = Options()
|
||||
|
||||
re_line = re.compile(r'^\s*([^#]*)\s*(#.*)?$')
|
||||
re_setting = re.compile(r'^(.*)\s*=\s*(.*)$')
|
||||
try:
|
||||
with open(filename) as file:
|
||||
for line in file.readlines():
|
||||
line = re_line.match(line).group(1).strip()
|
||||
m = re_setting.match(line)
|
||||
if m is None:
|
||||
continue
|
||||
(var, value) = (m.group(1), m.group(2).strip())
|
||||
options[var] = value
|
||||
except:
|
||||
pass
|
||||
|
||||
return options
|
||||
|
||||
|
||||
def get_env_options(*vars):
|
||||
options = Options()
|
||||
for var in vars:
|
||||
options[var] = os.getenv(var)
|
||||
return options
|
||||
|
||||
|
||||
class Options(dict):
|
||||
"""A dict that allows for object-like property access syntax."""
|
||||
def __getattr__(self, name):
|
||||
try:
|
||||
return self[name]
|
||||
except KeyError:
|
||||
raise AttributeError(name)
|
||||
|
||||
def require(self, *names):
|
||||
missing = []
|
||||
for name in names:
|
||||
if self.get(name) is None:
|
||||
missing.append(name)
|
||||
if len(missing) > 0:
|
||||
raise ValueError("Missing required setting%s: %s." %
|
||||
('s' if len(missing) > 1 else '',
|
||||
', '.join(missing)))
|
||||
|
||||
|
||||
class ServiceProxy(object):
|
||||
"""
|
||||
Proxy for a JSON-RPC web service. Calls to a function attribute
|
||||
generates a JSON-RPC call to the host service. If a callback
|
||||
keyword arg is included, the call is processed as an asynchronous
|
||||
request.
|
||||
|
||||
Each call returns (result, error) tuple.
|
||||
"""
|
||||
def __init__(self, url, username=None, password=None):
|
||||
self.url = url
|
||||
self.id = 0
|
||||
self.username = username
|
||||
self.password = password
|
||||
|
||||
def __getattr__(self, method):
|
||||
self.id += 1
|
||||
return Proxy(self, method, id=self.id)
|
||||
|
||||
|
||||
class Proxy(object):
|
||||
def __init__(self, service, method, id=None):
|
||||
self.service = service
|
||||
self.method = method
|
||||
self.id = id
|
||||
|
||||
def __call__(self, *args):
|
||||
if DEBUG:
|
||||
arg_strings = [json.dumps(arg) for arg in args]
|
||||
print "Calling %s(%s) @ %s" % (self.method,
|
||||
', '.join(arg_strings),
|
||||
self.service.url)
|
||||
|
||||
data = {
|
||||
'method': self.method,
|
||||
'params': args,
|
||||
'id': self.id,
|
||||
}
|
||||
request = urllib2.Request(self.service.url, json.dumps(data))
|
||||
if self.service.username:
|
||||
# Strip the newline from the b64 encoding!
|
||||
b64 = ('%s:%s' % (self.service.username, self.service.password)).encode('base64')[:-1]
|
||||
request.add_header('Authorization', 'Basic %s' % b64)
|
||||
|
||||
try:
|
||||
body = urllib2.urlopen(request).read()
|
||||
except Exception, e:
|
||||
return (None, e)
|
||||
|
||||
if DEBUG:
|
||||
print 'RPC Response (%s): %s' % (self.method, json.dumps(body, indent=4))
|
||||
|
||||
try:
|
||||
data = json.loads(body)
|
||||
except ValueError, e:
|
||||
return (None, e.message)
|
||||
# TODO: Check that id matches?
|
||||
return (data['result'], data['error'])
|
||||
|
||||
|
||||
def get_json_url(url):
|
||||
request = urllib2.Request(url)
|
||||
body = urllib2.urlopen(request).read()
|
||||
data = json.loads(body)
|
||||
return data
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
41
plugins/currency/bitcoin/btcguild_hashrate_
Normal file
41
plugins/currency/bitcoin/btcguild_hashrate_
Normal file
|
@ -0,0 +1,41 @@
|
|||
#!/usr/bin/python
|
||||
# based on https://github.com/pdbrown/munin-custom/blob/master/plugins/hashrate
|
||||
# improved by @deveth0 (donation to 1GzHgp9hsDRsf96MnVk2oo6EG1VmWP9jGs :) )
|
||||
# usage: link to btcguild_hashrate_YOURAPIKEY
|
||||
import sys
|
||||
import urllib2
|
||||
import json
|
||||
|
||||
URL = 'https://www.btcguild.com/api.php?api_key='
|
||||
API_KEY = sys.argv[0][(sys.argv[0].rfind('_')+1):]
|
||||
|
||||
STATS = URL + API_KEY
|
||||
|
||||
print STATS
|
||||
|
||||
command = ''
|
||||
if len(sys.argv) > 1:
|
||||
command = sys.argv[1]
|
||||
|
||||
header = {'User-Agent':'Mozilla/5.0'}
|
||||
request = urllib2.Request(STATS,headers=header)
|
||||
mining_stats_raw = urllib2.urlopen(request)
|
||||
mining_stats = json.load(mining_stats_raw)
|
||||
workers = mining_stats['workers']
|
||||
|
||||
|
||||
if command == 'config':
|
||||
print "graph_title BTCGuild Hashrate"
|
||||
print "graph_args --upper-limit 3000 -l 0"
|
||||
print "graph_vlabel MHash/s"
|
||||
print "graph_category htc"
|
||||
for worker in workers:
|
||||
label = workers[worker]['worker_name']
|
||||
print label + ".label " + label
|
||||
sys.exit(0)
|
||||
|
||||
for worker in workers:
|
||||
hash_rate = workers[worker]['hash_rate']
|
||||
label = workers[worker]['worker_name']
|
||||
print label + ".value %d" % int(hash_rate)
|
||||
|
37
plugins/currency/bitcoin/slush_hashrate_
Normal file
37
plugins/currency/bitcoin/slush_hashrate_
Normal file
|
@ -0,0 +1,37 @@
|
|||
#!/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 htc"
|
||||
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)
|
37
plugins/currency/bitcoin/slush_reward_
Normal file
37
plugins/currency/bitcoin/slush_reward_
Normal file
|
@ -0,0 +1,37 @@
|
|||
#!/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)
|
||||
|
||||
command = ''
|
||||
if len(sys.argv) > 1:
|
||||
command = sys.argv[1]
|
||||
|
||||
if command == 'config':
|
||||
print "graph_title Slush Rewards"
|
||||
print "graph_args -l 0"
|
||||
print "graph_vlabel BTC"
|
||||
print "graph_category htc"
|
||||
print "unconfirmed_reward.label Unconfirmed Reward"
|
||||
print "estimated_reward.label Estimeated Reward"
|
||||
print "confirmed_reward.label Confirmed Reward"
|
||||
print "send_threshold.label Send Threshold"
|
||||
sys.exit(0)
|
||||
|
||||
print "unconfirmed_reward.value " +mining_stats['unconfirmed_reward']
|
||||
print "estimated_reward.value " +mining_stats['estimated_reward']
|
||||
print "confirmed_reward.value " +mining_stats['confirmed_reward']
|
||||
print "send_threshold.value " +mining_stats['send_threshold']
|
Loading…
Add table
Add a link
Reference in a new issue