How to Add Pool Data from Cexplorer to your Grafana Dashboard

Before we get started

This guide will walk you through the process of adding your pool stats from Cexploer.io to your Grafana dashboard.

Also credit to sanskys for documenting original procedure for adapools

Copy your Json file from Cexplorer.io. Navigate to your pool then click on Share Tab. Then scroll down to "Data" and copy link to "JSON data output" file. Copy URL.

Keep this URL you will need it later

Step 2 - Create poolStat Directory

Create poolStat directory by running the following commands:

cd $NODE_HOME
mkdir -p poolStat

Step 3 -Create script getstat.sh

Now we will create a script in the poolStat directory to pull pool stat json file and trim non-numeric strings.

Prometheus can work only with numeric data, so we must trim non-numeric strings which is returned from the JSON file provided by Cexplorer.

Replace "https://js.cexplorer.io/api-static/pool/poolID.json" with the URL that you copied from Step 1

cd poolStat
echo "curl https://js.cexplorer.io/api-static/pool/poolID.json 2>/dev/null | jq '.data | del(.pool_id, .name, .pool_id_hash, .handles, .twitter_handle, .telegram_handle, .homepage, .url, .img, .updated, .stats)' | tr -d \\\"{},: | awk NF | sed -e 's/^[ \t]*/cexplorer_/' > $NODE_HOME/poolStat/poolStat.prom" > getstats.sh

Step 4 - Add Permissions and Run the getstat Script

Add permissions and run getstat script by running these commands:

chmod +x getstats.sh
./getstats.sh

Step 5 - Check Output File

Check output file to make sure it contains only numeric values by running:

cd $NODE_HOME/poolStat
cat poolStat.prom

Your results should look similar to this example:

cexplorer_stake 1172188909230 cexplorer_stake_active 1172188909230 cexplorer_tax_ratio 1 cexplorer_tax_fix 340000000 cexplorer_blocks_epoch 0 cexplorer_blocks_lifetime 19 cexplorer_roa_short 1.226 cexplorer_roa_lifetime 1.52 cexplorer_pledge 25000000000 cexplorer_delegators 18 cexplorer_position 672 cexplorer_blocks_est_epoch 1.01 cexplorer_luck_lifetime 0.89 cexplorer_saturation 0.016733

Step 6 - Configure Prometheus to Grab Data from poolStat.prom File

Configure prometheus-node-exporter.service to grab data from poolStat.prom file.

First let's backup the prometheus-node-exporter.service file by running the following:

sudo cp /lib/systemd/system/prometheus-node-exporter.service /lib/systemd/system/prometheus-node-exporter.service_backup

Then let's edit file by running the following command:

sudo nano /lib/systemd/system/prometheus-node-exporter.service

Now we need to change ExecStart line to:

Replace "< YOUR NODE FULL PATH >" Hint: to find your full path run:

cd $NODE_HOME

readlink -f poolStat

[Service]
ExecStart=/usr/bin/prometheus-node-exporter --collector.textfile.directory=< YOUR NODE FULL PATH >/poolStat/ --collector.textfile

Step 7 - Change Default User for prometheus-node-exporter.service

hange the default user to your Linux user name in prometheus-node-exporter.service. Replace below.

[Service]
User=<Linux User Name>

Or Alternatively: The default user of prometheus-node-exporter is “prometheus”. So, you could give the user “prometheus” read and write rights for poolStat.prom

Step 8 - Reload Daemon and Restart Services

Reload daemon and restart services by running:

sudo systemctl daemon-reload
sudo systemctl restart prometheus-node-exporter.service
sudo systemctl restart prometheus.service

Verify that the services are running properly:

sudo systemctl status grafana-server.service prometheus.service prometheus-node-exporter.service

Step 9 - Setup Cron Job to Update Data

The data will constantly change so we need to setup a cron job to grab the new data every so often. In this example we will grab new data every 6 hours.

First run:

crontab -e

Add the following to your cronjobs.

Replace "<YOUR NODE FULL PATH>" Hint: to find your full path run: find ~+ -type f -name getstats.sh

0 */6 * * * <YOUR NODE FULL PATH >/poolStat/getstats.sh

Step 10 - Display Data in Grafana

Now for your data source select Prometheus:

Now you should see all the "cexplorer_" Metrics

Some of the data you might want to display:

Remember amounts are given in lovelace so you need to divide by 1,000,000 to display in ADA

  1. Pledge = (cexplorer_pledge)/1000000

  2. Active Stake = (cexplorer_stake)/1000000

  3. Lifetime Blocks = cexplorer_blocks_lifetime

  4. Estimated Blocks per Epoch = cexplorer_blocks_est_epoch

  5. Lifetime ROA = cexplorer_roa_lifetime

  6. Current Number of Delegators = cexplorer_delegators

  7. Pool Rank = cexplorer_position

  8. Lifetime Luck = (cexplorer_luck_lifetime)*100

Congratulations you did it!

Contributors

Thanks to the following pools for helping to put together these guides. Please consider delegating to their pools to support them. Are you a pool? Consider buying them a coffee

Last updated