mirror of
https://github.com/thecyberlearn/quantumtaskai-caprover.git
synced 2026-08-18 08:52:57 +00:00
Complete Django AI agent marketplace with security optimizations and clean deployment documentation without any API keys or secrets. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
3.9 KiB
3.9 KiB
CapRover Monitoring and Logging Optimization
1. Enhanced Logging Configuration
Django Logging (Already Optimized)
Your current logging setup in settings.py is good. Additional optimizations:
# Add to settings.py
LOGGING_LEVEL = config('LOGGING_LEVEL', default='INFO')
# Performance monitoring
PERFORMANCE_MONITORING = {
'SLOW_QUERY_THRESHOLD': 1.0, # Log queries slower than 1 second
'MEMORY_THRESHOLD': 100, # MB
}
2. Application Performance Monitoring (APM)
Option A: Django Debug Toolbar (Development)
Already configured for DEBUG=True environments.
Option B: Simple Performance Middleware
Add custom middleware for production monitoring:
# In core/middleware.py
class PerformanceMonitoringMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
import time
start_time = time.time()
response = self.get_response(request)
duration = time.time() - start_time
if duration > 2.0: # Log slow requests
logger.warning(f"Slow request: {request.path} took {duration:.2f}s")
response['X-Response-Time'] = f"{duration:.3f}"
return response
3. CapRover Native Monitoring
Enable App Monitoring
- CapRover Dashboard → Apps → quantumtaskai → App Configs
- Enable: "Log Rotation"
- Set: "Max Log Size" to 100MB
- Set: "Max Files" to 5
Resource Limits
# In captain-definition (advanced)
{
"schemaVersion": 2,
"dockerfilePath": "./Dockerfile.captain",
"containerHttpPort": 80,
"resources": {
"memory": "512m",
"cpu": "0.5"
}
}
4. External Monitoring Options
Option A: Netdata (Lightweight)
- One-Click Apps → Search "Netdata"
- Deploy with default settings
- Access: Monitor system resources in real-time
Option B: Grafana + Prometheus (Advanced)
- Deploy Prometheus from One-Click Apps
- Deploy Grafana from One-Click Apps
- Configure Django metrics export
5. Health Checks and Uptime Monitoring
Application Health Endpoint
Create a health check endpoint in Django:
# In core/views.py
from django.http import JsonResponse
from django.core.cache import cache
from django.db import connection
def health_check(request):
"""Application health check endpoint"""
try:
# Test database
with connection.cursor() as cursor:
cursor.execute("SELECT 1")
# Test Redis
cache.set('health_check', 'ok', 10)
cache_status = cache.get('health_check') == 'ok'
return JsonResponse({
'status': 'healthy',
'database': 'ok',
'cache': 'ok' if cache_status else 'error',
'timestamp': timezone.now().isoformat()
})
except Exception as e:
return JsonResponse({
'status': 'unhealthy',
'error': str(e)
}, status=500)
External Uptime Monitoring
- UptimeRobot (Free tier available)
- Pingdom
- StatusCake
Monitor: https://quantumtaskai.captain.your-domain.com/health/
6. Log Analysis
Centralized Logging (Optional)
- Deploy ELK Stack (Elasticsearch, Logstash, Kibana)
- Configure Django to send logs to Logstash
- Analyze logs in Kibana dashboard
Simple Log Analysis
# Monitor application logs
docker logs -f [container-id]
# Search for errors
docker logs [container-id] 2>&1 | grep -i error
# Monitor performance
docker logs [container-id] 2>&1 | grep "Slow request"
7. Alerts and Notifications
Webhook Notifications
Set up webhooks for critical alerts:
- High memory usage
- Database connection failures
- Application errors
- Long response times
Email Notifications
Configure Django to send email alerts for critical issues using your existing email setup.