Prometheus

How do you join two metrics?

Difficulty: unrated

Source: bregman-arie/devops-exercises by Arie Bregman

Answer

In Prometheus, joining two metrics can be achieved using the join() function. The join() function combines two or more time series based on their label values. It takes two mandatory arguments: on and table. The on argument specifies the labels to join on and the table argument specifies the time series to join.

Here's an example of how to join two metrics using the join() function:

sum_series(
  join(
    on(service, instance) request_count_total,
    on(service, instance) error_count_total,
  )
)

In this example, the join() function combines the request_count_total and error_count_total time series based on their service and instance label values. The sum_series() function then calculates the sum of the resulting time series