Okay, the user is asking about Prometheus in the context of monitoring. They specifically want to know what Prometheus is, its data model (time-series database), how it collects metrics (pull-based model), and what PromQL is.
First, I need to define Prometheus clearly as an open-source monitoring and alerting toolkit. The user mentioned "time-series database" so I should explain its data model, emphasizing that it stores data as time series with labels.
Next, the pull-based model: I should contrast it with push-based models, explain how Prometheus scrapes targets, and mention service discovery and exporters. The user might be comparing different monitoring tools, so clarifying the pros and cons of pull vs. push would help.
For PromQL, I need to describe it as a query language, give examples of basic and advanced queries, and highlight its flexibility for aggregation and analysis. The user might be looking to understand how to actually use Prometheus for troubleshooting or dashboarding.
I should structure the response to address each part of the query sequentially, keep it concise but comprehensive, and avoid jargon unless explained. Since the user asked for definitions, I’ll start with a high-level overview before diving into specifics.
Also, the user might be new to monitoring, so I’ll avoid assuming too much prior knowledge. I’ll include practical examples where helpful, like a PromQL query for CPU usage, to make it tangible.
Finally, I’ll summarize why Prometheus is popular—its multidimensional data model, pull model, and powerful query language—to tie everything together. The response should answer all parts of the query without extra fluff.
Excellent question! You've hit on the core pillars of Prometheus. Let's break it down clearly.
1. What is Prometheus?
Prometheus is an open-source systems and service monitoring and alerting toolkit originally built at SoundCloud. It's now a graduated project of the Cloud Native Computing Foundation (CNCF) and is the de facto standard for monitoring in cloud-native and containerized environments (like Kubernetes).
Its core philosophy is to provide:
- Reliable monitoring in dynamic, ephemeral environments.
- Powerful queries and alerting on time-series data.
- An open, operational model that avoids vendor lock-in.
2. Its Data Model: A Time-Series Database
Prometheus stores all data as time series—a sequence of measurements taken at successive times, each with a set of labels.
A time series is uniquely identified by its metric name and a set of key-value label pairs.
Structure of a Sample:
<timestamp> <value> <metric_name>{<label_key1>="<label_value1>", <label_key2>="<label_value2>", ...}
Example:
1649241600 0.45 http_requests_total{method="GET", handler="/api/user", code="200"}
- Metric Name:
http_requests_total (the what)
- Labels:
method, handler, code (the dimensions/attributes)
- Value:
0.45 (the numeric measurement at a point in time)
- Timestamp:
1649241600 (the when)
Key Characteristics:
- Multidimensional: Data is organized by labels, not by separate databases or hierarchies. This allows for ad-hoc slicing and dicing of any dimension.
- Immutable & Append-Only: Data is never updated or deleted (until retention expires). It's a write-once log.
- Native Types: Supports 64-bit floating-point values (Gauges, Counters, Histograms, Summaries, and boolean/string info via the
TYPE and HELP metadata).
- Retention-Based: Data is stored locally on disk for a configurable retention period (e.g., 15 days). Long-term storage is possible via remote storage adapters.
3. How it Collects Metrics: The "Pull-Based" Model
This is the most distinctive and crucial aspect of Prometheus.
Pull Model: Prometheus actively scrapes (pulls) metrics from instrumented applications (called targets) at regular intervals.
The Process:
- Service Discovery: Prometheus discovers what to scrape. This can be:
- Static configuration (
prometheus.yml file).
- Dynamic cloud integrations (AWS, GCP, Azure).
- Kubernetes service discovery (the most common).
- Scraping: Prometheus contacts the target's
/metrics HTTP endpoint at its configured scrape_interval (e.g., every 15s).
- Parsing & Storing: It ingests the plaintext exposition format (usually from a client library), parses the metrics (with their labels), and stores them as new time series samples in its local TSDB.
Analogy: Instead of applications calling a central mailbox (push), a central mailman (Prometheus) regularly walks to every house (target) to pick up the letters (metrics) from their mailbox (/metrics).
Why Pull?
- Simplicity for Targets: Targets only need to expose an HTTP endpoint. No need to know about the monitoring system's address.
- Natural for Cloud-Native: Works perfectly with dynamic, ephemeral targets (containers/pods scaling up/down). Prometheus discovers them via Service Discovery.
- Failure Detection: If a target is down, Prometheus's scrape will fail, immediately alerting you to the outage. With push, you only know the sender stopped pushing.
- No Data Loss from Network Issues: The target always has the latest data. If Prometheus is down, a future scrape can catch up (within retention limits).
The Role of Exporters:
Many systems (e.g., Linux, MySQL, Nginx, RabbitMQ) don't natively expose Prometheus metrics. Exporters are small proxies that translate these systems' metrics into the Prometheus format on a /metrics endpoint. Examples: node_exporter (host metrics), mysqld_exporter, blackbox_exporter (probe HTTP/TCP/etc.).
4. What is PromQL (Prometheus Query Language)?
PromQL is a functional, rich expression language designed for querying and manipulating time-series data in Prometheus. It's the engine that powers:
- Grafana dashboards (changing graphs on the fly).
- Alerting rules (defining complex conditions like "5m cpu load average > 2").
- Ad-hoc exploration via the Prometheus web UI.
Core Concepts of PromQL:
- Instant Vector: A set of time series, each with a single sample value at the same timestamp (the "now").
- Example:
http_requests_total (all time series for that metric at the evaluation time).
- Range Vector: A set of time series, each with a range of samples over time (like a mini-graph).
- Example:
http_requests_total[5m] (all samples for each series over the last 5 minutes).
What you can do with PromQL:
- Filter by Labels: Select specific series.
http_requests_total{handler="/api/user", code="200"}
- Rate & Increase: Calculate per-second rates or total increases over a range.
rate(http_requests_total[5m]) (per-second rate over last 5m)
increase(http_requests_total[1h]) (total increase over last hour)
- Aggregation & Grouping: Summarize across labels.
sum(rate(http_requests_total[5m])) (total QPS across all handlers/methods)
sum(http_requests_total) by (handler) (total requests, grouped by handler)
avg(rate(process_cpu_seconds_total[5m])) by (instance) (avg CPU usage per instance)
- Math & Functions: Apply operators (
+, *, /, -), comparisons (>, <), and functions (abs, ceil, sqrt, histogram_quantile).
- Operators for Joining:
and, or, unless for set operations on instant vectors.
Simple Example Query:
"What is the 95th percentile of request latency for the /api/login endpoint over the last 10 minutes?"
histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket{handler="/api/login"}[10m])) by (le))
Summary Table
| Aspect | Description |
|---|
| What is it? | Open-source monitoring & alerting system. |
| Core Data Model | Multi-dimensional time-series identified by metric_name + labels. |
| Collection Model | Pull-based. Prometheus scrapes targets' /metrics HTTP endpoint. |
| Query Language | PromQL - a powerful functional language for selecting, aggregating, and calculating on time-series data. |
In essence: Prometheus pulls labeled metrics into its time-series database, and you use PromQL to ask complex questions ("queries") about that data for dashboards and alerts. This model made it exceptionally well-suited for the dynamic, label-rich world of microservices and Kubernetes.