Metrics & Monitoring¶
Craft Easy API exposes Prometheus-compatible metrics for monitoring request performance, business operations, and job execution.
Configuration¶
| Setting | Default | Description |
|---|---|---|
METRICS_ENABLED |
true |
Enable/disable metrics collection |
METRICS_PATH |
"/metrics" |
Path for the Prometheus scrape endpoint |
Setup¶
Metrics are automatically enabled when METRICS_ENABLED=true. The /metrics endpoint returns metrics in Prometheus text format:
HTTP Metrics¶
Request Counter¶
Labels: method, endpoint, status
Request Duration¶
Histogram buckets: 5ms, 10ms, 25ms, 50ms, 100ms, 250ms, 500ms, 1s, 2.5s, 5s, 10s
Labels: method, endpoint
Requests In Flight¶
Gauge tracking the number of currently active requests.
Request/Response Size¶
http_request_size_bytes_bucket{method="POST", endpoint="/users", le="1000"} 500
http_response_size_bytes_bucket{method="GET", endpoint="/users", le="10000"} 800
Histogram buckets: 100B, 1KB, 10KB, 100KB, 1MB (request), 10MB (response)
Labels: method, endpoint
Business Metrics¶
Authentication¶
auth_logins_total{method="email", success="true"} 234
auth_logins_total{method="oauth2", success="false"} 12
Labels: method (email, sms, oauth2, api_key), success (true/false)
CRUD Operations¶
crud_operations_total{resource="users", operation="create"} 89
crud_operations_total{resource="tenants", operation="update"} 45
Labels: resource, operation (create, read, update, delete)
Active Tenants¶
Gauge tracking the number of active tenants.
Job Execution¶
job_runs_total{job_name="token-cleanup", status="completed"} 720
job_duration_seconds_bucket{job_name="bi-export", le="60.0"} 30
- Counter labels:
job_name,status(completed, failed, cancelled) - Duration histogram buckets: 100ms, 500ms, 1s, 5s, 10s, 30s, 60s, 5min, 10min
Custom Registry¶
Metrics use a custom CollectorRegistry to avoid polluting the default Prometheus registry. This ensures clean metrics when running alongside other instrumented libraries.
Grafana Integration¶
The metrics are compatible with standard Prometheus/Grafana setups. Common dashboards:
- Request rate —
rate(http_requests_total[5m])by endpoint - Latency p95 —
histogram_quantile(0.95, rate(http_request_duration_seconds_bucket[5m])) - Error rate —
rate(http_requests_total{status=~"5.."}[5m]) - In-flight requests —
http_requests_in_flight