- Integrated all production features into main application flow - Added metrics, tracing, caching, and health checks to API server - Enhanced trade execution with circuit breakers and retry policies - Integrated database persistence for trades and metrics - Added structured logging and observability - Enhanced middleware with missing validators and rate limiters - Added comprehensive error handling and resilience patterns
4.3 KiB
4.3 KiB
Operational Runbooks
Common operational procedures for the Immortal AI Trading Bot.
Table of Contents
- Starting the Bot
- Stopping the Bot
- Checking Bot Status
- Viewing Logs
- Restarting Services
- Database Maintenance
- Clearing Cache
- Rotating API Keys
- Emergency Stop
Starting the Bot
Via API
curl -X POST http://localhost:3001/api/start-bot \
-H "Content-Type: application/json" \
-d '{
"tokens": [],
"risk": 5
}'
Via Docker
docker-compose exec backend bun run src/index.ts
Stopping the Bot
Via API
curl -X POST http://localhost:3001/api/stop-bot
Via Docker
docker-compose stop backend
Checking Bot Status
# Basic status
curl http://localhost:3001/api/bot-status
# Health check
curl http://localhost:3001/health
# Detailed health
curl http://localhost:3001/api/health
Viewing Logs
Docker Logs
# All services
docker-compose logs -f
# Backend only
docker-compose logs -f backend
# Last 100 lines
docker-compose logs --tail=100 backend
Log Files
# Error logs
tail -f logs/error.log
# Combined logs
tail -f logs/combined.log
# Structured JSON logs
tail -f logs/structured.json | jq
Restarting Services
# Restart all services
docker-compose restart
# Restart specific service
docker-compose restart backend
# Full restart (stop and start)
docker-compose down
docker-compose up -d
Database Maintenance
Run Migrations
bunx prisma migrate deploy
Check Database Size
psql $DATABASE_URL -c "SELECT pg_size_pretty(pg_database_size(current_database()));"
Vacuum Database
psql $DATABASE_URL -c "VACUUM ANALYZE;"
Check Table Sizes
psql $DATABASE_URL -c "
SELECT
schemaname,
tablename,
pg_size_pretty(pg_total_relation_size(schemaname||'.'||tablename)) AS size
FROM pg_tables
WHERE schemaname = 'public'
ORDER BY pg_total_relation_size(schemaname||'.'||tablename) DESC;
"
Clearing Cache
Redis Cache
# Connect to Redis
redis-cli
# Clear all cache
FLUSHALL
# Clear specific pattern
KEYS "immortal-bot:token:*" | xargs redis-cli DEL
Application Cache
# Via API (if endpoint exists)
curl -X POST http://localhost:3001/api/cache/clear
Rotating API Keys
Generate New API Key
# Via script
bun run scripts/generate-api-key.ts
# Or manually
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
Update Environment
- Add new key to
.env.production - Update API clients
- Revoke old key after migration period
Emergency Stop
Immediate Stop
# Stop bot
curl -X POST http://localhost:3001/api/stop-bot
# Pause wallet
# (Requires wallet manager integration)
Complete Shutdown
# Stop all services
docker-compose down
# Stop database (if local)
docker-compose stop postgres
Performance Tuning
Increase Memory Limits
Edit docker-compose.prod.yml:
services:
backend:
deploy:
resources:
limits:
memory: 2G
Optimize Database
# Analyze query performance
psql $DATABASE_URL -c "EXPLAIN ANALYZE SELECT * FROM \"Trade\" WHERE \"tokenAddress\" = '0x...';"
# Create indexes if needed
bunx prisma migrate dev --create-only
Monitoring
Check Metrics
# Prometheus metrics
curl http://localhost:3001/metrics
# Specific metric
curl http://localhost:3001/metrics | grep trades_total
View Grafana Dashboards
- Open Grafana: http://localhost:3000
- Navigate to dashboards
- Select relevant dashboard
Troubleshooting Common Issues
Bot Not Starting
- Check logs:
docker-compose logs backend - Verify environment variables
- Check database connection
- Verify wallet balance
High Error Rate
- Check error logs:
tail -f logs/error.log - Review recent errors
- Check external service status
- Review circuit breaker states
Slow Performance
- Check database query performance
- Review cache hit rates
- Check API response times
- Review system resources