
Prometheus
An open-source, systems monitoring and alerting toolkit designed for dynamic, multi-dimensional metric collection and analysis.
Descripción
Prometheus is an open-source, systems monitoring and alerting toolkit originally built at SoundCloud in 2012. It has since become a graduated project within the Cloud Native Computing Foundation (CNCF), second only to Kubernetes in terms of adoption and community size. Prometheus is designed to monitor highly dynamic, containerized environments, making it the de facto standard for Kubernetes observability.
Unlike traditional monitoring systems that rely on push-based agents sending metrics to a central collector, Prometheus primarily operates on a pull-based model. It actively scrapes HTTP endpoints exposed by target systems to retrieve metrics in a simple, plaintext format. This design simplifies client-side instrumentation and ensures that the monitoring system remains in control of its ingestion rate.
At its core, Prometheus features a custom-built, highly optimized time-series database (TSDB). It identifies metrics using a multi-dimensional data model, where every time series is uniquely defined by its metric name and a set of key-value pairs called labels. This approach allows for powerful, flexible querying using PromQL (Prometheus Query Language), enabling operators to slice and dice metric data across various dimensions such as service, environment, instance, or path.
Prometheus is built for reliability and operational independence. Each Prometheus server runs autonomously, relying only on local storage rather than distributed databases or external network services. This self-contained architecture ensures that Prometheus remains operational and capable of diagnosing outages even when the surrounding infrastructure is failing.
Arquitectura
The Prometheus ecosystem consists of several components, many of which are optional depending on the deployment scale. The central component is the Prometheus server itself, which is responsible for metric scraping, storage, and query execution.
The architecture operates through a well-defined lifecycle:
- Retrieval (Scraping): The Prometheus server discovers targets using built-in service discovery mechanisms (such as Kubernetes, Consul, AWS EC2, or DNS) or static configurations. At configured intervals (the scrape interval), the server sends HTTP GET requests to the /metrics endpoint of these targets. The targets respond with metrics formatted in the Prometheus exposition format, which is now standardized as OpenMetrics.
- Storage: Once retrieved, metrics are ingested into the local TSDB. The TSDB organizes data into two-hour blocks. Each block contains a metadata file, an index for rapid label-based lookups, and chunk files containing the actual raw sample data. To optimize disk space and I/O, Prometheus uses Gorilla compression, which compresses timestamps and floating-point values into highly compact bitstreams.
- Querying and Visualization: Users and external tools query the stored data using PromQL. Queries can be executed via the Prometheus expression browser, built-in APIs, or visualization platforms like Grafana.
- Alerting: Prometheus evaluates alerting rules (defined as PromQL expressions) at regular intervals. If an alert condition is met, the server does not send notifications directly. Instead, it dispatches the alert to the Alertmanager. The Alertmanager is a dedicated component that handles deduplication, grouping, silencing, inhibition, and routing of alerts to end-user receivers such as PagerDuty, Slack, email, or custom webhooks.
- Pushgateway: For short-lived, ephemeral jobs (such as batch cron jobs) that do not exist long enough to be scraped, Prometheus provides the Pushgateway. These jobs push their metrics to the Pushgateway, which caches them so the Prometheus server can scrape them later.
Ventajas
Prometheus offers several distinct advantages that make it highly effective for modern infrastructure monitoring:
- Multi-dimensional Data Model: The use of key-value labels to identify time series provides unparalleled flexibility. Instead of creating separate hierarchical metric names for every variation, engineers can define a single metric (e.g., httprequeststotal) and use labels (e.g., method="POST", handler="/api", status="200") to slice and dice the data dynamically.
- Powerful Query Language (PromQL): PromQL is specifically designed for time-series analysis. It supports nested expressions, vector arithmetic, aggregation across dimensions, rate calculations, and subqueries, allowing operators to construct complex queries and alerts with minimal syntax.
- Operational Simplicity: A basic Prometheus deployment requires no external database, clustering, or complex clustering coordination. It runs as a single binary with local storage, making it incredibly easy to deploy, maintain, and run even during catastrophic infrastructure failures.
- Extensive Service Discovery: Prometheus features native integration with major cloud providers, container orchestrators, and service registries. This allows it to automatically discover, scrape, and label new targets as they are provisioned or destroyed in dynamic environments.
- Rich Ecosystem and Integration: With hundreds of community-maintained exporters (e.g., Node Exporter, Blackbox Exporter, PostgreSQL Exporter), Prometheus can monitor almost any operating system, database, or network device without requiring custom instrumentation code.
Desventajas
While Prometheus is exceptionally powerful, it involves specific architectural trade-offs that limit its suitability for certain use cases:
- Single-Node Scaling Limits: By design, a single Prometheus server does not scale horizontally. It is limited by the CPU, memory, and disk I/O of the host machine it runs on. While vertical scaling can handle millions of active series, ultra-large deployments require complex architectural patterns like hierarchical federation or external long-term storage engines (e.g., Thanos, Cortex, or Mimir).
- Non-Durable Local Storage: The local TSDB is optimized for short-to-medium-term operational monitoring (typically 15 to 30 days). It is not designed to act as a durable, long-term data warehouse. For historical trend analysis spanning months or years, users must configure remote-write integrations to stream metrics to external distributed storage systems.
- Pull Model Constraints: The pull-based architecture requires Prometheus to have direct network access to the metrics endpoints of all targets. In highly segmented networks, across multiple firewalls, or in edge computing scenarios with transient connectivity, establishing these network paths can be challenging and require complex proxying or the use of Pushgateways.
- Lack of High Cardinality Support: Prometheus performance degrades significantly when dealing with high-cardinality labels (labels with a massive number of unique values, such as user IDs, IP addresses, or session tokens). High cardinality leads to memory exhaustion and slow query performance because each unique combination of labels creates a new time series in memory.
Casos de uso
Prometheus is highly optimized for specific operational scenarios:
- Kubernetes and Cloud-Native Environments: Due to its native service discovery and dynamic labeling, Prometheus is the ideal solution for monitoring Kubernetes clusters, microservices, and auto-scaling cloud infrastructure.
- Real-Time Operational Alerting: Prometheus excels at detecting active system anomalies, service degradations, and infrastructure failures. Its fast scrape intervals and robust alerting pipeline ensure that SRE teams are notified of issues within seconds.
- White-Box Monitoring: It is highly suited for application-level monitoring where developers instrument their own code using Prometheus client libraries (Go, Java, Python, Rust, etc.) to expose internal application metrics like queue depths, request latencies, and active database connections.
- Infrastructure Performance Analysis: Monitoring system-level metrics (CPU, memory, disk, network) across thousands of virtual machines or bare-metal servers using the Node Exporter.
Cuándo NO usarlo
Prometheus should not be used as a general-purpose data platform. Avoid it in the following scenarios:
- Billing and Auditing: Prometheus is designed for operational monitoring and uses an approximation-friendly, lossy data model. Scrapes can fail, and data points may be dropped or interpolated. It should never be used for financial billing, audit logs, or any application where 100% transactional accuracy is required.
- High-Cardinality User Tracking: Do not use Prometheus to track individual user behavior, session IDs, or transaction hashes. Doing so will explode the TSDB index, exhaust memory, and crash the Prometheus server. Use dedicated analytics databases or log management systems for this purpose.
- Long-Term Historical Archiving: If your primary goal is to store years of raw metrics for business intelligence or capacity planning without using external storage integrations, Prometheus's local storage is inappropriate.
- Non-Metric Observability: Prometheus is strictly a metrics engine. It does not ingest, index, or query structured logs, distributed traces, or profiling data. For those signals, look to dedicated tools like OpenTelemetry, Grafana Loki, or Jaeger.