The Prometheus stack is a set of open-source tools for collecting, storing, and visualizing time-series metrics; this tutorial explains its core components and walks through a basic setup. You will learn what each piece does, how they fit together, and how to get a working monitoring pipeline on your own infrastructure.
What the Prometheus Stack Includes
The stack is often called the “Prometheus ecosystem” and typically consists of four main tools, though you can use them independently:
- Prometheus server – scrapes metrics over HTTP, stores them in a time-series database, and evaluates alerting rules.
- Alertmanager – handles alerts generated by Prometheus, deduplicating, grouping, and routing them to channels like email, Slack, or PagerDuty.
- Grafana – a visualization layer that queries Prometheus and builds dashboards; it is not strictly required but is the standard front-end.
- Exporters – small agents that expose metrics from third-party systems (for example, node_exporter for Linux hosts, or mysqld_exporter for MySQL).
Sometimes the term “Prometheus stack” also includes Thanos or VictoriaMetrics for long-term storage and high availability, but the core stack is the four components above. Prometheus itself is a single binary; everything else is optional.
How Prometheus Collects Data
Unlike traditional monitoring systems that receive pushed data, Prometheus uses a pull model. It sends HTTP requests to endpoints (usually /metrics) on target services at a defined scrape interval (default 30 seconds). The target responds with plain-text metrics in the Prometheus exposition format. This design makes it easy to see if a target is down – if the scrape fails, the target is unreachable.
Metrics are stored with labels (key-value pairs) that allow flexible querying. For example, an HTTP request counter might have labels for method, path, and status. Prometheus’s query language, PromQL, lets you aggregate and slice that data. A simple query like http_requests_total{status="500"} returns the total number of 500 responses.
Setting Up the Core Stack
A minimal setup requires downloading the Prometheus server, configuring it to scrape itself, and then adding exporters. Here is a basic step-by-step:
- Download and run Prometheus – get the latest release from the official site, extract it, and run
./prometheus --config.file=prometheus.yml. - Configure a scrape job – in
prometheus.yml, add a job for your own service. For example, to scrape the Prometheus server itself, usescrape_configs: - job_name: 'prometheus' static_configs: - targets: ['localhost:9090']. - Add an exporter – download node_exporter, run it on the host, and add a new scrape job pointing to
localhost:9100. - Install Grafana – run Grafana (or use a Docker container), add a Prometheus data source pointing to
http://localhost:9090, and import a dashboard. - Set up Alertmanager – configure alerting rules in Prometheus and define an Alertmanager receiver (e.g., email) in its own config file.
All components are available as Docker images, so a docker-compose.yml with services for prometheus, node_exporter, grafana, and alertmanager is a common way to test the stack locally.
Choosing Exporters and Integrations
Exporters are the bridge between Prometheus and the systems you monitor. The official Prometheus project maintains a list of exporters, but many are community-developed. Common ones include:
- node_exporter – for Linux/Unix host metrics (CPU, memory, disk, network).
- cadvisor – for container metrics (used heavily with Docker).
- blackbox_exporter – for probing endpoints (HTTP, TCP, ICMP).
- mysqld_exporter, postgres_exporter, redis_exporter – for database metrics.
- statsd_exporter – for accepting StatsD metrics and converting them to Prometheus format.
When choosing an exporter, check its maintenance status and the Prometheus compatibility. Some exporters (like node_exporter) are official and battle-tested; others may be abandoned. Also ensure the exporter exposes metrics in the correct format – Prometheus does not understand JSON or XML natively.
Common Configuration Pitfalls
New users often hit the same issues:
- Scrape timeouts – if a target takes longer than the
scrape_timeout(default 10s) to respond, the scrape fails. Increase the timeout or optimize the exporter. - Label cardinality – using high-cardinality labels (like user IDs or IP addresses) can explode the database size. Keep labels to a few low-cardinality values.
- Relabeling confusion – relabeling rules are powerful but complex; a mistake can silently drop targets. Use
promtool check configto validate. - Storage retention – by default, Prometheus stores data for 15 days. If you need longer, adjust
--storage.tsdb.retention.timeor integrate with Thanos. - Alertmanager not receiving alerts – check that the Alertmanager URL in Prometheus’s config matches the actual endpoint, and that the
--web.listen-addressis correct.
PromQL Basics for Querying
PromQL is the query language that makes Prometheus powerful. You can use it in Grafana panels or directly in the Prometheus UI. A few essential concepts:
- Instant vector – a set of time series with a single value per series at the query time. Example:
node_cpu_seconds_total. - Range vector – a set of time series with a range of values over time. Example:
rate(node_cpu_seconds_total[5m])gives the per-second average rate over 5 minutes. - Aggregations –
sum(),avg(),max(),min()combine series. For example, total CPU usage across all cores:sum(rate(node_cpu_seconds_total{mode!="idle"}[5m])). - Comparison operators – you can build alert rules like
node_load1 > 4.
PromQL is not SQL; it is designed for time-series data. It is worth spending time learning the rate() and irate() functions, as they are central to most queries.
Costs and Resource Considerations
Prometheus itself is lightweight; the server binary uses modest CPU and memory. The main cost is storage and RAM for querying. For a small setup (a few hosts), you can run the stack on a single small VPS. For large setups, you need to consider:
- Disk space – each sample is about 1-2 bytes, but with many series and a short scrape interval, storage grows quickly. Use compression (enabled by default) and set a retention period.
- Memory – Prometheus holds data in memory for recent time ranges; queries over long periods can be memory-intensive.
- High availability – running two Prometheus instances in parallel is common, but they are not clustered; you need a separate component like Thanos for global view.
For a small to medium environment, the cost is negligible. For enterprise scale, you may need to budget for storage and additional components.
Security and Operational Best Practices
Because Prometheus scrapes over HTTP, you should protect the endpoints. Common practices:
- Authentication – use a reverse proxy (like nginx) with basic auth or OAuth2 for the Prometheus and Alertmanager web UIs.
- TLS – enable HTTPS for all components, especially if they are exposed to the internet. Use a certificate from a trusted CA.
- Network segmentation – keep exporters on internal networks; do not expose them publicly.
- Alertmanager security – Alertmanager can receive webhooks; ensure it is not publicly accessible without auth.
- Backup – Prometheus data is not a database you typically back up; instead, back up configuration files and use Thanos for long-term storage. If you must back up the TSDB, use
promtool snapshot.
Frequently Asked Questions
What is the difference between Prometheus and Grafana?
Prometheus is a time-series database and alerting engine; Grafana is a visualization tool that can query Prometheus (and many other data sources). Prometheus stores the data, Grafana displays it. You can use Grafana without Prometheus, but the Prometheus stack usually includes both.
Can I use Prometheus for logs?
No, Prometheus is designed for numeric metrics only. For logs, you need a separate system like Loki (which is often used alongside Prometheus and Grafana). The Prometheus stack does not handle log data.
How do I monitor a service that does not expose /metrics?
You can use an exporter that fetches data from the service and exposes it in Prometheus format. For example, if you have a Java application with JMX, use the JMX exporter. If no exporter exists, you can write a custom exporter in your language using the client libraries.
Is the Prometheus stack free?
Yes, all core components are open-source under the Apache 2.0 license. You can use them without a license fee. However, you may incur costs for hosting, storage, and support if you use a commercial service like Grafana Cloud.
What is the difference between Prometheus and InfluxDB?
Prometheus uses a pull model and is optimized for monitoring and alerting; InfluxDB uses a push model and is a general-purpose time-series database with a SQL-like query language. Prometheus is often preferred for Kubernetes and microservices monitoring; InfluxDB is more flexible for various time-series data.
How do I handle high availability for Prometheus?
Run two identical Prometheus servers scraping the same targets, and use a load balancer in front of them for queries. For alerting, you can run Alertmanager in a cluster. For long-term storage, add Thanos to deduplicate and store data in object storage.
Related
- Peg Oil and Gas: What It Is and How It Works
- Pegasus Airlines Address: HQ & Contact Info
- Pegasus Airlines Carry-On Baggage Allowance
How pages are sourced and corrected: Sources and editorial policy.