Adding two values in Prometheus

1/16/2020

We need to add results of two queries in Prometheus. Snippet is below:

(probe_ssl_earliest_cert_expiry{job="SSL-expiry"} - time() < 86400 * 738 )*1000 + (node_time_seconds*1000)

but the result says no data as shown below:

enter image description here

-- Navneet Nandan Jha
kubernetes
monitoring
performance
prometheus
prometheus-blackbox-exporter

1 Answer

1/16/2020

You will get an empty result if the metrics do not match. The reason is that for binary operator vector1 <op> vector2

vector1 and vector2 results in a vector consisting of the elements of vector1 for which there are elements in vector2 with exactly matching label sets. Other elements are dropped.

You must at least add a on() or ignoring() vector matching keyword specifying the labels (names) on which the (name and) value match. You may have to add grouping instruction if you have one to many matching.

Fill the ??? in the following expression such that label match:

(probe_ssl_earliest_cert_expiry{job="SSL-expiry"} - time() < 86400 * 738 )*1000 + ON(???) (node_time_seconds*1000)
-- Michael Doubez
Source: StackOverflow