🚨 Instantly detect runaway processes burning through your API tokens, credits, and cloud resources!
The Runaway Monitor is a comprehensive real-time monitoring system that tracks API usage patterns across all your connected services and immediately alerts you when anomalous behavior is detected. Perfect for preventing cost overruns, detecting runaway automation, and maintaining budget control.
- Real-Time Monitoring: Continuous polling of API usage across multiple services
- Intelligent Detection: Statistical analysis to identify usage spikes and patterns
- Instant Alerts: Telegram notifications for immediate response
- Cost Protection: Automatic circuit breakers to prevent runaway costs
- Multi-Service Support: OpenAI, GitHub Actions, Stripe, Supabase, Cloudflare R2, and more
-
Install Dependencies:
pip install -r requirements.txt
-
Configure Environment:
cp .env.example .env # Edit .env with your API credentials and Telegram bot details -
Configure Monitoring:
cp config/monitor_config.example.json config/monitor_config.json # Adjust thresholds and monitoring intervals -
Test Setup:
python test_monitor.py
-
Start Monitoring:
python monitor.py --start
# Telegram Notifications
TELEGRAM_BOT_TOKEN=your_bot_token_here
TELEGRAM_CHANNEL_ID=your_channel_id_here
# API Credentials to Monitor
OPENAI_API_KEY=your_openai_key_here
GITHUB_TOKEN=your_github_token_here
STRIPE_API_KEY=your_stripe_key_here
SUPABASE_URL=your_supabase_url_here
SUPABASE_ANON_KEY=your_supabase_key_here
CLOUDFLARE_API_TOKEN=your_cf_token_here
# Add more services as neededConfigure detection sensitivity in config/monitor_config.json:
{
"monitoring_interval": 300,
"cost_thresholds": {
"openai": {"hourly": 10.0, "daily": 100.0},
"github_actions": {"hourly": 5.0, "daily": 50.0}
},
"usage_spike_multiplier": 3.0,
"circuit_breaker": {
"enabled": true,
"threshold_multiplier": 5.0
}
}Runaway_Monitor/
├── monitor.py # Main monitoring engine
├── config/
│ ├── monitor_config.json # Monitoring thresholds
│ └── thresholds.py # Threshold management
├── detectors/
│ ├── api_detector.py # General API usage detection
│ ├── github_detector.py # GitHub Actions monitoring
│ └── database_detector.py # Database usage monitoring
├── notifications/
│ └── telegram_notifier.py # Telegram alert system
└── test_monitor.py # Test suite
- OpenAI: Token usage and cost tracking
- GitHub Actions: Workflow minutes and cost monitoring
- Stripe: Transaction volume and processing fees
- Supabase: Database operations and bandwidth
- Cloudflare R2: Storage operations and bandwidth
- MongoDB Atlas: Database operations and costs
- Vercel: Deployment and function usage
- Custom APIs: Extensible framework for any REST API
- Cost Spike Alerts: When hourly/daily costs exceed thresholds
- Usage Pattern Alerts: Unusual API call patterns detected
- Circuit Breaker Alerts: Automatic emergency stops triggered
- Service Status Alerts: API endpoint availability issues
- Circuit Breakers: Automatic emergency stops when thresholds exceeded
- Rate Limiting: Prevents monitor itself from causing API spam
- Graceful Degradation: Continues monitoring even if some services fail
- Cost Estimation: Real-time cost projections based on current usage
This system integrates seamlessly with ENVThing for credential management:
# Automatic credential loading from ENVThing
monitor = RunawayMonitor(env_source="envthing")python test_monitor.py- Create new detector in
detectors/ - Extend
APIUsageDetectorclass - Add service configuration to
monitor_config.json - Update main monitor to include new detector
Adjust monitoring sensitivity by modifying threshold multipliers and baseline calculations in config/thresholds.py.
MIT License - See LICENSE file for details.
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Submit a pull request
⚡ Stop runaway processes before they burn through your budget!