====== Runbook: Prometheus ======
**Duration:** ~15 minutes \\
**Role:** DevOps, SRE \\
**Prerequisite:** Prometheus Server, Gateway running
Collect metrics from Data Gateway with Prometheus.
----
===== Workflow =====
flowchart TD
A[Start] --> B[Enable metrics]
B --> C[Prometheus config]
C --> D[Add scrape job]
D --> E[Prometheus reload]
E --> F[Check targets]
F --> G{Up?}
G -->|Yes| H[Done]
G -->|No| I[Check firewall/endpoint]
style H fill:#e8f5e9
style I fill:#ffebee
----
===== 1. Enable Metrics in Gateway =====
**appsettings.json:**
{
"Metrics": {
"Enabled": true,
"Endpoint": "/metrics"
}
}
**Or via NuGet (if not built-in):**
# prometheus-net.AspNetCore
dotnet add package prometheus-net.AspNetCore
**Program.cs:**
// Metrics Middleware
app.UseHttpMetrics();
app.MapMetrics(); // /metrics Endpoint
----
===== 2. Test Metrics Endpoint =====
curl http://localhost:5000/metrics
# Expected output (Prometheus format):
# HELP http_requests_total Total HTTP requests
# TYPE http_requests_total counter
# http_requests_total{method="GET",endpoint="/api/v1/dsn/demo/tables",status="200"} 42
----
===== 3. Prometheus Configuration =====
**/etc/prometheus/prometheus.yml:**
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
# Data Gateway
- job_name: 'data-gateway'
static_configs:
- targets: ['gateway.example.com:5000']
metrics_path: /metrics
scheme: http # or https
# Multiple instances
- job_name: 'data-gateway-cluster'
static_configs:
- targets:
- 'gateway-1.example.com:5000'
- 'gateway-2.example.com:5000'
- 'gateway-3.example.com:5000'
----
===== 4. Reload Prometheus =====
# Config reload (without restart)
curl -X POST http://localhost:9090/-/reload
# Or restart
sudo systemctl restart prometheus
----
===== 5. Check Targets =====
**Web UI:** ''http://prometheus:9090/targets''
Or via API:
curl -s http://localhost:9090/api/v1/targets | jq '.data.activeTargets[] | {job: .labels.job, health: .health}'
**Expected output:**
{
"job": "data-gateway",
"health": "up"
}
----
===== 6. Important Queries =====
**PromQL examples:**
# Request rate (per second)
rate(http_requests_total{job="data-gateway"}[5m])
# Average response time
rate(http_request_duration_seconds_sum{job="data-gateway"}[5m])
/
rate(http_request_duration_seconds_count{job="data-gateway"}[5m])
# Error rate (5xx)
sum(rate(http_requests_total{job="data-gateway",status=~"5.."}[5m]))
/
sum(rate(http_requests_total{job="data-gateway"}[5m]))
# Memory usage
process_resident_memory_bytes{job="data-gateway"}
# Active connections
http_requests_in_progress{job="data-gateway"}
----
===== 7. Checklist =====
| # | Check | Done |
|---|-------|------|
| 1 | Metrics endpoint enabled | [ ] |
| 2 | /metrics reachable | [ ] |
| 3 | Prometheus config updated | [ ] |
| 4 | Prometheus reloaded | [ ] |
| 5 | Target "up" in Prometheus | [ ] |
| 6 | Metrics visible in Grafana | [ ] |
----
===== Troubleshooting =====
| Problem | Cause | Solution |
|---------|-------|----------|
| Target "down" | Endpoint not reachable | Check firewall, URL |
| ''connection refused'' | Gateway not running | Start Gateway |
| ''404 Not Found'' | Metrics not enabled | Check appsettings.json |
| No metrics | Wrong path | Check ''metrics_path'' |
----
===== Kubernetes ServiceMonitor =====
For Prometheus Operator:
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: data-gateway
namespace: monitoring
labels:
release: prometheus
spec:
selector:
matchLabels:
app: data-gateway
namespaceSelector:
matchNames:
- data-gateway
endpoints:
- port: http
path: /metrics
interval: 15s
----
===== Related Runbooks =====
* [[.:grafana-dashboard|Grafana Dashboard]] - Visualization
* [[.:alerting|Alerting]] - Notifications
* [[..:automatisierung:kubernetes|Kubernetes]] - K8s deployment
----
<< [[.:start|<- Monitoring]] | [[.:grafana-dashboard|-> Grafana Dashboard]] >>
----
//Wolfgang van der Stille @ EMSR DATA d.o.o. - Data Gateway Professional//
{{tag>operator runbook prometheus metrics monitoring}}