Prometheus is an open-source metrics collection and alerting system, originally built at SoundCloud and now maintained by the Cloud Native Computing Foundation. It's the #23 most-used developer tool, reported in roughly 11.8% of developer surveys. Built around its own time-series database and query language (PromQL), it's become the standard for monitoring Kubernetes and cloud-native applications, and is almost always paired with Grafana for building dashboards on top of its data.
PromQL lets you query and aggregate time-series metrics scraped from your services โ here's a query for the 5-minute request rate, grouped by status code.
# rate of HTTP requests per second over the last 5 minutes, by status code
sum(rate(http_requests_total[5m])) by (status_code)
# alert if error rate exceeds 5% for 10 minutes
(sum(rate(http_requests_total{status_code=~"5.."}[5m]))
/ sum(rate(http_requests_total[5m]))) > 0.05
Run Prometheus locally with Docker and point it at a config file that tells it which endpoints to scrape.
# prometheus.yml
scrape_configs:
- job_name: 'myapp'
static_configs:
- targets: ['localhost:9090']
# run via Docker
docker run -p 9090:9090 -v ./prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus