Skip to content

Prometheus

Course: Prometheus and Grafana - chapter 2

Prometheus is a time series DB. It can monitor your

  1. Processes (node, go, rust…)
  2. Hosts

https://prometheus.io/docs/introduction/overview/

1. Multi-dimensional data model with time series data identified by metric name and key/value pairs

Section titled “1. Multi-dimensional data model with time series data identified by metric name and key/value pairs”

Prometheus stores its data in a time series format where each data point consists of:

  • Metric Name: A name that identifies the type of data, e.g., http_requests_total.
  • Labels (Key/Value Pairs): Additional metadata that further identifies and differentiates the time series, e.g., method="GET" and handler="/api". Labels provide a way to add dimensions to the metric data, allowing for flexible and detailed querying and analysis.

2. PromQL, a flexible query language to leverage this dimensionality

Section titled “2. PromQL, a flexible query language to leverage this dimensionality”

PromQL lets you query on top of all your timeseries data.

For example

sum(http_requests_total{job="api-server", status="500"})

would give you all the http requests that your server handled with status code 500

3. No reliance on distributed storage; single server nodes are autonomous

Section titled “3. No reliance on distributed storage; single server nodes are autonomous”

Prometheus is designed to be a standalone, single-node system that does not require external distributed storage solutions. Each Prometheus server node is autonomous, meaning it can independently scrape, store, and query time series data. This design simplifies the system architecture and operational overhead but also means that Prometheus is not inherently horizontally scalable. However sharding techniques can be used to manage larger deployments.

4. Time series collection happens via a pull model over HTTP

Section titled “4. Time series collection happens via a pull model over HTTP”

Prometheus primarily uses a pull model to collect metrics:

  • Pull Model: Prometheus periodically scrapes metrics from configured targets by making HTTP requests to the /metrics endpoint exposed by the targets. This approach allows Prometheus to control the scraping intervals and retry logic.
  • Targets expose their metrics in a specific format that Prometheus understands, typically using client libraries provided by Prometheus for various languages and environments.

5. Pushing time series is supported via an intermediary gateway

Section titled “5. Pushing time series is supported via an intermediary gateway”

While Prometheus generally uses a pull model, it also supports a push model through the Pushgateway:

  • Pushgateway: An intermediary service that allows applications and batch jobs to push metrics to it. The Pushgateway then exposes these metrics for Prometheus to scrape. This is useful for short-lived jobs or services that cannot be scraped reliably.

6. Targets are discovered via service discovery or static configuration

Section titled “6. Targets are discovered via service discovery or static configuration”

Prometheus supports multiple methods for discovering targets to scrape:

  • Service Discovery: Dynamically discovers targets using various service discovery mechanisms like Kubernetes, Consul, AWS, etc. This allows Prometheus to automatically update its target list as the environment changes.
  • Static Configuration: Manually specifies the list of targets in the configuration file. This is straightforward but less flexible compared to service discovery.

7. Multiple modes of graphing and dashboarding support

Section titled “7. Multiple modes of graphing and dashboarding support”

Prometheus offers several ways to visualize and interact with the collected metrics:

  • Prometheus UI: A built-in web interface for ad-hoc queries and simple graphing.
  • Grafana: A popular open-source dashboarding tool that integrates well with Prometheus, providing rich visualization and dashboarding capabilities.
  • **Alertmanager: **A component of the Prometheus ecosystem used to handle alerts generated by Prometheus queries, allowing for complex alerting rules and notification integrations.