Jump to content
Sign in to follow this  

Crypto Stats using Grafana, InfluxDB, Denarius Daemon

Recommended Posts

How to pull stats from a coin daemon and throw them into influxdb, and then use Grafana to create a pretty graph.

Imgur Image

Setup a VM, VPS, raspberry pi, whatever to play on this. Anything breaks its pretty easy to delete stuff. Using ubuntu/debian for the example.

The idea is relatively simple. Ask the daemon for information, throw that into influxdb and then have Grafana pull from that database.

Install denarius daemon
Install python denarius rpc
Install grafana
Install influxdb

One this is all done we need a test to see if python is working with the daemon. Switch in rpc_user and rpc_password that's inside of denarius.conf


from denariusrpc.authproxy import AuthServiceProxy, JSONRPCException

# rpc_user and rpc_password are set in the denarius.conf file
rpc_connection = AuthServiceProxy("http://%s:%[email protected]:32369"%(rpc_user, rpc_password))
best_block_hash = rpc_connection.getbestblockhash()

# batch support : print timestamps of blocks 0 to 99 in 2 RPC round-trips:
commands = [ [ "getblockhash", height] for height in range(100) ]
block_hashes = rpc_connection.batch_(commands)
blocks = rpc_connection.batch_([ [ "getblock", h ] for h in block_hashes ])
block_times = [ block["time"] for block in blocks ]

test run

python test.py

Lets double check another test run to get current Denarius price from Coinvex.


from denariusrpc.authproxy import AuthServiceProxy, JSONRPCException

import requests, urllib, json

coinvex_url = requests.get('https://coinvex.org/api/v1/public/getlastmarketdata')
coinvex_data = json.loads(coinvex_url.text)
coinvex_price = coinvex_data['result']['coins']
for r in coinvex_price:
    if r["name"] == "Denarius":
        coinvex_last = float(r["price"])
        print format(coinvex_last, '0.8f')

test run

python testcoinvex.py

Works? The next post will show how to take this data and put into influxdb.

  • Like 1

Join Denarius Discord - https://discord.gg/JQEmXwb

Share this post

Link to post
Share on other sites

Create a new database ininfluxdb. Run influx to get into the command prompt.


create database


use database

USE mydb

from a second command line, lets make a sample.py


from denariusrpc.authproxy import AuthServiceProxy, JSONRPCException

import time
import sys
import datetime
import urllib
import json
from influxdb import InfluxDBClient

# rpc_user and rpc_password are set in the denarius.conf file
rpc_connection = AuthServiceProxy("http://%s:%[email protected]:32369"%("rpc_user", "rpc_password"))

blocktest = rpc_connection.getblockcount()

# Configure InfluxDB connection variables
host = "" # My Ubuntu NUC
port = 8086 # default port
user = "admin" # the user/password created for the pi, with write access
password = "admin" 
dbname = "mydb" # the database we created earlier
interval = 60 # Sample period in seconds

# Create the InfluxDB client object
client = InfluxDBClient(host, port, user, password, dbname)

# think of measurement as a SQL table, it's not...but...
measurement = "measurement"
# location will be used as a grouping tag later
blockchain = "denarius"

blockcount = rpc_connection.getblockcount()
block = rpc_connection.getblockbynumber(blockcount)
grafanatime = block['time'] * 1000000000
hash = block['hash']
size = block['size']
height = block['height']
version = block['version']
merkleroot = block['merkleroot']
mint = int(block['mint'])
timed = block['time']
nonce = block['nonce']
bits = block['bits']
difficulty = float(block['difficulty'])
blocktrust = block['blocktrust']
chaintrust = block['chaintrust']
chainwork = block['chainwork']
previousblockhash = block['previousblockhash']
#nextblockhash = block['nextblockhash']
flags = block['flags']
proofhash = block['proofhash']
entropybit = block['entropybit']
modifier = block['modifier']
modifierchecksum = block['modifierchecksum']

data = [
      "measurement": measurement,
          "tags": {
              "blockchain": blockchain,
          "time": grafanatime,
          "fields": {
             #"block" : i,
              "hash" : hash,
              "size" : size,
	      "height" : height,
	      "version" : version,
	      "merkleroot" : merkleroot,
              "mint" : mint,
	      "time" : timed,
	      "nonce" : nonce,
	      "bits" : bits,
	      "difficulty" : difficulty,
	      "blocktrust" : blocktrust,
	      "chaintrust" : chaintrust,
	      "chainwork" : chainwork,
#	      "nextblockhash" : nextblockhash,
	      "flags" : flags,
	      "proofhash" : proofhash,
	      "entropybit" : entropybit,
	      "modifier" : modifier,
	      "modifierchecksum" : modifierchecksum
    # Send the JSON data to InfluxDB

If you run python sample.py you should see data appear in your influxdb. Run below a few times to throw data in.

python sample.py

In the other command line running influx already, make sure you are using the correct database and lets see if the data is inside.

use mydb


You should see output, now we need to connect influxdb to grafana.

  • Like 1

Join Denarius Discord - https://discord.gg/JQEmXwb

Share this post

Link to post
Share on other sites

Login to your localhost grafana.

on the left click the gear -> data sources

add data source

search for influxdb

use settings like this


save and test

Go back to the grafana homepage and click + and add query


Your query would look something like this. Remember to select your mydb database, my screenshot is using another name for the DB.






Click Save at the top right


Should see something like this on your homepage.


  • Like 1

Join Denarius Discord - https://discord.gg/JQEmXwb

Share this post

Link to post
Share on other sites

Lets make sure to run that python file over and over and over on every new block.

Go into denarius.conf and add this line. I have my files in a influx directory.


Lets create block.sh in the influx directory and throw our sample.py in there

python /home/USERNAME/influx/sample.py

make block.sh executable

chmod +x block.sh

stop and restart daemon to pick this change up

denariusd stop

If it all went right your grafana page should start updating the block count.

  • Like 1

Join Denarius Discord - https://discord.gg/JQEmXwb

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Create New...