Prometheus Concepts: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(35 intermediate revisions by the same user not shown)
Line 8: Line 8:


=Target=
=Target=
Prometheus will monitor targets. A target can be a server, database, virtual machine, etc. Different targets can have different [[#Pull_Rate|pull rates]]. Targets can be discovered dynamically with [[#Service_Discovery|service discovery]].
Prometheus will monitor targets. They are also sometimes referred to as "resources". A target can be a server, database, virtual machine, etc. Different targets can have different [[#Pull_Rate|pull rates]]. Targets can be discovered dynamically with [[#Service_Discovery|service discovery]].
=Instance=
=Job=


=Pull vs. Push=
=Pull vs. Push=
Line 24: Line 22:
Prometheus pulls metrics from instrumented applications. An instrumented application exposes Prometheus metrics on a given URL. Such an application will be identified by Prometheus as a [[#Target|target]] and scrapped at regular periods.
Prometheus pulls metrics from instrumented applications. An instrumented application exposes Prometheus metrics on a given URL. Such an application will be identified by Prometheus as a [[#Target|target]] and scrapped at regular periods.
==Exporters==
==Exporters==
An alternative are prebuilt exporters. Examples: node exporter, SQL exporter, HAProxy exporter. The exporters are usually exposed as Docker images, and can be configured to monitor existing [[#Target|targets]].
An alternative are prebuilt exporters. Examples: node exporter, SQL exporter, HAProxy exporter. The exporters are usually exposed as Docker images, and can be configured to monitor existing [[#Target|targets]]. Available exporters:
===Node Exporter===
{{Internal|Prometheus Node Exporter|Node Exporter}}


==Push Gateway==
==Pushgateway==
Push gateways are used in case of applications or short-lived jobs that do not export metrics directly.
Push gateways are used in case of applications or short-lived jobs that do not export metrics directly.
{{Internal|Prometheus Pushgateway|Pushgateway}}


=Storage=
=Storage=
{{External|https://prometheus.io/docs/prometheus/latest/storage/}}
{{External|https://github.com/prometheus-operator/prometheus-operator/blob/master/Documentation/user-guides/storage.md}}
By default, the prometheus container stores metrics on an [[Kubernetes_Storage_Concepts#emptyDir|emtpyDir]] volume named "prometheus-prometheus-kube-prometheus-prometheus-db" mounted in /prometheus in the container.
=Alertmanager=
=Alertmanager=
Prometheus pushes alerts to Alertmanager via custom rules defined in its configuration files.
Prometheus pushes alerts to Alertmanager via custom rules defined in its configuration files.
Line 36: Line 41:
=Metrics=
=Metrics=


A Prometheus metric is a key/value pair plus a set of labels, commonly referred to as metadata. The key is the name of the metric. The value is a float numerical value.
A Prometheus metric is a key/value pair plus a set of labels, commonly referred to as metadata. The key is the [[#Name|name]] of the metric. The value is a float numerical value.
<syntaxhighlight lang='text'>
<syntaxhighlight lang='text'>
cpu_usage{core="1",ip="127.0.01"} 14.04
cpu_usage{core="1",ip="127.0.01"} 14.04
</syntaxhighlight>
Also see: {{Internal|Monitoring_Concepts#Metric|Monitoring Concepts &#124; Metrics}}
<font color=darkgray>
TODO:
* https://prometheus.io/docs/concepts/data_model/
* https://prometheus.io/docs/instrumenting/exposition_formats/
</font>
==<span id='Name'></span>Metric Name==
==Sample==
Also see [[#Instant_Vector|instant vector]]
==Series==
Series can be queried at the /api/v1/series endpoint.
===Data Types used in Queries===
====Instant Vector====
A set of time series containing a simple [[#Sample|sample]] for each time series, all sharing the same timestamp. More: {{Internal|PromQL#Instant_Vector|PromQL &#124; Instant Vector}}
====Range Vector====
A set of time series containing a range of data points over time for each series. More: {{Internal|PromQL#Range_Vector|PromQL &#124; Range Vector}}
====Scalar====
A simple numeric floating point value. More: {{Internal|PromQL#Scalar|PromQL &#124; Scalar}}
====String====
A simple string value. More: {{Internal|PromQL#String|PromQL &#124; String}}
==Labels==
===Job===
Prometheus server will attach "job" and "instance" labels to each metric:
<syntaxhighlight lang='text'>
go_threads{job="coredns",instance="10.1.0.9:9153",namespace="kube-system",pod="coredns-66bff467f8-pwz6r",container="coredns",...}
</syntaxhighlight>
===Instance===
Prometheus server will attach "job" and "instance" labels to each metric:
<syntaxhighlight lang='text'>
go_threads{job="coredns",instance="10.1.0.9:9153",namespace="kube-system",pod="coredns-66bff467f8-pwz6r",container="coredns",...}
</syntaxhighlight>
</syntaxhighlight>


Also see: {{Internal|Monitoring_Concepts#Metric|Monitoring Concepts &#124; Metrics}}
==Metric Types==
==Metric Types==
===Counter===
===Counter===
Line 49: Line 89:
===Histogram===
===Histogram===
===Summary===
===Summary===
==Prometheus Format==
{{External|https://prometheus.io/docs/instrumenting/exposition_formats/}}
The Prometheus format is structured plain text.
=PromQL=
=PromQL=
Vectors. Instant vectors. Time ranged vectors.
{{Internal|PromQL|PromQL}}
 
=Configuration=
=Configuration=
Prometheus is configured in a prometheus.yaml configuration file:
{{Internal|Prometheus Configuration|Configuration}}
<syntaxhighlight lang='yaml'>
=Prometheus Console=
global:
Prometheus comes with a built-in console that allows performing metric queries and inspecting configuration. When Prometheus is deployed in Kubernetes and on some Kubernetes instances, such as Docker Desktop Kubernetes, access to console must be enabled explicitly by [[Prometheus_Operations#Expose_Prometheus_Console_in_Kubernetes|deploying a LoadBalancer service]].  
  scrape_interval: 15s
 
  evaluation_interval: 15s
Server configuration can be viewed with Status → Configuration.
rule_files:
 
  # - "first.rules"
=Prometheus Operator=
  # - "second.rules"
{{Internal|Prometheus Operator Concepts|Prometheus Operator Concepts}}
scrape_configs:
=Prometheus Adapter for Kubernetes Metrics APIs=
  - job_name: prometheus
{{Internal|Prometheus Adapter for Kubernetes Metrics APIs|Prometheus Adapter for Kubernetes Metrics APIs}}
    static_configs:
      - targets: ['localhost:9090']
</syntaxhighlight>

Latest revision as of 02:09, 17 October 2020

External

Internal

Overview

Prometheus is a time series database plus tools to collect metrics to be stored in the database as aggregated metrics. Prometheus is a solution for system monitoring. It is not designed to catch individual events in time (such as a service outage) but it is designed to gather aggregated metrics about services. Prometheus is not designed to store raw information, such as text. Prometheus provides alerting capabilities with Alertmanager. Prometheus has some built-in visualization capabilities, but Grafana can also be used.

Target

Prometheus will monitor targets. They are also sometimes referred to as "resources". A target can be a server, database, virtual machine, etc. Different targets can have different pull rates. Targets can be discovered dynamically with service discovery.

Pull vs. Push

Prometheus will actively pull (scrap) metrics, by connecting to targets. The retrieval is done by invoking HTTP into endpoints, which are defined in the configuration.

Advantages of pull vs. push:

  • Centralized control - the configuration is done on Prometheus and not on individual targets.
  • Adjustable pull rate - the system has control over pull rate, and avoids being overloaded.

Pull Rate

Sources of Metrics

Instrumented Applications

Prometheus pulls metrics from instrumented applications. An instrumented application exposes Prometheus metrics on a given URL. Such an application will be identified by Prometheus as a target and scrapped at regular periods.

Exporters

An alternative are prebuilt exporters. Examples: node exporter, SQL exporter, HAProxy exporter. The exporters are usually exposed as Docker images, and can be configured to monitor existing targets. Available exporters:

Node Exporter

Node Exporter

Pushgateway

Push gateways are used in case of applications or short-lived jobs that do not export metrics directly.

Pushgateway

Storage

https://prometheus.io/docs/prometheus/latest/storage/
https://github.com/prometheus-operator/prometheus-operator/blob/master/Documentation/user-guides/storage.md

By default, the prometheus container stores metrics on an emtpyDir volume named "prometheus-prometheus-kube-prometheus-prometheus-db" mounted in /prometheus in the container.

Alertmanager

Prometheus pushes alerts to Alertmanager via custom rules defined in its configuration files.

Service Discovery

Prometheus can discover targets dynamically.

Metrics

A Prometheus metric is a key/value pair plus a set of labels, commonly referred to as metadata. The key is the name of the metric. The value is a float numerical value.

cpu_usage{core="1",ip="127.0.01"} 14.04

Also see:

Monitoring Concepts | Metrics

TODO:

Metric Name

Sample

Also see instant vector

Series

Series can be queried at the /api/v1/series endpoint.

Data Types used in Queries

Instant Vector

A set of time series containing a simple sample for each time series, all sharing the same timestamp. More:

PromQL | Instant Vector

Range Vector

A set of time series containing a range of data points over time for each series. More:

PromQL | Range Vector

Scalar

A simple numeric floating point value. More:

PromQL | Scalar

String

A simple string value. More:

PromQL | String

Labels

Job

Prometheus server will attach "job" and "instance" labels to each metric:

go_threads{job="coredns",instance="10.1.0.9:9153",namespace="kube-system",pod="coredns-66bff467f8-pwz6r",container="coredns",...}

Instance

Prometheus server will attach "job" and "instance" labels to each metric:

go_threads{job="coredns",instance="10.1.0.9:9153",namespace="kube-system",pod="coredns-66bff467f8-pwz6r",container="coredns",...}

Metric Types

Counter

A counter counts elements over time. A counter is a monotonically increasing positive value. A counter can only go up or can be reset. It must never decrease.

Gauge

A gauge measures values that can go up and down.

Histogram

Summary

Prometheus Format

https://prometheus.io/docs/instrumenting/exposition_formats/

The Prometheus format is structured plain text.

PromQL

PromQL

Configuration

Configuration

Prometheus Console

Prometheus comes with a built-in console that allows performing metric queries and inspecting configuration. When Prometheus is deployed in Kubernetes and on some Kubernetes instances, such as Docker Desktop Kubernetes, access to console must be enabled explicitly by deploying a LoadBalancer service.

Server configuration can be viewed with Status → Configuration.

Prometheus Operator

Prometheus Operator Concepts

Prometheus Adapter for Kubernetes Metrics APIs

Prometheus Adapter for Kubernetes Metrics APIs