Prometheus is the de facto cloud-native standard for metrics collection, originally developed at SoundCloud and now a graduated CNCF project.
Why Pull over Push?
Unlike traditional agents (e.g. Datadog or CloudWatch) that push metrics outbound, Prometheus pulls (scrapes) metrics over HTTP:
- Centralized Rate Control: The server decides when and how often to scrape, preventing target servers from being overwhelmed.
- Built-In Liveness Detection: If Prometheus fails to scrape an endpoint, it immediately records
up{instance="..."} = 0. You know the target died without relying on the dead server to send a failure alert. - Multiple Scrapers: Staging and monitoring clusters can scrape the same application without modifying application configuration.
TSDB Internal Storage Engine
Prometheus stores time-series data using a specialized append-only engine:
- Head Chunk: Recent samples are buffered in memory and appended to a Write-Ahead Log (WAL) on disk to survive process crashes.
- Compacted Blocks: Every 2 hours, memory chunks are compacted into immutable 2-hour disk blocks containing a chunks directory, index, and metadata.
Hands-On: Production prometheus.yml Configuration
Let's write a production configuration file with global settings, alert rules, and target scrape jobs:
Running the Monitoring Stack with Docker Compose
Create a docker-compose.yml:
Start Prometheus:
Open your browser to http://localhost:9090 and navigate to Status -> Targets to verify all endpoints are in the UP state!