• Forum has been upgraded, all links, images, etc are as they were. Please see Official Announcements for more information

monitoring multiple nm using blocknotify

chaeplin

Well-known member
Status updated when a new block is received.

Code:
-blocknotify=<cmd>     Execute command when the best block changes (%s in cmd is replaced by block hash)
-walletnotify=<cmd>    Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)
-alertnotify=<cmd>     Execute command when a relevant alert is received (%s in cmd is replaced by message)

# darkcoin.conf // each user
Code:
blocknotify=/usr/local/bin/darkcoinmonitor.sh

# /usr/local/bin/darkcoinmonitor.sh
Code:
#!/bin/sh
myid=$USER
/usr/bin/darkcoind getinfo             > /dev/shm/getinfo.$myid
/usr/bin/darkcoind masternode debug     > /dev/shm/debug.$myid
/usr/bin/darkcoind masternode count     > /dev/shm/count.$myid
/usr/bin/darkcoind masternode current   > /dev/shm/current.$myid


as root.
Code:
# grep error /dev/shm/getinfo.nm0*
/dev/shm/getinfo.nm01:    "errors" : ""
/dev/shm/getinfo.nm02:    "errors" : ""
/dev/shm/getinfo.nm03:    "errors" : ""
/dev/shm/getinfo.nm04:    "errors" : ""
/dev/shm/getinfo.nm05:    "errors" : ""
Code:
# grep blocks /dev/shm/getinfo.nm0*
/dev/shm/getinfo.nm01:    "blocks" : 97919,
/dev/shm/getinfo.nm02:    "blocks" : 97919,
/dev/shm/getinfo.nm03:    "blocks" : 97919,
/dev/shm/getinfo.nm04:    "blocks" : 97919,
/dev/shm/getinfo.nm05:    "blocks" : 97919,
Code:
# cat /dev/shm/count.nm0*
577
577
577
577
577
Code:
# cat /dev/shm/current.nm0*
162.243.254.15:9999
162.243.254.15:9999
162.243.254.15:9999
162.243.254.15:9999
162.243.254.15:9999
Code:
# cat /dev/shm/debug.nm0*
Missing masternode input, please look at the documentation for instructions on masternode creation
Missing masternode input, please look at the documentation for instructions on masternode creation
Missing masternode input, please look at the documentation for instructions on masternode creation
Missing masternode input, please look at the documentation for instructions on masternode creation
Missing masternode input, please look at the documentation for instructions on masternode creation

if error occured.
Code:
# cat /dev/shm/getinfo.nm01
{
    "version" : 101105,
    "protocolversion" : 70018,
    "walletversion" : 60000,
    "balance" : 0.00000000,
    "blocks" : 97920,
    "timeoffset" : 0,
    "connections" : 9,
    "proxy" : "",
    "difficulty" : 2830.06364659,
    "testnet" : false,
    "keypoololdest" : 1404495439,
    "keypoolsize" : 101,
    "paytxfee" : 0.00000000,
    "mininput" : 0.00001000,
    "errors" : "EXCEPTION: St9bad_alloc       \nstd::bad_alloc       \ndarkcoin in ProcessMessages()       \n"
}
 
Last edited by a moderator:
Using python and https://github.com/jgarzik/python-bitcoinrpc

change code in /usr/local/bin/darkcoindmonitor.sh

Code:
#!/usr/bin/python
import io
import os
import sys
import datetime
from time import time
from time import sleep
import getpass
from bitcoinrpc.authproxy import AuthServiceProxy

#--------------
def ParseConfig(fileBuffer):
    assert type(fileBuffer) is type(b'')
    f = io.StringIO(fileBuffer.decode('ascii', errors='ignore'), newline=None)
    result = {}
    for line in f:
        assert type(line) is type(b''.decode())
        stripped = line.strip()
        if stripped.startswith('#'):
            continue
        if stripped == '':
            continue
        parts = stripped.split('=')
        assert len(parts) == 2
        parts[0] = parts[0].strip()
        parts[1] = parts[1].strip()
        result[parts[0]] = parts[1]
    return result

#----------------------------

with open(os.path.join(os.path.expanduser("~"), '.darkcoin', 'darkcoin.conf'), mode='rb') as f:
    configFileBuffer = f.read()
config = ParseConfig(configFileBuffer)
serverURL = 'http://' + config['rpcuser'] + ':' + config['rpcpassword'] + '@localhost:' + str(config['rpcport'])
access = AuthServiceProxy(serverURL)

#-----------------------------
oneday = int(time())
USER=getpass.getuser()

#-----------------------------

i1 = access.getinfo()
i2 = access.masternode('debug')
i3 = access.masternode('count')
i4 = access.masternode('current')

getinfo = 'bl: ' + str(i1['blocks']) + ' diff: ' + str(i1['difficulty']) + ' conn: ' + str(i1['connections']) + ' errors: ' + str(i1['errors']) + '\n'

i1fo = open('/dev/shm/getinfo.' + USER, 'w')
i2fo = open('/dev/shm/debug.' + USER, 'w')
i3fo = open('/dev/shm/count.' + USER, 'w')
i4fo = open('/dev/shm/current.' + USER, 'w')


i1fo.write(getinfo)
i1fo.close()

i2fo.write(str(i2) + '\n')
i2fo.close()

i3fo.write(str(i3) + '\n')
i3fo.close()

i4fo.write(str(i4) + '\n')
i4fo.close()
 
Once I've got my triple node up and running this is going straight in. Nice work!
 
Hi,

Using shared memory to to make the status of each node available is a good idea. I haven't thought about that kind of approach to monitor masternodes. One could write a parser / plugin to monitor the shared memory and feed the data to your favourite monitoring solution (such as nagios). I'm currently monitoring a masternode single instance by sending out emails via ssmtp but your approach looks way better.
 
I would love an android app that lists the status of my masternodes and vibrates when a payment is received.
 
and one for the iPhone please
while you are at it !
that would be amazing !

a friend of mine got an iPhone app (not pretty) done for 2000 US !
 
Back
Top