Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge zero values (vector(0) with metric values in PromQL

I'm using flexlm_exporter to export my license usage to Prometheus and from Prometheus to custom service (Not Graphana).

As you know Prometheus hides missing values.

However, I need those missing values in my metric values, therefore I added to my prom query or vector(0)

For example:

flexlm_feature_used_users{app="vendor_lic-server01",name="Temp"} or vector(0)

This query adds a empty metric with zero values.

My question is if there's a way to merge the zero vector with each metric values?

Edit:

I need grouping, at least for a user and name labels, so vector(0) is probably not the best option here? Example query with a specific user with missing values and zero vector

I tried multiple solutions in different StackOverflow threads, however, nothing works.

Please assist.

like image 949
Vibex Avatar asked Oct 15 '20 06:10

Vibex


1 Answers

It would help if you used Absent with labels to convert the value from 1 to zero, use clamp_max

( Metrics{label=“a”} OR clamp_max(absent(notExists{label=“a”}),0))
+
( Metrics2{label=“a”} OR clamp_max(absent(notExists{label=“a”}),0)

Vector(0) has no label.

clamp_max(Absent(notExists{label=“a”},0) is 0 with label.

like image 112
user2244652 Avatar answered Sep 22 '22 19:09

user2244652