Discord & TG Alert System

This Validator Monitoring Bot integrates with Prometheus to monitor the key metrics of your Berachain validator. This bot can automatically alert you via Discord or Telegram when there are issues.

Validator Monitoring Bot for Berachain

Introduction

This guide walks you through creating a Validator Monitoring Bot to track key metrics of your Berachain validator node using Prometheus and sending alerts via Discord. The bot monitors metrics such as missed blocks and CPU usage, ensuring you are notified when performance issues arise.

Features:

  • Real-time monitoring of validator performance.

  • Alerts for missed blocks and high CPU usage.

  • Configurable thresholds for warnings.

  • Notifications sent via Discord (can extend to Telegram).


Prerequisites

Before starting, ensure the following are installed and configured:

  1. Python 3.6+ installed.

  2. Prometheus running and scraping your validator node metrics.

  3. Discord bot created and token available.

  4. Optional: Node Exporter for monitoring system metrics like CPU usage.


Step 1: Install Required Python Libraries

First, install the necessary Python libraries to interact with Prometheus and Discord.


Step 2: Create the Validator Monitoring Script

Next, create a Python script that will query Prometheus for key metrics and send alerts to a Discord channel when certain thresholds are breached.

Create a file named validator_monitor.py and add the following code:

Explanation:

  • TOKEN: Replace with your Discord bot token.

  • CHANNEL_ID: Replace with your Discord channel ID where alerts will be sent.

  • Prometheus Queries: The script queries Prometheus for missed blocks and CPU usage metrics.

  • Thresholds: Alerts are triggered when missed blocks exceed MISSED_BLOCKS_THRESHOLD or CPU usage exceeds CPU_USAGE_THRESHOLD.


Step 3: Configure Prometheus

Ensure that Prometheus is scraping the required metrics from your validator node. Here’s an example of what your prometheus.yml configuration should look like:


Step 4: Running the Monitoring Bot

Once everything is set up, run the Python script:

You should see messages printed in your terminal indicating that the bot is active. Any violations of the thresholds (missed blocks or high CPU) will trigger an alert in your specified Discord channel.


Step 5: Extend to Telegram (Optional)

If you prefer to use Telegram for alerts, you can modify the script to use the Telegram Bot API. Install the python-telegram-bot library:

Then replace the Discord-related code in the script with Telegram bot logic.


Conclusion

With this Validator Monitoring Bot, you can keep an eye on the health of your Berachain validator and get notified when any issues arise. This bot provides a lightweight, customizable solution that can be expanded to include more metrics or different notification channels.

Next Steps:

  • Add more metrics for monitoring (e.g., memory usage, disk space).

  • Implement auto-recovery scripts or alerts for multiple communication platforms.

  • Integrate with Grafana for advanced visual monitoring.


By following this guide, you'll have a basic monitoring solution for your Berachain validator node, ensuring you're always aware of any critical issues in real-time.

Last updated