Gateway Watchdog
by @guoqunabc
Monitor OpenClaw Gateway health by detecting abnormal error rates in logs. Use when: (1) setting up Gateway error monitoring, (2) diagnosing repeated API fai...
clawhub install gateway-watchdog๐ About This Skill
name: gateway-watchdog description: "Monitor OpenClaw Gateway health by detecting abnormal error rates in logs. Use when: (1) setting up Gateway error monitoring, (2) diagnosing repeated API failures (429, quota, timeouts), (3) user asks about Gateway health or error trends, (4) integrating error detection into heartbeat checks. Detects rate-limiting, server errors, auth failures, network errors, and message delivery failures across all channels."
Gateway Watchdog
Detect abnormal error patterns in the OpenClaw Gateway before they cause damage. Works with all channels: Telegram, WhatsApp, Discord, Slack, Signal, iMessage, Feishu, and more.
Born from a real incident: a silent try-catch caused 76,744 failed retries in 8 hours โ undetected until the API quota was exhausted.
What It Detects
| Category | Patterns |
|----------|----------|
| Rate limiting | HTTP 429, rate.limit, too many requests |
| Server errors | HTTP 5xx status codes |
| Auth/permission | HTTP 401/403, unauthorized, forbidden, token expired |
| Network errors | ETIMEDOUT, ECONNREFUSED, ECONNRESET, ENOTFOUND, socket hang up |
| Delivery failures | sendMessage failed, deliver failed, fetch failed |
| Custom | User-defined via WATCHDOG_EXTRA_PATTERNS env var |
Smart Analysis
Quick Start
bash scripts/gateway-watchdog.sh check # silent unless errors exceed threshold
bash scripts/gateway-watchdog.sh verbose # always outputs full report
bash scripts/gateway-watchdog.sh history # show monitoring history
bash scripts/gateway-watchdog.sh trend # last 24h error trend
Heartbeat integration
Add to HEARTBEAT.md:
## Gateway Error Monitoring (every heartbeat)
Run ~/.openclaw/workspace/skills/gateway-watchdog/scripts/gateway-watchdog.sh check
If output is non-empty, report to user immediately
No output = healthy, skip reporting
Cron (optional)
openclaw cron add \
--name "gateway-watchdog" \
--schedule "*/30 * * * *" \
--task "Run gateway-watchdog.sh verbose. If errors detected, notify user with the report." \
--channel last
Configuration
All via environment variables:
| Variable | Default | Description |
|----------|---------|-------------|
| WATCHDOG_THRESHOLD | 30 | Error count that triggers alert |
| WATCHDOG_WINDOW | 30 | Monitoring window in minutes |
| WATCHDOG_SPIKE_RATIO | 3 | Alert when errors jump Nx vs last check |
| WATCHDOG_EXTRA_PATTERNS | _(empty)_ | Custom regex patterns (e.g., 99991400\|99991403) |
| WATCHDOG_STATE | ~/.local/state/gateway-watchdog/state.json | State file |
| WATCHDOG_LOG | ~/.local/state/gateway-watchdog/history.log | History log |
Adding channel-specific patterns
# Feishu-specific error codes
export WATCHDOG_EXTRA_PATTERNS='99991400|99991403|99991404|99991429'Telegram-specific
export WATCHDOG_EXTRA_PATTERNS='Too Many Requests|FLOOD_WAIT|bot was blocked'Discord-specific
export WATCHDOG_EXTRA_PATTERNS='DiscordAPIError|Missing Permissions|Unknown Channel'
Interpreting Results
๐ด Alert (Chinese locale)
๐ด Gateway ๆ่ฟ 30 ๅ้ๅบ็ฐ 150 ๆกๅผๅธธ้่ฏฏ๏ผ้ๅผ: 30๏ผ5/min๏ผ
๐ ้่ฏฏ็ชๅข: 12 โ 150๏ผ3ๅ้ๅผ่งฆๅ๏ผ้่ฏฏๅ็ฑป๏ผ
429/้ๆต: 120
5xxๆๅก็ซฏ้่ฏฏ: 5
่ฎค่ฏ/ๆ้: 0
็ฝ็ป้่ฏฏ: 5
ๆถๆฏๆ้ๅคฑ่ดฅ: 20
โ ๏ธ ๅไธ้่ฏฏ็ฑปๅใ429/้ๆตใๅ ๆฏ 80%๏ผๅฏ่ฝๆฏๅไธๆ
้ๆบ
๐ด Alert (English equivalent)
๐ด Gateway detected 150 errors in the last 30 min (threshold: 30, 5/min)
๐ Error spike: 12 โ 150 (3x threshold triggered)Error breakdown:
429/Rate-limit: 120
5xx Server errors: 5
Auth/Permission: 0
Network errors: 5
Delivery failures: 20
โ ๏ธ Single error type "429/Rate-limit" accounts for 80%+ โ likely a single fault source
๐ Healthy
No output fromcheck mode.Limitations
~/.openclaw/logs/ on macOS)Security
~/.local/state/gateway-watchdog/ (XDG standard, no elevated permissions needed)๐ก Examples
bash scripts/gateway-watchdog.sh check # silent unless errors exceed threshold
bash scripts/gateway-watchdog.sh verbose # always outputs full report
bash scripts/gateway-watchdog.sh history # show monitoring history
bash scripts/gateway-watchdog.sh trend # last 24h error trend
Heartbeat integration
Add to HEARTBEAT.md:
```markdown
โ๏ธ Configuration
All via environment variables:
| Variable | Default | Description |
|----------|---------|-------------|
| WATCHDOG_THRESHOLD | 30 | Error count that triggers alert |
| WATCHDOG_WINDOW | 30 | Monitoring window in minutes |
| WATCHDOG_SPIKE_RATIO | 3 | Alert when errors jump Nx vs last check |
| WATCHDOG_EXTRA_PATTERNS | _(empty)_ | Custom regex patterns (e.g., 99991400\|99991403) |
| WATCHDOG_STATE | ~/.local/state/gateway-watchdog/state.json | State file |
| WATCHDOG_LOG | ~/.local/state/gateway-watchdog/history.log | History log |
Adding channel-specific patterns
# Feishu-specific error codes
export WATCHDOG_EXTRA_PATTERNS='99991400|99991403|99991404|99991429'Telegram-specific
export WATCHDOG_EXTRA_PATTERNS='Too Many Requests|FLOOD_WAIT|bot was blocked'Discord-specific
export WATCHDOG_EXTRA_PATTERNS='DiscordAPIError|Missing Permissions|Unknown Channel'