Skip to content

Latest commit

 

History

History
128 lines (90 loc) · 3.97 KB

install_bridge_metrics.md

File metadata and controls

128 lines (90 loc) · 3.97 KB

Implementation and Configuration of Custom Metrics Monitoring

Introduction

Node Exporter is a Prometheus tool that collects operating system and server hardware metrics. However, it can also be used to expose custom metrics.

Prerequisites:

  • Install node_exporter on your server

Step 1: Prepare the environment

Create a metrics directory to store metrics scripts.

sudo mkdir -p /usr/local/metrics

Download the metrics script info_bridge.sh

This is a bash script that extracts the desired metrics from the bridge node and sends them to Prometheus. The script is not intrusive it just executes a series of CLI commands and sends the metrics to node_exporter_metrics.prom file, these metrics will be picked up by node_exporter to expose them in Prometheus.

sudo wget https://raw.githubusercontent.com/Cumulo-pro/Celestia-monitoring/main/bridge-monitor/info_bridge.sh -O /usr/local/metrics/get_bridge_height.sh

Provides the necessary permissions to the script

sudo chmod +x /usr/local/metrics/get_bridge_height.sh

Step 2: Setting up the Node Exporter service

Edit the Node Exporter service file (already installed and running on your server): /etc/systemd/system/node_exporter.service, and add the option --collector.textfile.directory to specify the directory where the metrics generated by the script will be stored:

sudo sed -i 's|ExecStart=/usr/local/bin/node_exporter.*|ExecStart=/usr/local/bin/node_exporter --collector.textfile.directory=/usr/local/metrics|' /etc/systemd/system/node_exporter.service

image

Reload systemd: Once the file has been saved, reload the systemd daemon so that it recognises the changes:

sudo systemctl daemon-reload

Restart the service:

sudo systemctl restart node_exporter

Provides the necessary permissions for node_exporter:

sudo chown -R node_exporter:node_exporter /usr/local/metrics
sudo chmod -R 755 /usr/local/metrics

Step 3: Service and Timer Configuration

Create a service file and timer to run the script periodically /etc/systemd/system/update_bridge_metrics.service:

sudo tee /etc/systemd/system/update_bridge_metrics.service > /dev/null << EOF
[Unit]
Description=Bridge metrics update
After=network.target

[Service]
Type=oneshot
ExecStart=/usr/local/metrics/get_bridge_height.sh

[Install]
WantedBy=multi-user.target
EOF

Enable and start services:

sudo systemctl daemon-reload
sudo systemctl enable update_bridge_metrics.service
sudo systemctl start update_bridge_metrics.service

Create the timer /etc/systemd/system/update_bridge_metrics.timer:

sudo tee /etc/systemd/system/update_bridge_metrics.timer > /dev/null << EOF
[Unit]
Description=Temporizador para la actualización de métricas del puente

[Timer]
OnUnitActiveSec=6s
Persistent=true

[Install]
WantedBy=timers.target
EOF

Enable and start services:

sudo systemctl daemon-reload
sudo systemctl enable --now update_bridge_metrics.timer

Step 4: Verification

Check that the Node Exporter, update_bridge_metrics and the timer are working correctly:

sudo systemctl status node_exporter
sudo systemctl status update_bridge_metrics.service
sudo systemctl status update_bridge_metrics.timer

Verify that the metrics are being collected correctly by accessing the Node Exporter URL:

curl http://localhost:9100/metrics | grep bridge_height

image


That's all, now install Dashboar on your Grafana to be able to visualise the metrics.