Guides4 min read

Monitor Your Bot's Uptime 24/7

Set up comprehensive uptime monitoring for your AI chatbot. Get alerts when your bot goes down and track performance metrics.

Published: 27/01/2025

Why Monitor Your Bot?

Without monitoring, you won't know when your bot goes offline until users complain. Proper monitoring helps you:

  • Get instant alerts when the bot goes down
  • Track uptime percentage
  • Identify performance issues before they escalate
  • Maintain user trust with high availability

Monitoring Options

| Tool | Cost | Features | |------|------|----------| | UptimeRobot | Free | Basic HTTP monitoring | | BetterStack | Free tier | Logs + monitoring | | PM2 Plus | $14/mo | Process monitoring | | Self-hosted | Free | Full control |

Method 1: PM2 Built-in Monitoring

PM2 includes basic monitoring out of the box.

Real-time Dashboard

pm2 monit

This shows CPU, memory, and logs in real-time.

Process Status

pm2 status
pm2 list

Log Monitoring

pm2 logs your-bot --lines 100

Auto-restart on Crash

PM2 automatically restarts crashed processes. Configure limits:

pm2 start index.js --name your-bot --max-restarts 10 --restart-delay 5000

Method 2: UptimeRobot (Free)

UptimeRobot can monitor a health endpoint on your bot.

Step 1: Add Health Endpoint

Add to your bot code:

const http = require('http');

http.createServer((req, res) => {
  if (req.url === '/health') {
    res.writeHead(200);
    res.end('OK');
  }
}).listen(3001);

Step 2: Configure Firewall

sudo ufw allow 3001/tcp

Step 3: Set Up UptimeRobot

  1. Sign up at uptimerobot.com
  2. Click Add New Monitor
  3. Select HTTP(s)
  4. Enter: http://your-server-ip:3001/health
  5. Set check interval (5 minutes for free)
  6. Add alert contacts (email, Telegram, Discord webhook)

Method 3: BetterStack (Recommended)

BetterStack combines uptime monitoring with log management.

Setup

  1. Sign up at betterstack.com
  2. Create a new monitor
  3. Install the agent:
curl -fsSL https://logs.betterstack.com/setup/linux | sudo bash

Features

  • 30-second check intervals
  • Status pages
  • Incident management
  • Log aggregation

Method 4: Discord Webhook Alerts

Get alerts directly in Discord when your bot has issues.

Create Webhook

  1. In Discord, go to Server Settings → Integrations
  2. Click WebhooksNew Webhook
  3. Copy the webhook URL

PM2 Alert Script

Create /opt/scripts/alert.sh:

#!/bin/bash
WEBHOOK_URL="your-discord-webhook-url"

curl -H "Content-Type: application/json" \
  -d "{\"content\": \"⚠️ Bot Alert: $1\"}" \
  $WEBHOOK_URL

Make it executable:

chmod +x /opt/scripts/alert.sh

Integrate with PM2

pm2 set pm2:webhook:url "your-discord-webhook-url"

Method 5: Custom Health Checks

Create a comprehensive health check script:

#!/bin/bash
# /opt/scripts/health-check.sh

BOT_NAME="your-bot"
WEBHOOK_URL="your-discord-webhook-url"

# Check if PM2 process is running
if ! pm2 pid $BOT_NAME > /dev/null 2>&1; then
    curl -H "Content-Type: application/json" \
        -d '{"content": "🔴 Bot is DOWN! Attempting restart..."}' \
        $WEBHOOK_URL
    pm2 restart $BOT_NAME
    exit 1
fi

# Check memory usage
MEM=$(pm2 jlist | jq ".[] | select(.name==\"$BOT_NAME\") | .monit.memory")
MEM_MB=$((MEM / 1024 / 1024))

if [ $MEM_MB -gt 500 ]; then
    curl -H "Content-Type: application/json" \
        -d "{\"content\": \"⚠️ High memory usage: ${MEM_MB}MB\"}" \
        $WEBHOOK_URL
fi

echo "Health check passed"

Schedule with cron:

crontab -e
# Add:
*/5 * * * * /opt/scripts/health-check.sh

Setting Up Alerts

Email Alerts

Most monitoring services include email alerts. Configure:

  1. Primary email
  2. Backup email
  3. SMS for critical alerts (if available)

Discord Alerts

Use webhooks for instant Discord notifications:

# Example alert payload
{
  "embeds": [{
    "title": "Bot Status Alert",
    "description": "Your bot went offline",
    "color": 15158332,
    "timestamp": "2025-01-27T12:00:00Z"
  }]
}

Telegram Alerts

Create a Telegram bot for alerts:

  1. Message @BotFather to create a bot
  2. Get your chat ID
  3. Send alerts via API:
curl "https://api.telegram.org/bot<TOKEN>/sendMessage?chat_id=<CHAT_ID>&text=Bot%20is%20down!"

Dashboard Setup

PM2 Web Dashboard

pm2 install pm2-server-monit
pm2 web

Access at http://your-server:9615

Grafana Dashboard (Advanced)

For detailed metrics:

  1. Install Prometheus
  2. Add PM2 exporter
  3. Connect Grafana
  4. Import bot monitoring dashboard

Best Practices

  1. Multiple alert channels - Don't rely on just email
  2. Escalation policy - Alert phone if not acknowledged
  3. Check intervals - 1-5 minutes for production
  4. Log retention - Keep 7-30 days of logs
  5. Regular testing - Test alerts monthly

Related Guides

Managed Monitoring

Our maintenance plans include 24/7 monitoring with:

  • Instant alerts
  • Automatic restarts
  • Monthly uptime reports
  • UK-based support

Need a VPS for Your Bot?

We recommend Hostinger KVM 2 VPS - reliable, fast, and perfect for AI chatbots. Get started with our recommended setup.

Get Hostinger VPS

Need Help With Setup?

Got your VPS? Let us handle the technical work. Professional setup and maintenance for OpenClaw (formerly Clawd.bot).