> For the complete documentation index, see [llms.txt](https://kdongs.gitbook.io/kdocs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kdongs.gitbook.io/kdocs/prometheus/prometheus.md).

# Prometheus

## [About](https://prometheus.io/docs/introduction/overview/)

Power your metrics and alerting with a leading open-source monitoring solution.

{% hint style="warning" %}
Most Prometheus components are written in `Go`, making them easy to build and deploy as static binaries.
{% endhint %}

{% hint style="success" %}
**Use it in:**

Prometheus works well for recording any purely numeric time series. IT fits both machine-centric as well as monitoring of highly dynamic service-oriented architectures.

It is designed for reliability, each server is standalone, not depending on network storage or other remote services.

No need to setup extensive infrastructure to use it.
{% endhint %}

{% hint style="danger" %}
**Doesn't fit when:**

If you need 100% accuracy , such as per-request billing, as the collected data will likely not be detailed and complete enough.
{% endhint %}

### Features

* Multi-dimensional data model with time series data identified by metric name and key/value pairs, making it a powerful tool for data collection.
* `PromQL` a flexible query language to leverage this dimensionality and create powerful prompts.
* Efficient storage, no reliance on distributed storage; single server nodes are autonomous.
* Easy integration with Grafana and other clients. *(Despite being a powerful tool, Prometheus don't have visual display of its data)*
* Intelligent alert system.

### Components

The Prometheus ecosystem consist of multiple components:

* The main, Prometheus server which scrapes and stores time series data.
* [Client libraries](https://prometheus.io/docs/instrumenting/clientlibs/) for instrumenting application code.
* A push gateway for supporting short-lived jobs.
* Special-purpose [exporters](https://prometheus.io/docs/instrumenting/exporters/) for services.
* An alert-manager to handle alerts.
* Other support tools.

## Architecture

<figure><img src="https://570189390-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0FF6Csa8c9LPIzD1clfK%2Fuploads%2FbXVkrK7rylhgCZPPmaww%2Farchitecture.png?alt=media&amp;token=c2d5042d-5dde-4cfe-b7aa-25dd9a917264" alt=""><figcaption><p><a href="https://prometheus.io/assets/architecture.png">https://prometheus.io/assets/architecture.png</a></p></figcaption></figure>

Prometheus scrapes metrics from instrumented jobs, either directly or via an intermediary push gateway for short-lived jobs.

It stores all scraped samples locally and runs rules over this data to either aggregate and record new time series from existing data or generate alerts.

Grafana or other API consumers can be used to visualize the collected data.

### [Prometheus Server](https://prometheus.io/docs/prometheus/latest/getting_started/)

#### Retrieval

The component that receives all the information from outside.

#### TSDB (Time series Database)

The component that stores all information with a time series format.

Data storage changes with time.

Recent data is more precise than old data.

#### HTTP server

An internal HTTP server, by which it can monitor itself, and to make all the data available to the outside.

{% hint style="warning" %}
Also, access the Web Server to see target jobs and other useful Prometheus configurations.
{% endhint %}

### Service Discovery

Prometheus can have access and communicate with `Service Discoveries`, to find new targets to monitor. *(for instance when you have dynamic architectures where nodes are added and deleted due to auto-scaling)*

### [Pushgateway](https://prometheus.io/docs/instrumenting/pushing/)

For services or applications that are not working all the time. *(Ex.: An application available only once a day at a specific time)*

To avoid Prometheus to keep trying to pull unecessarily the metrics from this job directly, the job push the metrics and data to the Pushgateway, and the Pushgateway "stores" this data.

{% hint style="info" %}
So, the Pushgateway can be used for services that don't need to produce useful metrics all the time.
{% endhint %}

### [Exporters](https://prometheus.io/docs/instrumenting/exporters/)

Useful for generating metrics over thid-party software *(that you don't have access to)*.

<img src="https://570189390-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0FF6Csa8c9LPIzD1clfK%2Fuploads%2Fz4J1USNUMbyRSKR3MJDO%2Ffile.excalidraw.svg?alt=media&amp;token=7b43b502-e751-4411-9ba7-1876f1e795d3" alt="" class="gitbook-drawing">

{% hint style="info" %}
You can build your own Exporter if needed.
{% endhint %}

### [Alertmanager](https://prometheus.io/docs/alerting/latest/overview/)

The Alertmanager hits the Prometheus Server's Http server to get the required data for the alerts to work.

## Metrics

The Prometheus client libraries offer four core metric types.

### Counter

A metric with an incremental (cumulative) value.

It can only increase or be reset to zero on restarts.

{% hint style="danger" %}
Do not use Counter to expose a value that can decrease.

*Ex.: For the number of currently running processes;*
{% endhint %}

### Gauge

It is a metric that represents a single numerical value that can arbitrarily go up and down.

*Ex.: Like mesuraments of memory usage, temperatures, etc.*

### [Histrogram](https://prometheus.io/docs/concepts/metric_types/#histogram)

A *histogram* **samples observations** (usually things like request durations or response sizes) and counts them in configurable buckets. It also provides a sum of all observed values.

Useful for **frequency distribution**.

### [Summary](https://prometheus.io/docs/concepts/metric_types/#summary)

Similar to a *histogram*, a *summary* samples observations (usually things like request durations and response sizes).&#x20;

While it also provides a total count of observations and a sum of all observed values, it calculates configurable quantiles over a sliding time window.

## [PromQL](https://prometheus.io/docs/prometheus/latest/querying/basics/)

{% hint style="info" %}
The documentation is kind of weak, but Grafana for instance has really good auto complete for Prometheus queries.
{% endhint %}
