Health Checks
Basic Health Check
SuperTokens provides a/hello endpoint for basic health verification:
200 OK- Service is healthy and database is accessible500 Internal Server Error- Service or database issue
Docker Health Check
Configure health checks in Docker Compose:Kubernetes Probes
Advanced Health Monitoring
Create a comprehensive health check script:Logging
Log Configuration
Configure logging inconfig.yaml:
Log Levels
- DEBUG: Detailed debugging information (verbose)
- INFO: General informational messages (default)
- WARN: Warning messages for potential issues
- ERROR: Error messages for failures
- NONE: Disable logging (not recommended)
Docker Logging
Send logs to stdout/stderr:Log Rotation
Using logrotate (Linux): Create/etc/logrotate.d/supertokens:
Centralized Logging
Elasticsearch + Fluentd + Kibana (EFK)
Loki + Promtail + Grafana
OpenTelemetry Integration
SuperTokens supports OpenTelemetry for distributed tracing and metrics.Configuration
OpenTelemetry Collector Setup
otel-collector-config.yaml:
docker-compose.yml:
Metrics and Monitoring
Key Metrics to Monitor
Application Metrics
- Request Rate: Requests per second to SuperTokens
- Response Time: Average/P95/P99 response times
- Error Rate: Percentage of failed requests
- Active Sessions: Number of active user sessions
- Database Queries: Query count and latency
System Metrics
- CPU Usage: Core CPU utilization percentage
- Memory Usage: RAM consumption
- Disk I/O: Read/write operations
- Network I/O: Inbound/outbound traffic
Database Metrics
- Connection Pool: Active/idle connections
- Query Performance: Slow query count and duration
- Database Size: Storage usage growth
- Replication Lag: For replicated setups
Prometheus Configuration
prometheus.yml:
Grafana Dashboards
Import Dashboards
- Open Grafana: http://localhost:3000
- Navigate to Dashboards > Import
- Use these dashboard IDs:
- PostgreSQL: 9628
- MySQL: 7362
- Docker: 179
- Node Exporter: 1860
Custom SuperTokens Dashboard
Create a dashboard with panels for:- Request rate (requests/sec)
- Response time (ms) - P50, P95, P99
- Error rate (%)
- Active sessions
- Database query count
- CPU and memory usage
Database Monitoring
PostgreSQL Exporter
MySQL Exporter
Container Monitoring
cAdvisor
Alerting
AlertManager Configuration
alertmanager.yml:
Alert Rules
alerts.yml:
Uptime Monitoring
Using External Services
- Pingdom: https://www.pingdom.com
- UptimeRobot: https://uptimerobot.com
- StatusCake: https://www.statuscake.com
- Better Uptime: https://betteruptime.com
Self-Hosted Options
Uptime Kuma
Performance Monitoring
Application Performance Monitoring (APM)
Integrate with APM tools:- Datadog: https://www.datadoghq.com
- New Relic: https://newrelic.com
- Dynatrace: https://www.dynatrace.com
- Elastic APM: https://www.elastic.co/apm
Custom Performance Tracking
Troubleshooting with Monitoring
High CPU Usage
High Memory Usage
Slow Database Queries
Security Monitoring
Failed Authentication Attempts
Monitor error logs for patterns:Rate Limiting
SuperTokens has built-in rate limiting. Monitor rate limit hits:Audit Logging
For compliance, enable audit logging:Best Practices
- Set up health checks on all deployment platforms
- Monitor key metrics continuously (response time, error rate, CPU, memory)
- Configure alerts for critical issues with appropriate thresholds
- Centralize logs for easier troubleshooting
- Test alerts regularly to ensure they work
- Document runbooks for common issues
- Review metrics regularly to identify trends
- Set up dashboards for at-a-glance status
- Monitor database health separately
- Keep retention policies for logs and metrics