Skip to main content

Health Checks & Application Metrics

Plugged.in exposes health check endpoints for load balancers and monitoring systems, plus comprehensive Node.js runtime metrics for performance tracking.

Health Check Endpoint

GET /api/health

Returns the health status of the application with database connectivity check.

Response Format

string
required
Overall health status: healthy or unhealthy
  • 200 OK: Application is healthy
  • 503 Service Unavailable: Application has issues
string
required
ISO 8601 timestamp of the health check
object
required
Individual health check results
number
Whitelisted IPs only: Process uptime in seconds
string
Whitelisted IPs only: Application version (from APP_VERSION env var)
string
Whitelisted IPs only: Runtime environment (development/production)

Security & IP Restrictions

Detailed health information (version, environment, uptime) is only visible to whitelisted monitoring IPs to prevent information disclosure.
Health endpoint uses the same METRICS_ALLOWED_IPS configuration as the metrics endpoint:
Allowed IPs see:
  • Full health status with version, environment, uptime
Non-whitelisted IPs see:
  • Basic health status only (status, timestamp, checks)

HEAD /api/health

Lightweight health check that returns only status code (no body).
Ideal for:
  • Load balancer health checks
  • Kubernetes liveness/readiness probes
  • High-frequency monitoring

Application Metrics Endpoint

GET /api/metrics

Exposes Node.js runtime and HTTP metrics in Prometheus format.
The /api/metrics endpoint is IP-restricted and should only be accessible to your Prometheus/Grafana server.

IP Whitelist Configuration

Configure allowed IPs in .env:
Supported formats:
  • IPv4: 127.0.0.1, 10.0.0.1
  • IPv6: ::1, fe80::1
  • CIDR: 172.17.0.0/16, 10.0.0.0/8

Node.js Runtime Metrics

Counter
Total user CPU time consumed by the process
Counter
Total system CPU time consumed by the process
Gauge
Process start time in seconds since Unix epoch
Gauge
Resident memory size in bytes
Gauge
Total heap size allocated for the process
Gauge
Currently used heap size
Gauge
Memory used by C++ objects bound to JavaScript objects
Gauge
Event loop lag in seconds (sampled every 10ms)
High event loop lag (> 0.1s) indicates the process is blocked or under heavy load
Gauge
50th percentile event loop lag
Gauge
90th percentile event loop lag
Gauge
99th percentile event loop lag
Histogram
Garbage collection duration by GC typeLabels: kind (minor/major/incremental/etc.)Buckets: 0.001s, 0.01s, 0.1s, 1s, 2s, 5s
Gauge
Number of active handles (file descriptors, sockets, etc.)
Gauge
Number of active asynchronous requests

HTTP Metrics

Counter
Total HTTP requestsLabels: method, path, status_code
Histogram
HTTP request duration in secondsLabels: method, path, status_codeBuckets: 0.01s, 0.05s, 0.1s, 0.5s, 1s, 2s, 5s, 10s
Counter
Total HTTP errors (4xx + 5xx responses)Labels: method, path, error_typeError types: client_error (4xx), server_error (5xx), rate_limit, unauthorized

Prometheus Configuration

Add to your prometheus.yml:

Alert Rules

Health Check Alerts

Add to prometheus/rules/pluggedin-app-alerts.yml:

Performance Alerts

Grafana Dashboard

Query Examples

Troubleshooting

  1. Check database connectivity: psql $DATABASE_URL -c "SELECT 1"
  2. Review application logs for database errors
  3. Verify database server is running
  4. Check connection pool settings
  1. Verify your IP is in METRICS_ALLOWED_IPS
  2. Check IP format (IPv4, IPv6, or CIDR)
  3. For CIDR, ensure proper notation (e.g., 172.17.0.0/16)
  4. Test from allowed IP: curl -H "X-Forwarded-For: 127.0.0.1" http://localhost:12005/api/metrics
  1. Check for blocking synchronous operations
  2. Review CPU usage: pluggedin_process_cpu_user_seconds_total
  3. Identify long-running functions
  4. Consider offloading heavy work to background workers
  1. Check for memory leaks with heap snapshots
  2. Review pluggedin_nodejs_heap_size_used_bytes trend
  3. Check GC metrics: pluggedin_nodejs_gc_duration_seconds
  4. Consider increasing heap size or implementing memory limits

Best Practices

Health Check Frequency

Load Balancers: Poll every 10-30 seconds using HEAD requestMonitoring Systems: Poll every 30-60 seconds using GET requestAvoid: Polling more frequently than 10 seconds (unnecessary load)

IP Whitelist Security

Production: Only whitelist your specific monitoring server IPsNever: Use 0.0.0.0/0 or overly broad CIDR rangesReview: Audit whitelist quarterly, remove unused IPs

Metrics Retention

Prometheus: 15-30 days for detailed metricsLong-term: Export to time-series database for historical analysisAggregation: Use recording rules for frequently-queried metrics

Next Steps

OAuth Metrics

OAuth 2.1 specific metrics and queries

Grafana Dashboards

Build custom dashboards and alerts

Log Queries

Query application logs with LogQL

Alert Rules

Production-ready alert configuration