Monitoring with Prometheus and Grafana
Add metrics to an app, collect them with Prometheus, build Grafana dashboards and alert when something breaks.
Advancedâą 10â14 hoursđĒ 7 stepsPrometheusGrafanaDocker Compose
What you'll learn
- âMetrics types (counter, gauge, histogram)
- âPromQL queries
- âDashboards and alerting
What you'll build
- âApp exposes /metrics
- âRequest rate, error rate, latency (p95) dashboard
- âServer CPU and memory via node exporter
- âAlert when error rate > 5%
Step-by-step guide
- 1
Instrument the app
Use a Prometheus client library (prom-client for Node, Micrometer for Spring Boot, prometheus_client for Python).
- 2
Key metrics
http_requests_total{route,status} counter and http_request_duration_seconds histogram.
- 3
Compose stack
Services: app, prometheus (with prometheus.yml scrape config), grafana, node-exporter.
- 4
PromQL
Rate: sum(rate(http_requests_total[5m])); errors: share of status=~"5.."; p95: histogram_quantile(0.95, sum by (le) (rate(...[5m]))).
- 5
Dashboard
Grafana panels for the four golden signals; save the dashboard JSON in the repo.
- 6
Alerts
An alert rule for high error rate and for the app being down (up == 0).
- 7
Break it
Add a debug endpoint that returns errors and show the alert firing.
đ Make it stand out
- +Logs with Loki
- +Tracing with OpenTelemetry
- +SLOs and error budgets