> For the complete documentation index, see [llms.txt](https://ecp.gitbook.io/how-to-guides-for-coincashew-method-cardano-spos/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ecp.gitbook.io/how-to-guides-for-coincashew-method-cardano-spos/maintenance-and-daily-operations/how-to-guides-for-spos-using-coincashew-method/how-to-add-pool-data-from-cexplorer-to-your-grafana-dashboard.md).

# 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](https://cexplorer.io/) to your Grafana dashboard.

{% hint style="info" %}
Credits to <img src="https://earncoinpool.com/images/coin_v3.png" alt="" data-size="line"> [Earn Coin Pool](https://earncoinpool.com/) for documenting the procedure.<br>

Also credit to [sanskys](https://sanskys.github.io/grafana/) for documenting original procedure for adapools
{% endhint %}

***

## Step 1 - Get API Key from Cexplorer

Go to <https://cexplorer.io/api> and select a plan

<figure><img src="/files/IGgsGkTux4Ivxu9flpEk" alt=""><figcaption></figcaption></figure>

***

## Step 2 - Copy API Key

Once you have selected a plan we can now copy our API Key

<figure><img src="/files/qL24Agn5pM0hAlx75Oyz" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
📝 Copy this to a save place as we will need it later.
{% endhint %}

### Copy Pool ID

If you don't know your pool id off the top of your head copy it from [Cexploer.io](https://cexplorer.io/) while you are on their site.

<figure><img src="/files/Uvd76AlIRNEPjHS3QdZ9" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
📝 Copy this to a save place as we will need it later.
{% endhint %}

***

## Step 3 - Create poolStat Directory

Create poolStat directory by running the following commands:

```
cd $NODE_HOME
mkdir -p poolStat
```

***

## Step 4 -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.

```
cd $NODE_HOME/poolStat
sudo nano getstats.sh
```

{% hint style="warning" %}
Replace "YOUR\_SECRET\_TOKEN" with the Key that you copied from [Step 2](#step-2-copy-api-key)\
\
Also replace "YOUR\_POOL\_ID" with your pool id from [Step 2](#step-2-copy-api-key)\
\
Replace ${NODE\_HOME} with full path
{% endhint %}

```
#!/bin/bash
set -euo pipefail

API_KEY="YOUR_SECRET_TOKEN"
POOL_ID="YOUR_POOL_ID"

API_URL="https://api-mainnet-stage.cexplorer.io/v1/pool/detail?pool_id=${POOL_ID}"

OUTPUT_FILE="${NODE_HOME}/poolStat/poolStat.prom"

# Fetch JSON
response=$(curl -s -H "api-key: ${API_KEY}" "$API_URL")

# Extract values
live_stake=$(echo "$response" | jq -r '.data.live_stake')
active_stake=$(echo "$response" | jq -r '.data.active_stake')
delegators=$(echo "$response" | jq -r '.data.delegators')
pledged=$(echo "$response" | jq -r '.data.pledged')
saturation=$(echo "$response" | jq -r '.data.saturation')
blocks_epoch=$(echo "$response" | jq -r '.data.blocks.epoch')
blocks_total=$(echo "$response" | jq -r '.data.blocks.total')
lifetime_roa=$(echo "$response" | jq -r '.data.stats.lifetime.roa')
lifetime_luck=$(echo "$response" | jq -r '.data.stats.lifetime.luck')
recent_roa=$(echo "$response" | jq -r '.data.stats.recent.roa')
recent_luck=$(echo "$response" | jq -r '.data.stats.recent.luck')
last_block_time=$(echo "$response" | jq -r '.data.last_block.time')
last_block_proto=$(echo "$response" | jq -r '.data.last_block.proto')
last_block_slot_number=$(echo "$response" | jq -r '.data.last_block.slot_no')
last_block_epoch_number=$(echo "$response" | jq -r '.data.last_block.epoch_no')

# Convert lovelace to ADA
active_stake_ada=$(echo "$active_stake / 1000000" | bc -l)
live_stake_ada=$(echo "$live_stake / 1000000" | bc -l)
pledged_ada=$(echo "$pledged / 1000000" | bc -l)

# Convert ISO → epoch milliseconds
if [[ -n "$last_block_time" ]]; then
  last_block_time_ms=$(($(date -d "$last_block_time" +%s) * 1000))
else
  last_block_time_ms=0
fi

# Write Prometheus metrics file
cat <<EOF > "${OUTPUT_FILE}"
# HELP cexplorer_active_stake_ada - Active stake in ADA
cexplorer_active_stake_ada ${active_stake_ada}

# HELP cexplorer_live_stake_ada - Live stake in ADA
cexplorer_live_stake_ada ${live_stake_ada}

# HELP cexplorer_delegators - Number of delegators
cexplorer_delegators ${delegators}

# HELP cexplorer_pledge - Pool Pledge in ADA
cexplorer_pledge_ada ${pledged_ada}

# HELP cexplorer_saturation - Pool Saturation
cexplorer_saturation ${saturation}

# HELP cexplorer_blocks_epoch - Blocks minted in current epoch
cexplorer_blocks_epoch ${blocks_epoch}

# HELP cexplorer_blocks_total - Total blocks minted lifetime
cexplorer_blocks_total ${blocks_total}

# HELP cexplorer_lifetime_roa - Lifetime ROA percentage
cexplorer_lifetime_roa ${lifetime_roa}

# HELP cexplorer_lifetime_luck - Lifetime Luck percentage
cexplorer_lifetime_luck ${lifetime_luck}

# HELP cexplorer_recent_roa - Recent epoch ROA percentage
cexplorer_recent_roa ${recent_roa}

# HELP cexplorer_recent_luck - Recent epoch Luck percentage
cexplorer_recent_luck ${recent_luck}

# HELP cexplorer_last_block_time_ms - Last Block time
cexplorer_last_block_time_ms ${last_block_time_ms}

# HELP cexplorer_last_block_proto - Last Block Protocol
cexplorer_last_block_proto ${last_block_proto}

# HELP cexplorer_last_block_slot_number - Last Block Slot Number
cexplorer_last_block_slot_number ${last_block_slot_number}

# HELP cexplorer_last_block_epoch_number - Last Block Epoch Number
cexplorer_last_block_epoch_number ${last_block_epoch_number}
EOF
```

***

## Step 5 - Add Permissions and Run the getstat Script

Add permissions and run getstat script by running these commands:

```
chmod +x getstats.sh
```

```
./getstats.sh
```

***

## Step 6 - Check Output File&#x20;

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:
>
> ```
> # HELP cexplorer_active_stake_ada - Active stake in ADA
> cexplorer_active_stake_ada 807189.69016300000000000000
>
> # HELP cexplorer_live_stake_ada - Live stake in ADA
> cexplorer_live_stake_ada 847049.41978400000000000000
>
> # HELP cexplorer_delegators - Number of delegators
> cexplorer_delegators 65
>
> # HELP cexplorer_pledge - Pool Pledge in ADA
> cexplorer_pledge_ada 113027.96825000000000000000
>
> # HELP cexplorer_saturation - Pool Saturation
> cexplorer_saturation 0.011
>
> # HELP cexplorer_blocks_epoch - Blocks minted in current epoch
> cexplorer_blocks_epoch 0
>
> # HELP cexplorer_blocks_total - Total blocks minted lifetime
> cexplorer_blocks_total 242
>
> # HELP cexplorer_lifetime_roa - Lifetime ROA percentage
> cexplorer_lifetime_roa 1.95399410812197
>
> # HELP cexplorer_lifetime_luck - Lifetime Luck percentage
> cexplorer_lifetime_luck 0.9997108660683562
>
> # HELP cexplorer_recent_roa - Recent epoch ROA percentage
> cexplorer_recent_roa 1.309502264533149
>
> # HELP cexplorer_recent_luck - Recent epoch Luck percentage
> cexplorer_recent_luck 1.1085345058639466
>
> # HELP cexplorer_last_block_time_ms - Last Block time
> cexplorer_last_block_time_ms 1771643550000
>
> # HELP cexplorer_last_block_proto - Last Block Protocol
> cexplorer_last_block_proto 10.6
>
> # HELP cexplorer_last_block_slot_number - Last Block Slot Number
> cexplorer_last_block_slot_number 180077259
>
> # HELP cexplorer_last_block_epoch_number - Last Block Epoch Number
> cexplorer_last_block_epoch_number 614
>
> ```

***

## Step 7 - 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:

{% hint style="warning" %}
Replace "< YOUR NODE FULL PATH >"\
\
Hint: to find your full path run:

cd $NODE\_HOME

readlink -f poolStat
{% endhint %}

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

***

## Step 8 - 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>
```

{% hint style="info" %}
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
{% endhint %}

***

## Step 9 - 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 10 - 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.&#x20;

{% hint style="warning" %}
Replace "\<YOUR NODE FULL PATH>"\
\
Hint: to find your full path run:\
find \~+ -type f -name getstats.sh
{% endhint %}

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

***

## Step 11 - Display Data in Grafana&#x20;

Now for your data source select Prometheus:

<figure><img src="/files/9OTALh2Qc1SapRtOJTtl" alt=""><figcaption><p><strong>Select Prometheus for Data source</strong></p></figcaption></figure>

Now you should see all the "cexplorer" Metrics

<figure><img src="/files/BojlDxuaJuffjnVHeOXJ" alt=""><figcaption></figcaption></figure>

**Some of the data you might want to display:**<br>

1. Active stake in ADA = cexplorer\_active\_stake\_ada
2. Live stake in ADA = cexplorer\_live\_stake\_ada
3. Number of Delegators = cexplorer\_delegators
4. Pool Pledge in ADA = cexplorer\_pledge\_ada
5. Pool Saturation = cexplorer\_saturation
6. Blocks in Current Epoch = cexplorer\_blocks\_epoch
7. Lifetime Blocks = cexplorer\_blocks\_total
8. Lifetime ROA = cexplorer\_lifetime\_roa
9. Lifetime Luck Percentage = cexplorer\_lifetime\_luck
10. Recent ROA = cexplorer\_recent\_roa
11. Recent Luck Percentage = cexplorer\_recent\_luck
12. Last Block Time = cexplorer\_last\_block\_time\_ms
13. Last Block Protocol = cexplorer\_last\_block\_proto
14. Last Block Slot Number = cexplorer\_last\_block\_slot\_number
15. Last Block Epoch Number = cexplorer\_last\_block\_epoch\_number

***

## Congratulations you did it!

***

## Contributors&#x20;

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

![](https://img.cexplorer.io/7/e/1/9/f/pool16cdtqyk0fvxzfkhjg3esjcuty4tnlpds5lj0lkmqmwdjyzaj7p8.png)  [Earn Coin Pool - Ticker: ECP](https://cexplorer.io/pool/pool16cdtqyk0fvxzfkhjg3esjcuty4tnlpds5lj0lkmqmwdjyzaj7p8)

![xSPO Alliance Logo](/files/6U364TnLAtmyWJIEdO8v) [xSPO Alliance](http://xspo-alliance.org/discord)
