Production Monitoring

Implement metrics and monitoring for production environments.

Running

go run main.go

Server starts on http://localhost:3110

Metrics Endpoints

Prometheus Format (/metrics)

Standard Prometheus exposition format:

# HELP http_requests_total Total number of HTTP requests
# TYPE http_requests_total counter
http_requests_total 1234

# HELP http_errors_total Total number of HTTP errors
# TYPE http_errors_total counter
http_errors_total 5

# HELP http_request_duration_avg Average request duration
# TYPE http_request_duration_avg gauge
http_request_duration_avg 25.5

JSON Format (/stats)

Easy-to-read JSON metrics:

{
  "uptime_seconds": 3600,
  "requests_total": 1234,
  "errors_total": 5,
  "requests_active": 3,
  "avg_latency_ms": 25.5
}

Metrics Tracked

Request Metrics

System Metrics

Performance Metrics

Integration

Prometheus

Scrape /metrics endpoint:

scrape_configs:
  - job_name: 'lokstra-app'
    static_configs:
      - targets: ['localhost:3110']
    metrics_path: '/metrics'

Grafana

Create dashboards using metrics:

Alerting

Set up alerts based on thresholds:

Best Practices