LogoLogo
  • Welcome
  • Explorers
    • Aptos Explorer
    • Cosmos Explorer
  • Blockchains
    • Aptos
      • Run a Validator and VFN
        • Operator
        • Node Requirements
        • Deploy Nodes
          • Using Source Code
        • Connect Nodes
          • Connect to a Network
          • Staking Pool Operations
          • Delegation Pool Operations
          • Staking Pool Voter
        • Verify Nodes
          • Node Health
          • Validator Leaderboard
        • Modify Nodes
          • Upgrade Nodes
          • Shutdown Nodes
      • Run a Public Fullnode
        • PFN Requirements
        • Deploy a PFN
          • Deploy a PFN using Source Code
        • Verify a PFN
        • Modify a PFN
          • Customize PFN Networks
          • Generate a PFN Identity
          • Upgrade your PFN
          • Run a PFN from Source Code
      • Bootstrap a Node with historical data
        • Bootstrap from a Backup
        • Bootstrap from a Snapshot
      • Configure a Node
        • State Synchronization
        • Data Pruning
        • Telemetry
        • Locating Node Files
          • Files For Mainnet
          • Files For Testnet
          • Files For Devnet
      • Monitor your Nodes
        • Important Node Metrics
        • Node Health Checker
        • Node Health Checker FAQ
        • Node Inspection Service
      • Building Aptos From Source
      • Aptos Networks
    • Berachain V2
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • gRPC Endpoint
      • Live Peers
      • Forest Staking Peer
      • Performance Optimizer Script
      • Discord & TG Alert System
      • RPC Load Balancer Setup
    • Casper
      • Explorer
    • Haqq
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • Live Peers
      • Forest Staking Peer
    • Mantra
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • Live Peers
      • Forest Staking Peer
    • Ika
    • Story Protocol
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • EVM Endpoint
      • Websocket
      • WSS
      • Discord & TG Alert System
      • RPC Load Balancer
      • Performance Optimizer Script
      • Live Peers
      • Forest Staking Peer
    • Supra
      • Explorer
      • Oracle data
    • Showdown
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • Live Peers
      • Forest Staking Peer
    • Soarchain
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • Live Peers
      • Forest Staking Peer
    • Zenrock
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • Live Peers
      • Forest Staking Peer
    • Zetachain
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • Live Peers
      • Forest Staking Peer
    • Airchains
      • Node Snapshot
      • Explorer
  • Gunzilla - Off The Grid
    • Vision and Foundation
    • Gunzilla Hacker Dashboard
      • Key Features of the Hackers Dashboard
        • Wallet Integration and Testnet Access
        • License System with Rarity Tiers
        • Decoding Stats and Hash Power Tracking
        • Marketplace for Trading Licenses and Assets
        • Scanner Tool for Blockchain Transparency
        • Social Media Integration and Community Engagement
      • Mastering the Hackers Dashboard
      • Benefits of the Hackers Dashboard
    • Gunzilla Token Page
  • Forest Esports Team
    • Forest Hexers
  • Crypto Tools & Analytics
    • Top 10 Crypto Exchanges
      • Binance
      • Coinbase
      • Kraken
      • Bybit
      • OKX
      • KuCoin
      • Bitfinex
      • Gemini
      • Crypto.com
      • Bitstamp
    • Top 10 Wallets
      • Ledger Nano X
      • Trezor Model T
      • Exodus
      • Coinbase Wallet
      • Trust Wallet
      • MetaMask
      • Crypto.com DeFi Wallet
      • ZenGo
      • Atomic Wallet
      • SafePal
  • Top 10 Crypto Data Platforms
    • CoinMarketCap
    • CoinGecko
    • CryptoCompare
    • CoinCodex
    • Live Coin Watch
    • CoinCheckup
    • Messari
    • CoinPaprika
    • Arkham Intelligence
  • DeFi Analytics and Tracking
    • DefiLlama
    • Dune Analytics
    • DeBank
    • Zapper
    • Token Terminal
    • DeepDAO
    • Revert Finance
    • L2BEAT
  • API's
    • What are APIs?
    • How APIs Work
    • Types of APIs
    • Real-World API Use Cases
    • Benefits of Using API's
    • Challenges and Considerations of using API's
  • Node Security
    • Physical Security
    • Network Security
    • System and Software Security
    • Access Control
    • Data Security
    • Monitoring and Logging
    • Backup and Disaster Recovery
    • Best Practices for Validator Nodes
    • Cloud Security
    • Incident Response and Recovery
  • Linux Bash
    • Bash 101
      • Getting Started with Bash
      • Navigating the File System
      • File Management Basics
      • Viewing and Editing Files
      • Managing Permissions
      • Working with Processes
      • Using Pipes and Redirection
      • Bash Scripting Basics
      • Essential Networking Commands
      • Installing Software with Package Managers
    • Advanced Linux for Validator Nodes
      • Advanced Bash Scripting for Node Automation and Maintenance
      • Monitoring and Logging Essentials
      • Networking and Security Best Practices
      • Backup and Disaster Recovery
  • Staking 101
    • Understand What Staking Is and How It Works
    • Choose a Blockchain Network to Stake On
    • Set Up a Compatible Wallet for Staking
    • Purchase or Transfer Funds for Staking
    • Choose a Staking Pool
    • Connect Your Wallet to a Staking Platform
    • Confirm and Stake Your Funds
    • Monitor Staking Rewards and Performance
    • Withdraw or Re-Stake Rewards
  • Optimizing Your Infrastructure Choices
    • Infrastructure Comparison: VPS vs. Bare Metal
Powered by GitBook
On this page
  • Validator Monitoring Bot for Story Protocol
  • Step 1: Install Required Python Libraries
  • Step 2: Create the Validator Monitoring Script
  • Step 3: Configure Prometheus
  • Step 4: Running the Monitoring Bot
  • Step 5: Extend to Telegram (Optional)
  • Conclusion

Was this helpful?

  1. Blockchains
  2. Story Protocol

Discord & TG Alert System

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

Validator Monitoring Bot for Story Protocol

Introduction

This guide walks you through creating a Validator Monitoring Bot to track key metrics of your Story Protocol 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 (extendable to Telegram).

Prerequisites

Before starting, ensure the following are installed and configured:

  • Python 3.6+ installed.

  • Prometheus running and scraping your validator node metrics.

  • Discord bot created and token available.

  • 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.

bashCopy codepip install requests prometheus_client discord.py

Step 2: Create the Validator Monitoring Script

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

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

pythonCopy codeimport requests
import discord
from discord.ext import commands, tasks

# Discord bot setup
TOKEN = 'YOUR_DISCORD_BOT_TOKEN'
CHANNEL_ID = YOUR_DISCORD_CHANNEL_ID  # Replace with your Discord channel ID

client = commands.Bot(command_prefix='!')

# Prometheus API URL
PROMETHEUS_URL = 'http://localhost:9090/api/v1/query'

# Monitoring thresholds
MISSED_BLOCKS_THRESHOLD = 5
CPU_USAGE_THRESHOLD = 80

# Function to get Prometheus metrics
def get_prometheus_metric(query):
    try:
        response = requests.get(f'{PROMETHEUS_URL}?query={query}')
        results = response.json()['data']['result']
        return float(results[0]['value'][1]) if results else None
    except Exception as e:
        print(f"Error fetching Prometheus metrics: {e}")
        return None

# Task to monitor missed blocks and CPU usage
@tasks.loop(seconds=60)  # Run every 60 seconds
async def monitor_validator():
    missed_blocks = get_prometheus_metric('storyprotocol_missed_blocks')
    cpu_usage = get_prometheus_metric('rate(node_cpu_seconds_total{mode="system"}[5m]) * 100')
    
    channel = client.get_channel(CHANNEL_ID)

    if missed_blocks and missed_blocks > MISSED_BLOCKS_THRESHOLD:
        await channel.send(f"🚨 Alert! Missed blocks detected: {missed_blocks} blocks missed!")
    
    if cpu_usage and cpu_usage > CPU_USAGE_THRESHOLD:
        await channel.send(f"⚠️ Warning! High CPU usage detected: {cpu_usage}%")

# Discord bot events
@client.event
async def on_ready():
    print(f'Logged in as {client.user}')
    monitor_validator.start()

# Run the bot
client.run(TOKEN)

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.

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


Step 3: Configure Prometheus

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

yamlCopy codescrape_configs:
  - job_name: 'storyprotocol_validator'
    static_configs:
      - targets: ['localhost:26660']  # Replace with your Story Protocol node metrics endpoint
  - job_name: 'node_exporter'
    static_configs:
      - targets: ['localhost:9100']   # Node Exporter endpoint for system metrics

Step 4: Running the Monitoring Bot

Once everything is set up, run the Python script:

bashCopy codepython3 validator_monitor.py

You should see messages in your terminal indicating that the bot is active. If any thresholds (missed blocks or high CPU) are breached, an alert will be sent to your specified Discord channel.


Step 5: Extend to Telegram (Optional)

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

bashCopy codepip install python-telegram-bot

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


Conclusion

With this Validator Monitoring Bot, you can monitor the health of your Story Protocol validator and get real-time alerts about any critical issues. This lightweight, customizable solution can be expanded to include more metrics or additional 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 Story Protocol validator node, ensuring you’re always aware of critical issues in real-time.

PreviousWSSNextRPC Load Balancer

Last updated 6 months ago

Was this helpful?