Example setup to collect Monero related metrics using bash + InfluxDB and Grafana.
Demo: https://monitor.ditatompel.com/d/xmr_metrics/monero-metrics?orgId=2
In this article, I use : Ubuntu 18.04 for Grafana and InfluxDB.
If you already have Grafana, you can skip this step. For detailed installation guide on Debian based, please follow official installation guide.
Add stable Grafana OSS repository:
sudo apt-get install -y apt-transport-https
sudo apt-get install -y software-properties-common wget curl
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
Install Grafana:
sudo apt-get update
sudo apt-get install grafana
Start Grafana service and make sure service is running (systemd):
sudo systemctl daemon-reload
sudo systemctl start grafana-server
sudo systemctl status grafana-server
To make Grafana server to start at boot:
sudo systemctl enable grafana-server.service
Add the InfluxData repository:
echo "deb https://repos.influxdata.com/ubuntu bionic stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
sudo curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
Install InfluxDB:
sudo apt-get update
sudo apt-get install influxdb
Start InfluxDB service and make sure service is running (systemd):
sudo systemctl daemon-reload
sudo systemctl start influxdb
sudo systemctl status influxdb
To make InfluxDB server to start at boot:
sudo systemctl enable influxdb.service
Launch InfluxDB’s command line interface (influx
)
influx -precision rfc3339
Once you’ve entered the shell and successfully connected to InfluxDB, create at least one InfluxDB admin user:
CREATE USER <YOUR_INFLUXDB_ADMIN_USER> WITH PASSWORD '<YOUR_INFLUXDB_ADMIN_PASSWORD>' WITH ALL PRIVILEGES
Change
<YOUR_INFLUXDB_ADMIN_USER>
and<YOUR_INFLUXDB_ADMIN_PASSWORD>
with your desired username and password
Create database to store Monero Metrics:
CREATE DATABASE MoneroMetrics
Create non-admin user (for Grafana and bash script we use latter) and grant privileges to MoneroMetrics
database:
CREATE USER grafana WITH PASSWORD 'some_password'
GRANT READ ON MoneroMetrics TO grafana
CREATE USER monero WITH PASSWORD 'some_password'
GRANT ALL ON MoneroMetrics TO monero
Enable authentication in your configuration file (/etc/influxdb/influxdb.conf
) by setting the auth-enabled
option to true
in the [http]
section:
Note: You might also need to disable queue limit and timeout by setting the
max-enqueued-write-limit
andenqueued-write-timeout
to0
in the[http]
section.
Restart InfluxDB service
systemctl restart influxdb
In this article, there are 5 types of metric we will collect and store it to InfluxDB:
- Node metrics via
monerod
RPC (NodeMetrics.sh) - XMRig worker metrics (XmrigMetrics.sh)
- Pool metrics (PoolMetrics.sh)
- Exchange metrics (IndodaxExchange.sh & KrakenExchange.sh)
monero-project/monero
GitHub metrics (GitHubMetrics.sh)r/Monero
Reddit metrics (RedditMetrics.sh)
You can find all example files under examples directory.
All script written in bash, jq
and curl
package is required to run all of these script. In additional, and bc
package is required to run PoolMetrics.sh
.
Make sure all bash script is executable and run them using cron job.
File: examples/bash/NodeMetrics.sh
If you run local or public Monero node, you can scrap monerod
metrics using its rpc
or restricted-rpc
.
Restrict RPC is view only commands and do not return privacy sensitive data in RPC calls. So, some data like *_connections_count
, *_peerlist_size
will return 0
.
File: examples/bash/XmrigMetrics.sh
In order to grab XMRig worker metrics, we need to enable XMRig HTTP API for each your XMRig devices. Eg:
{
"api": {
"id": null,
"worker-id": null
},
"http": {
"enabled": true,
"host": "i.i.i.i",
"port": 54321,
"access-token": "your password",
"restricted": true
},
...
File: examples/bash/PoolMetrics.sh
For now, only mining pool who use jtgrassie/monero-pool, Snipa22/nodejs-pool and SChernykh/p2pool backend is supported. Feel free to edit the script and add your favorite mining pool backend.
it's quite easy to find pool backend and usually each frontend design quite similar. For example: monerop.com, xmrvsbeast.com using jtgrassie and moneroocean.stream, moneromine.co using snipa22.
Important About Pool Metrics:
You may doesn't need to grab Network Difficulty and Network Height data from your mining pool server, especially those who use nodejs-pool by Snipa22. This because we need to fetch one additional API request to the server and may cause DOS effect on high traffic pool.
Avoid doing that by comment out NetworkInfo=$(curl -s ${POOLPARAMS[1]}/network/stats ...
and remove NetDiff=$NetworkDiff
and NetHeight=$NetworkHeight
InfluxDB data post. Eg:
curl -i -XPOST 'http://192.168.100.1:8086/write?db=MoneroMetrics' -u monero:some_password --data-binary "PoolInfo,Node=${POOLPARAMS[0]} PoolHR=$PoolHR,RoundHR=$RoundHashes,LastBlock=$LastBlockFound,BlockFound=$PoolBlockFound,CountMiners=$ConnectedMiners,MyHashrate=$MinerHashrate,MyBalance=$MinerBalance"
Files: examples/bash/IndodaxExchange.sh and examples/bash/KrakenExchange.sh
If you like to add coin price, market, etc, you can use your favorite exchange API. In this example, I use Indodax API as my local currency exchange. You may create your own script to do that. Some exchange like Kraken provide an example API client, but if you like to use simple bash script, you can take a look into examples/bash/KrakenExchange.sh.
After all data is collected, lets create the Grafana dashboard. We need to add our InfluxDB data source first.
Login to Grafana > Configuration
> Data Sources
> Add Data Source
and choose InfluxDB
.
Leave Query Language to default (InfluxQL
)
In the HTTP
section, fill URL
to your InfluxDB server.
In InfluxDB
Details section, fill your database access details:
Database: MoneroMetrics
User: grafana
Password: your_configured_password
Save and Test.
Now you can create your Monero dashboard. You may export my dashboard template from the demo site by clicking share icon.
Note: In order to use my dashboard, you may need to install Blendstat panel plugin.
- Grafana Installation (Grafana Docs)
- Install InfluxDB on Ubuntu 20.04/18.04 and Debian 9 by Josphat Mutai
- Authentication and authorization in InfluxDB (InfluxDB Docs)
- Using InfluxDB in Grafana (Grafana Docs)
- Create Fancy Graph with metrics from XMRIG (1/3) by master-lamps
- Create Fancy Graph with metrics from XMRIG (2/3) by master-lamps
- Create Fancy Graph with metrics from XMRIG (3/3) by master-lamps
If you want to create data scraping using your desired programming language, feel free to create a pull request.