Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 14

Monitoring with

Prometheus

by Sujoy Kundu

| Sujoy K | 2023-05-25 | Ericsson Internal | Page 1 of 14


Why Prometheus?
Prometheus is an open-source tool used for metrics-based monitoring and alerting.

● Most monitoring systems use a pushing mechanism where clients (applications /servers) are responsible
for pushing their metric data to a centralized collection platform (server). In contrast to a “push”
mechanic system, Prometheus is relying on targets (applications/servers) providing simple HTTP
endpoints that its data retrieval workers can pull/scrape from.

● Prometheus is a very powerful monitoring system, designed from the ground up to support and work
with dynamic environments. Prometheus has gained a reputation as the de facto monitoring software in
recent times. Its ease of use, versatility and literally endless integration options make it a favorite in the
monitoring and alerting world.

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

| Sujoy K | 2023-05-25 | Ericsson Internal | Page 2 of 14


Prometheus — Overview
• Multidimensional data model: Support for structured time series metrics and ability to represent
complex data types , so that data can be sliced and diced at will, along dimensions like instance, cluster,
endpoint, and namespaces etc.
• PromQL: Native Domain Specific Language (DSL) for querying multidimensional data
• Multiple metrics types: Support for various metric types, e.g., counters for monotonically increasing
metrics, gauges (single numerical values), histograms, and summaries
• Web UI allows to access, visualize, and chart the stored data. Prometheus provides its own UI, but other
visualization tools, like Grafana can be configured , to access the Prometheus server using PromQL (the
Prometheus Query Language).
• Alert management: Built-in alert manager that can be configured to send alerts in response to certain
metrics (e.g., low storage, low memory, network problem)

| Sujoy K | 2023-05-25 | Ericsson Internal | Page 3 of 14


Prometheus Components and
Architecture

| Sujoy K | 2023-05-25 | Ericsson Internal | Page 4 of 14


Prometheus Components and
Architecture
● Prometheus Server : The Prometheus server handles the scraping and storing of metrics.
The server manages scheduling of monitoring jobs – querying data sources (called
“instances”) at a predefined polling frequency. Monitoring jobs are configured via one or more
“scrape config” directives, managed via a YAML configuration file
● Prometheus Exporters (Targets) : A Prometheus Exporter is a piece of software that
– Can fetch statistics from another, non-Prometheus system
– Can turn those statistics into Prometheus metrics, using a client library
– Starts a web server that exposes a /metrics URL, and have that URL display the
system metrics
Primary method of data collection is scraping metrics (Query ) list of data sources (sometimes
called exporters) at a specific polling frequency (Scrape – Interval) , which expose metrics in a
plaintext format via HTTP endpoints.
● PromQL : Prometheus collects data in the form of time series. Prometheus stores the scraped
data, which you can analyze with the Prometheus Query Language (PromQL).
| Sujoy K | 2023-05-25 | Ericsson Internal | Page 5 of 14
Prometheus Components and
Architecture
● Prometheus Push Gateway : is available for pushing metrics from external applications and
services. It is useful for collecting metrics from systems that are not compatible with the pull-
based infrastructure. For instance, short-lived batch jobs that are ephemeral in nature may
start and end before Prometheus can discover and scrape metrics from them. It can be used
to push the metrics of such processes to prevent losing essential data before they get a
chance to get scraped.
● Prometheus Alertmanager : The Alertmanager handles alerts sent by client applications
such as the Prometheus server. In practice, the Prometheus server generates alerts when an
alert condition is met in a user-defined alerting rule.
Prometheus alerting is separated into two parts : Alerting rules and Alert processing . Alerting
rules are PromQL expressions that are evaluated at regular intervals by the Prometheus
server.
● Prometheus Visualizations : To create a series of dashboards in Grafana to display system
metrics. Grafana transforms metrics into meaningful visualizations.
| Sujoy K | 2023-05-25 | Ericsson Internal | Page 6 of 14
Prometheus Configuration
● Scrape_intervals : Prometheus collects metrics via a pull model over HTTP. The targets from which you
want to pull metrics can be specified in the global Prometheus configuration file under
the scrape_config section

| Sujoy K | 2023-05-25 | Ericsson Internal | Page 7 of 14


Prometheus Configuration
relabel_configs : The Prometheus relabel_configs you see in the example above allows you to relabel
default Kubernetes labels into labels you wish to refer to in your time series database and PromQL
queries.

Reference : https://grafana.com/blog/2022/03/21/how-relabeling-in-prometheus-works/
Scrape_Configs : Expose a metrics endpoint on your application server and let Prometheus know about
it. is providing a static target for your application server, as seen in the example below. This static
configuration approach mentioned below , where the metrics are collected on the specified endpoint.

| Sujoy K | 2023-05-25 | Ericsson Internal | Page 8 of 14


PromQL Basics : Data Types
PromQL, short for Prometheus Querying Language, is the main way to query metrics within Prometheus.
● Data types : Prometheus uses three data types for metrics: the scalar, the instant vector, and the range vector
 Scalar (Floats) : Examples of scalars include 0, 18.12, and 1000000.
 Instant Vector : When we group together scalars as a set of metrics in a single point in time, we
get the instant vector data type. When you run a query asking for only the name of a metric, such
as bicycle_distance_meters_total, the response is an instant vector because metrics have both
names and labels
 Range Vector : An array of vectors over time gives you the range vector. Syntactically, we get a
range vector when you query an instant vector and append a time selector such as [5m]. The
simplest range vector query is an instant vector with a time selector, such as
bicycle_distance_meters_total[5m]

| Sujoy K | 2023-05-25 | Ericsson Internal | Page 9 of 14


PromQL Basics : Labels

● Labels :
Some earlier metric systems had only the metric name for distinguishing different metrics from
each other. This means that you might end up with metric names such as
bicycle.distance.meters.monark.7 to distinguish a 7-geared Monark bicycle from a 2-geared
Brompton bicycle (bicycle.distance.meters.brompton.2). In Prometheus, we use labels for that. A
label is written after the metric name in the format {label=value}.

This means that our previous two bikes are rewritten as


bicycle_distance_meters_total{brand="monark",gears="7"} and
bicycle_distance_meters_total{brand="brompton",gears="2"}.

| Sujoy K | 2023-05-25 | Ericsson Internal | Page 10 of 14


PromQL Basics : Data Types
1. Counters
2. Gauges
3. Histograms
4. Summaries

Counter and Gauge are basic metric types, both of which store a scalar. A counter always counts up (a
reset to zero can happen on restart) compared to a gauge, which can go both up and down.
bicycle_distance_meters_total is a counter since the number of kilometers a bike has traveled cannot
decrease, whereas bicycle_speed_meters_per_second would have to be a gauge to allow for decreased
speeds.
Histogram and Summaries are used less , can be studies in
https://grafana.com/blog/2020/02/04/introduction-to-promql-the-prometheus-query-language/

| Sujoy K | 2023-05-25 | Ericsson Internal | Page 11 of 14


PromQL Operators and Functions

Prometheus supports a large number of functions, aggregation operators, and


binary operators. Details are covered in below link
● https://logz.io/blog/promql-examples-introduction/#oper
Read More about Prom QL
• Prometheus Querying Basics
• Prometheus Querying Operators
• Prometheus Metric Types
• Prometheus Histogram and Summaries
• Prometheus Functions

| Sujoy K | 2023-05-25 | Ericsson Internal | Page 12 of 14


Additional Resources for Further Study
and Hands-On
● Prometheus Documentation :
https://prometheus.io/docs/tutorials/getting_started/#
● Monitoring with Prometheus :
https://opensource.com/article/19/11/introduction-monitoring-prometheus
● Prometheus Basics : Github :
https://github.com/yolossn/Prometheus-Basics
● Prometheus Video Tutorial :
https://youtube.com/playlist?list=PLdsu0umqbb8NxUs8r8BIUe9-PhcoZyojA
● Prometheus Udemy Course: Prometheus | The Complete Hands-On for Monitoring & Alerting
https://www.udemy.com/course/prometheus-course/
● Prometheus Cheatsheets: https://blog.ruanbekker.com/cheatsheets/prometheus/
| Sujoy K | 2023-05-25 | Ericsson Internal | Page 13 of 14

You might also like