14

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.

Vibex
  • 171
  • 1
  • 2
  • 8

4 Answers4

15

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.

user2244652
  • 211
  • 2
  • 6
  • Could this be leveraged to tackle multiple time series at the same time? I.e. if `Metrics{label=“a”}` returns multiple time series. – Mo Kanj Aug 28 '23 at 23:32
3

If you do sum(flexlm_feature_used_users{app="vendor_lic-server01",name="Temp"} or vector(0)) you should get what you're looking for, but you'll lose possibility to do group by, since vector(0) doesn't have any labels.

sskrlj
  • 199
  • 4
  • You right, but I need the grouping. So any other solution probably without vector(0), since I have to get at least user and name labels – Vibex Oct 15 '20 at 14:24
  • I think you should be able to manually add them with recording rules, but this could be painful, if the list of values is long and/or not fixed. But then it's better to find a way for metric to always contain a value, even when 0. – sskrlj Oct 15 '20 at 15:09
1

I needed a similar thing, and ended up flattening the options. What worked for me was something like:

(sum by xyz(flexlm_feature_used_users{app="vendor_lic-server01",name="Temp1"} + sum by xyz(flexlm_feature_used_users{app="vendor_lic-server01",name="Temp2"}) or

sum by xyz(flexlm_feature_used_users{app="vendor_lic-server01",name="Temp1"} or

sum by xyz(flexlm_feature_used_users{app="vendor_lic-server01",name="Temp2"}
AmerS
  • 88
  • 5
0

There is no an easy generic way to fill gaps in returned time series with zeroes in Prometheus. But this can be easily done via default operator in VictoriaMetrics:

flexlm_feature_used_users{app="vendor_lic-server01",name="Temp"} default 0

The q default N fills gaps with the given default value N per each time series returned from q. See more details in MetricsQL docs.

valyala
  • 11,669
  • 1
  • 59
  • 62