Add data from Cexplorer.io to your public dashboard (v2)
Tested on Ubutnu 20.04, Grafana 9.1.1, Pormetheus 2.15.2
Inspired by BUFFY page
https://crypto2099.io/adding-pool-stats-to-grafana-dashboard/

Prerequisites
  • Grafana installed and running
  • Prometheus installed and running as service
  • Prometheus-node-exporter installed and running as service
  1. Copy the JSON link from cexplorer.io



  2. Prometheus can only use numeric data, so we must first trim the JSON file.
    cd /$NODE_HOME or < YOUR NODE FULL PATH >
    mkdir -p cexplorer
    cd cexplorer
    echo "curl https://https://js.cexplorer.io/api-static/pool/pool< YOUR POOL ID >.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_/' > cexplorer.prom" > getstats.sh
    chmod +x getstats.sh
    ./getstats.sh

  3. Look at cexplorer.prom content
    nano cexplorer.prom
    You should have something like...
    cexplorer_lvlup_stake 655823108193
    cexplorer_lvlup_stake_active 653982951884
    cexplorer_lvlup_tax_ratio 0
    cexplorer_lvlup_tax_fix 340000000
    cexplorer_lvlup_blocks_epoch 0
    cexplorer_lvlup_blocks_lifetime 95
    cexplorer_lvlup_roa_short 4.544
    ...


  4. Configure promethues-node-exporter.service to grab data from cexplorer.io file. Note that you can run getstats.sh on any other server running node-exporter, you don't have to do it on same server running prometheus.service.
    sudo cp /lib/systemd/system/prometheus-node-exporter.service /lib/systemd/system/prometheus-node-exporter.service_backup
    sudo nano /lib/systemd/system/prometheus-node-exporter.service
    Change ExecStart line for
    ExecStart=/usr/bin/prometheus-node-exporter --collector.textfile.directory=< YOUR NODE FULL PATH >/cexplorer --collector.textfile
    Reload daemon and restart services
    sudo systemctl daemon-reload
    sudo systemctl restart prometheus-node-exporter.service
    sudo systemctl restart prometheus.service

  5. Assuming Grafana and Prometheus are active and running, you can now add data coming directly from ADApools to your public dashboard. Let's add the active stake.
    1. Add a new panel.

    2. From Prometheus datasource, select Metrics, cexplorer, cexplorer_total_stake.
    3. Data from the pledge, active_stake and total_stake are lovelaces, you must divide by 1 000 000 to get ADA.
    4. Add a title to your panel, choose visualization template and don't forget to tick Instant if you don't want the graph.
    5. Set thresholds to change color.
    6. Save and that's it.

  6. Set cron job to update data from Cexplorer.io everyday.
    crontab -e
    Add those lines
    #Get data from cexplorer.io every day at 00:00
    0 0 * * * cd < YOUR NODE FULL PATH >/cexplorer/ && ./getstats.sh

  7. Now, you can create any panel you want with all data from Cexplorer.io.
    * *
    *Would like to...but not my data.



@ Level Up! 2022