Division between two queries not working?

12 views
Skip to first unread message

Cole Beasley

unread,
Jun 30, 2020, 12:11:44 PM6/30/20
to Prometheus Users
Hi there,

This might be a very basic question but I'm trying to get the ration of error log messages / total error messages. Using grok_exporter I have the metric type_counter which returns 
ElementValue
type_counter{instance="localhost:9144",job="grok",log_type="AUTH"}45
type_counter{instance="localhost:9144",job="grok",log_type="ERROR"}55
type_counter{instance="localhost:9144",job="grok",log_type="IN"}17603
type_counter{instance="localhost:9144",job="grok",log_type="NESTED"}971

I simply then want (type_counter{log_type="ERROR"}) / (sum(type_counter)), but this does not return a value, this is odd to me as both type_counter{log_type="ERROR"} and sum(type_counter) return their expected values and will divide by themselves or manually entered integers (such as (18,000 / sum(type_counter)). I'm not sure why the division here is not working, any ideas?

Julius Volz

unread,
Jun 30, 2020, 1:06:11 PM6/30/20
to Cole Beasley, Prometheus Users
By default, binary operators match series from the left and right side on exactly identical label sets. But you keep the log_type label on the left, while aggregating it away on the right. You can either aggregate it away on both sides:

  sum(type_counter{log_type="ERROR"}) / sum(type_counter)

...or ignore that label for matching:

  type_counter{log_type="ERROR"} / ignoring(log_type) sum(type_counter)

Btw., I assume type_counter is a counter metric. You should typically never care about the absolute value of a counter metric and instead always rate(...) it (or increase(), etc.) before using.

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/c1b630e6-60de-42dd-aeab-51e57baf9dcdo%40googlegroups.com.


--
Julius Volz
PromLabs - promlabs.com

Cole Beasley

unread,
Jun 30, 2020, 2:08:03 PM6/30/20
to Prometheus Users
Awesome thanks for the help! Still learning the basics.


On Tuesday, June 30, 2020 at 11:06:11 AM UTC-6, Julius Volz wrote:
By default, binary operators match series from the left and right side on exactly identical label sets. But you keep the log_type label on the left, while aggregating it away on the right. You can either aggregate it away on both sides:

  sum(type_counter{log_type="ERROR"}) / sum(type_counter)

...or ignore that label for matching:

  type_counter{log_type="ERROR"} / ignoring(log_type) sum(type_counter)

Btw., I assume type_counter is a counter metric. You should typically never care about the absolute value of a counter metric and instead always rate(...) it (or increase(), etc.) before using.

On Tue, Jun 30, 2020 at 6:11 PM Cole Beasley <colebea...@gmail.com> wrote:
Hi there,

This might be a very basic question but I'm trying to get the ration of error log messages / total error messages. Using grok_exporter I have the metric type_counter which returns 
ElementValue
type_counter{instance="localhost:9144",job="grok",log_type="AUTH"}45
type_counter{instance="localhost:9144",job="grok",log_type="ERROR"}55
type_counter{instance="localhost:9144",job="grok",log_type="IN"}17603
type_counter{instance="localhost:9144",job="grok",log_type="NESTED"}971

I simply then want (type_counter{log_type="ERROR"}) / (sum(type_counter)), but this does not return a value, this is odd to me as both type_counter{log_type="ERROR"} and sum(type_counter) return their expected values and will divide by themselves or manually entered integers (such as (18,000 / sum(type_counter)). I'm not sure why the division here is not working, any ideas?

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to promethe...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages