Monitoring and alerting for a deployed Solana program and its services: which on-chain facts to alert on, which off-chain metrics to emit with thresholds, how to wire subscriptions and webhooks to an alert channel.
git clone https://github.com/solanabr/ai-kit.git--- name: monitoring description: "Monitoring and alerting for a deployed Solana program and its services: which on-chain facts to alert on, which off-chain metrics to emit with thresholds, how to wire subscriptions and webhooks to an alert channel." --- # Monitoring a deployed program What to watch after `/deploy`, with thresholds, and how to wire it. Generic observability (Prometheus, Grafana, on-call rotation) works as usual; this file is the Solana half. What to do when an alert is real: [deployment.md](deployment.md#incident-response). Auditor checklist [17-logging-monitoring-incident-response.md](ext/auditor-skill/checklists/17-logging-monitoring-incident-response.md) grades the result. Start by listing, per cluster, the program IDs (`.program-id-*` or `Anchor.toml`), each ProgramData address (`solana program show <PROGRAM_ID>`), the program's config, vault and pause accounts from the IDL, and every service and wallet that signs. ## On-chain facts that are alerts Each is an account subscription or a webhook filter, not an HTTP error. Page on the first group; ticket the rest. | Signal | Watch | Fire when | |---|---|---| | Program upgraded or authority changed | the ProgramData account (loader-v3), or the program account itself (loader-v4) | any change not matching a release you are executing | | Admin instruction invoked | transactions on the program filtered to admin instructions | any call outside a planned change | | Pause flag flipped | the config account's pause field | any change | | Vault balance outside its band | lamports or token amount of each program-owned vault | a move beyond N% of balance within M slots | | Invariant broken | e.g. total shares vs vault assets, mint supply vs recorded deposits (`getTokenSupply`) | any divergence beyond rounding | | Oracle stale | the price account's publish time or slot | age approaching the staleness bound the program enforces, before the program starts rejecting | | Authority keys used | mint, freeze, fee and multisig member keys | any transaction signed by them that you did not plan | ## Off-chain metrics to emit | Metric | Unit | Alert | |---|---|---| | Transaction land rate per service | landed / sent | below its 7-day baseline for 10+ minutes | | Attempts to land (resends until confirmed) | count, p50 / p95 | p95 rising while land rate falls: fees too low or RPC degraded | | Priority fee paid vs the recent-fee percentile you target | lamports | paying above a set cap for 30+ minutes | | Confirmed-but-not-finalized backlog | transactions | growing for 30+ minutes | | Indexer lag | slots (tip slot minus last processed slot) | above ~150 slots (about a minute) for 5+ minutes | | Fee payer and deployer balance | days of runway (balance / 7-day average daily spend) | under 7 days; page under 2 | | RPC error rate per provider | errors / requests | above 5% for 5 minutes, then fail over | | Slot lag between providers | slots behind the highest | above ~50 slots for 1 minute: take that provider out | Measure lag in slots, not seconds: skipped slots make wall-clock lag jump and recover on its own. Every threshold above takes a duration (`for:` in Prometheus), so one late sample doesn't page anyone. ## Wiring - Source: Helius webhooks on the program and vault addresses (managed, retried, no socket to keep open), `accountSubscribe` / `programSubscribe` over WebSocket for low volume, or Laserstream / Yellowstone gRPC at high volume ([helius skill](ext/helius/helius-skills/helius/SKILL.md); install first: `bash .claude/bin/skills.sh add helius`). Subscriptions drop silently, so the handler needs the heartbeat and backfill from [backend-async.md](backend-async.md#streams). - Handler: decode with the IDL, compare against the band or invariant, emit a metric and, for page-level signals, post to the alert channel directly as well, so an alert doesn't depend on the metrics stack. - Alerts land in a channel nobody mutes (PagerDuty, Opsgenie, or a dedicated Discord or Telegram channel with mentions). Say which one; it is the one manual step. - Check the monitor itself: a synthetic transaction every few minutes (a memo from a monitoring key) that must appear in the pipeline, and an alert when it doesn't. - After an upgrade, re-read the IDL the handler decodes with; a layout change silently breaks decoding.
[{"step":"Define your monitoring scope. Replace [SOLANA_PROGRAM_NAME], [PROGRAM_ADDRESS], and [LIST_OF_ON_CHAIN_EVENTS] with your program's specifics. For example, if you're monitoring a staking program, include events like 'stake delegation', 'reward claim failures', and 'slashing events'.","tip":"Use Solana Explorer (https://explorer.solana.com) or Solscan (https://solscan.io) to identify critical on-chain events for your program. Focus on events that directly impact user funds or program integrity."},{"step":"Set up off-chain metrics and thresholds. Replace [LIST_OF_METRICS] with relevant metrics for your services (e.g., API response time, queue depth, error rates). Use tools like Prometheus (https://prometheus.io) for metrics collection and Grafana (https://grafana.com) for visualization.","tip":"Start with conservative thresholds and adjust based on historical data. For example, set API latency alerts at the 95th percentile of normal traffic, not the absolute maximum."},{"step":"Configure alert channels. Replace [ALERT_CHANNEL] with your preferred notification method (e.g., Slack, Discord, PagerDuty, email). Use webhook integrations for real-time alerts. For Slack, go to `Settings > Integrations > Incoming WebHooks` to create a new webhook URL.","tip":"Test your webhook configuration by sending a test alert. In Slack, use `/webhook-test` in the channel where the webhook is configured."},{"step":"Deploy monitoring and validate alerts. Use a staging environment to test your monitoring setup before deploying to production. Simulate failures (e.g., by sending malformed transactions) to ensure alerts trigger correctly.","tip":"Use tools like `solana-test-validator` for local testing or a devnet program for staging. Monitor logs in real-time using `solana logs --url devnet` to verify event detection."},{"step":"Iterate and refine. Review alert frequency and severity over time. Adjust thresholds based on false positives/negatives. Use incident reports to identify gaps in monitoring coverage.","tip":"Set up a dedicated Slack/Discord channel for monitoring discussions to centralize feedback from your team. Use reactions (e.g., 👍 for acknowledged alerts) to track response times."}]
No install command available. Check the GitHub repository for manual installation instructions.
git clone https://github.com/solanabr/ai-kit/blob/main/.claude/skills/monitoring.mdCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Monitor the [SOLANA_PROGRAM_NAME] Solana program deployed at [PROGRAM_ADDRESS] for critical events. Set up alerts for [LIST_OF_ON_CHAIN_EVENTS, e.g., 'failed transactions', 'stake slashing events', 'minting failures'] and off-chain metrics [LIST_OF_METRICS, e.g., 'API latency > 500ms', 'queue depth > 1000', 'error rate > 1%']. Configure webhooks to send alerts to [ALERT_CHANNEL, e.g., 'Slack #solana-alerts', 'Discord #program-monitoring', 'PagerDuty']. Include a summary of recent activity and any anomalies detected in the last [TIME_RANGE, e.g., '24 hours'].
## Solana Program Monitoring Report: StakingRewards v2.1.0 **Program Address:** `StakeRw2a1P19s9Gk6W824X7a2mH9f9b9X9X9X9X9X9X9` **Monitoring Period:** Last 24 hours (UTC: 2024-05-15 00:00:00 to 2024-05-16 00:00:00) ### 🚨 Critical Alerts Triggered 1. **Failed Transaction Spike** - **Event:** 42 failed transactions detected in the last hour. - **Root Cause:** `StakeInstruction::ClaimRewards` failed due to insufficient compute units (CU). - **Impact:** 12 users unable to claim rewards, total locked rewards: ~3.2 SOL. - **Action Taken:** Program maintainers increased compute budget to 1.4M CUs (from 1.2M). 2. **Slashing Event Detected** - **Event:** Validator `F9s9...X9X9` slashed 0.05 SOL for double-signing. - **Impact:** Affected 8 delegators (avg. loss: 0.006 SOL each). - **Action Taken:** Validator removed from delegation whitelist. ### 📊 Off-Chain Metrics | Metric | Threshold | Current Value | Status | Trend | |----------------------|-----------|---------------|---------|--------| | API Latency (p99) | < 500ms | 680ms | ⚠️ Alert | ↗️ | | Queue Depth | < 1000 | 1240 | ⚠️ Alert | ↗️ | | Error Rate | < 1% | 1.8% | ❌ Critical | ↗️ | | RPC Health | 100% | 98.2% | ⚠️ Alert | ↘️ | ### 🔍 Recent Activity Summary - **Total Transactions:** 12,450 (+12% vs. 24h avg) - **Unique Users:** 872 (+8% vs. 24h avg) - **Rewards Distributed:** 45.6 SOL (avg. reward: 0.052 SOL/user) - **Top User:** `UserA1b2...C3d4` claimed 2.1 SOL in rewards. ### 🛠️ Recommended Actions 1. **Immediate:** Investigate API latency spike (root cause: `getStakeAccounts` RPC call). Consider caching frequent queries. 2. **Short-term:** Review compute budget for `ClaimRewards` instruction. Test with 1.6M CUs in staging. 3. **Long-term:** Implement circuit breaker for slashing events to auto-pause delegations temporarily. ### 📡 Alert Configuration - **Slack Channel:** `#staking-alerts` (webhook: `https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX`) - **Discord Channel:** `#program-monitoring` (webhook: `https://discord.com/api/webhooks/...`) - **PagerDuty:** Escalation policy `Solana-OnCall` (severity: `critical` for failed transactions, `warning` for others). --- *Next report scheduled in 4 hours. For real-time alerts, enable `SolanaMonitor` bot in your workspace.*
skills-collection
Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan