mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 14:16:00 +00:00
bitcoind_: update for Bitcoin Core v0.19.0 release
* Use new RPC calls to get relevant statistics, as some calls are either deprecated or completely removed. * Fix response printing when MUNIN_DEBUG is set. * Remove "fees" graph as there is no sane way to implement that. * Add missing success return.
This commit is contained in:
parent
642b48a4f7
commit
15f1055e2c
1 changed files with 25 additions and 10 deletions
|
@ -69,7 +69,6 @@ def main():
|
||||||
command = sys.argv[1] if len(sys.argv) > 1 else None
|
command = sys.argv[1] if len(sys.argv) > 1 else None
|
||||||
request_labels = {'balance': ('Wallet Balance', 'BTC'),
|
request_labels = {'balance': ('Wallet Balance', 'BTC'),
|
||||||
'connections': ('Peer Connections', 'Connections'),
|
'connections': ('Peer Connections', 'Connections'),
|
||||||
'fees': ("Tip Offered", "BTC"),
|
|
||||||
'transactions': ("Transactions", "Transactions",
|
'transactions': ("Transactions", "Transactions",
|
||||||
('confirmed', 'waiting')),
|
('confirmed', 'waiting')),
|
||||||
'block_age': ("Last Block Age", "Seconds"),
|
'block_age': ("Last Block Age", "Seconds"),
|
||||||
|
@ -120,8 +119,9 @@ def main():
|
||||||
bitcoin_options.rpcport),
|
bitcoin_options.rpcport),
|
||||||
username=bitcoin_options.rpcuser,
|
username=bitcoin_options.rpcuser,
|
||||||
password=bitcoin_options.rpcpassword)
|
password=bitcoin_options.rpcpassword)
|
||||||
(info, connect_error) = bitcoin.getinfo()
|
(info, connect_error) = bitcoin.getnetworkinfo()
|
||||||
error = "Could not connect to Bitcoin server: {}".format(connect_error)
|
if connect_error:
|
||||||
|
error = "Could not connect to Bitcoin server: {}".format(connect_error)
|
||||||
|
|
||||||
if command == 'autoconf':
|
if command == 'autoconf':
|
||||||
if error:
|
if error:
|
||||||
|
@ -134,20 +134,35 @@ def main():
|
||||||
print(error, file=sys.stderr)
|
print(error, file=sys.stderr)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if request_var == 'balance':
|
||||||
|
# we use getbalance*s* (plural) as old getbalance is being deprecated,
|
||||||
|
# and we have to calculate total balance (owned and watch-only) manually now.
|
||||||
|
(info, error) = bitcoin.getbalances()
|
||||||
|
|
||||||
|
total = sum(info[wallet_mode]['trusted']
|
||||||
|
for wallet_mode in ('mine', 'watchonly')
|
||||||
|
if wallet_mode in info)
|
||||||
|
|
||||||
|
info['balance'] = total
|
||||||
|
|
||||||
if request_var in ('transactions', 'block_age'):
|
if request_var in ('transactions', 'block_age'):
|
||||||
(info, error) = bitcoin.getblockhash(info['blocks'])
|
(info, error) = bitcoin.getblockchaininfo()
|
||||||
(info, error) = bitcoin.getblock(info)
|
(info, error) = bitcoin.getblock(info['bestblockhash'])
|
||||||
info['block_age'] = int(time.time()) - info['time']
|
info['block_age'] = int(time.time()) - info['time']
|
||||||
info['confirmed'] = len(info['tx'])
|
info['confirmed'] = len(info['tx'])
|
||||||
|
|
||||||
if request_var in ('fees', 'transactions'):
|
if request_var == 'difficulty':
|
||||||
(memory_pool, error) = bitcoin.getrawmempool()
|
(info, error) = bitcoin.getblockchaininfo()
|
||||||
if memory_pool:
|
|
||||||
info['waiting'] = len(memory_pool)
|
if request_var == 'transactions':
|
||||||
|
(memory_pool, error) = bitcoin.getmempoolinfo()
|
||||||
|
info['waiting'] = memory_pool['size']
|
||||||
|
|
||||||
for label in line_labels:
|
for label in line_labels:
|
||||||
print("%s.value %s" % (label, info[label]))
|
print("%s.value %s" % (label, info[label]))
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def parse_conf(filename):
|
def parse_conf(filename):
|
||||||
""" Bitcoin config file parser. """
|
""" Bitcoin config file parser. """
|
||||||
|
@ -249,7 +264,7 @@ class Proxy:
|
||||||
return (None, e)
|
return (None, e)
|
||||||
|
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print('RPC Response (%s): %s' % (self.method, json.dumps(body, indent=4)))
|
print('RPC Response (%s): %s' % (self.method, json.dumps(json.loads(body), indent=4)))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = json.loads(body)
|
data = json.loads(body)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue