Saturday, 24 May 2025

Quick Introduction to Prometheus Data Types

 

Prometheus is a powerful open-source monitoring and alerting toolkit. Whether you're tracking how many users visited your website or monitoring server health, Prometheus helps you to collect and analyze metrics over time. But before diving deep into PromQL (Prometheus Query Language), it’s important to understand the four core data types Prometheus works with.

 

1. First, What Is a Time Series?

A time series in Prometheus is a metric (like CPU usage or request count) that is tracked over time. Each time series is identified by:

 

·      A metric name (like http_requests_total)

·      A set of labels (like {method="GET", handler="/home"})

 

Each time series stores:

 

·      A timestamp

·      A value

·      Set of labels

 

Timestamp

Value

Labels

2025-04-11 10:00

124

{code="200", handler="/", instance="localhost:9090", job="prometheus"}

2025-04-11 10:00

34

{code="200", handler="/classic/static/*filepath", instance="localhost:9090", job="prometheus"}

2025-04-11 10:00

65

{code="200", handler="/version", instance="localhost:9090", job="prometheus"}

2025-04-11 10:00

79

{code="200", handler="/api/v1/admin/tsdb/clean_tombstones", instance="localhost:9090", job="prometheus"}

 

2. Data Types in Prometheus

 

2.1 Instant Vector

An Instant Vector is a snapshot of one or more time series at a single point in time.

 

For example, You have a microservices-based application with 3 services:

 

·      auth-service

·      user-service

·      payment-service

 

Each of these services exposes a Prometheus metric:

prometheus_http_requests_total

This metric counts the total number of HTTP requests handled by each service, broken down by method (GET, POST) and route (/login, /user, /pay, etc.).

 

At exactly 10:00 AM, Prometheus scrapes the metrics and you get:

 

Service

Method

Route

Total Requests

auth-service

POST

/login

4,521

user-service

GET

/profile

123

payment-service

POST

/pay

8675

 

Each row is a time series, and all values share the same timestamp (10:00 AM).

 


You can even get the metrics for a given handler like below.

 

prometheus_http_requests_total{handler="/metrics"} 

 


2.2 Range Vector

A Range Vector is a set of time series where each series contains multiple data points, all within a specific time range (like the last 5 minutes).

 

Let’s say you’re tracking HTTP requests across 3 microservices:

 

·      auth-service

·      user-service

·      payment-service

 

You're interested in how many requests each service received over the last 5 minutes, and how fast that number is increasing. Prometheus scrapes data every 15 seconds, so over 5 minutes, you’ll get 20 data points per time series.

 

Example PromQL:

prometheus_http_requests_total[5m]

 

This query gives you:

·      All request counter values for the last 5 minutes

 

·      For every combination of route, method, and service (i.e., time series)

 

You can’t plot this directly on a dashboard, but it’s super useful when combined with a function like rate().

 


You can filter out for a given handler for 5 minutes duration like below:

 

prometheus_http_requests_total{handler="/metrics"}[5m]

 


Prometheus scrapes data every 15 seconds as per my system configuration, so over 5 minutes, you’ll get 20 data points per time series.

 

2.3 Scalar: A Scalar is just a single numeric value (a floating-point number) with no labels or time series context.

 

Just the number 5.67 floating in space — that’s a scalar.

 

For example,

5 * rate(prometheus_http_requests_total{handler="/metrics"}[5m])

 

Here, 5 is a scalar multiplying a range vector result.

 


2.4 String: A String in Prometheus is a simple text value. However, Prometheus doesn’t really use strings in most queries.

 

In summary, understanding data types in Prometheus is key to writing effective queries.

·      Use instant vectors for current values.

·      Use range vectors to analyze trends over time.

·      Use scalars for math and logic.

·      Ignore strings unless you're deep into Prometheus internals.

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment