Brian, even better - great.

Now that you mentioned how count() returns no labels - it relates to
another alert rule I was trying to implement.
If I wanted to alert anytime a counter is incremented (and have it self
resolve after x time), this seems to do it:

*count(exception_total) - count(exception_total offset 1h) *
{}   0

above returns a zero value when it has been incremented but no labels or
useful results otherwise, but this other query I happened upon returns
labels and I don't understand why

*exception_total unless exception_total offset 1h*

exception_total{pod="x"} 1
exception_total{pod="y"} 1
exception_total{pod="z"} 1



--
Dan



On Mon, Oct 4, 2021 at 7:02 PM Brian Candler <[email protected]> wrote:

> count() returns no labels, and it also returns no timeseries when it has
> no input (rather than a timeseries with value zero, which I had naïvely
> expected).  So this is simpler again:
>
> absent(jenkins_up) and count(up{job="jenkins"})
>
> On Monday, 4 October 2021 at 15:29:14 UTC+1 Dan S wrote:
>
>> Thanks Brian for the advice! I found the `absent() and absent()` seemed
>> to work well.
>>
>> Also Ben - thank you - I did take your advice as well re: making multiple
>> layers of alerts, and didn't know about 
>> prometheus_target_scrape_pool_targets,
>> which could be useful in other ways as well.
>>
>> Appreciate it!
>>
>> Dan
>>
>>
>> On Mon, Oct 4, 2021 at 5:07 PM Brian Candler <[email protected]> wrote:
>>
>>> On Sunday, 3 October 2021 at 22:50:59 UTC+1 [email protected] wrote:
>>>
>>>> Trying to manipulate alerts with absent() tends to behave badly.
>>>>
>>>
>>> Aside: I found it a bit surprising at first that count() and sum()
>>> across an empty instant vector give an empty result, rather than 0.  I
>>> don't see that behaviour explicitly called out here
>>> <https://prometheus.io/docs/prometheus/latest/querying/operators/#aggregation-operators>,
>>> but I guess it makes sense when you think about what "count by", "sum by"
>>> or "count_values" would have to do, when given no input.
>>>
>>> You can of course make it work the other way if required: e.g.
>>> "count(foo) or vector(0)"
>>>
>>> --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "Prometheus Users" group.
>>> To unsubscribe from this topic, visit
>>> https://groups.google.com/d/topic/prometheus-users/gi8GtrBMMMk/unsubscribe
>>> .
>>> To unsubscribe from this group and all its topics, send an email to
>>> [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/prometheus-users/4adf9702-adbc-43be-837e-794c6e009d2bn%40googlegroups.com
>>> <https://groups.google.com/d/msgid/prometheus-users/4adf9702-adbc-43be-837e-794c6e009d2bn%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Prometheus Users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/prometheus-users/gi8GtrBMMMk/unsubscribe
> .
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/prometheus-users/da11741e-52c5-4cf4-baa3-deb3daed7b38n%40googlegroups.com
> <https://groups.google.com/d/msgid/prometheus-users/da11741e-52c5-4cf4-baa3-deb3daed7b38n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-users/CAOdST49PEh4vy2Z40cJLdyQfr6qxu-MNT0dbjsSmbaouPSjWhw%40mail.gmail.com.

Reply via email to