Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

result of a count() on a query that returns nothing should be 0 ? #2286

Closed
zerthimon opened this Issue Dec 15, 2016 · 8 comments

Comments

Projects
None yet
7 participants
@zerthimon
Copy link

zerthimon commented Dec 15, 2016

What did you do?
count(container_last_seen{name="container_that_doesn't_exist"})

What did you expect to see?
0

What did you see instead? Under which circumstances?
"no data"

@brian-brazil

This comment has been minimized.

Copy link
Member

brian-brazil commented Dec 15, 2016

This is correct. You're probably looking for the absent function.

@zerthimon

This comment has been minimized.

Copy link
Author

zerthimon commented Dec 15, 2016

@brian-brazil I'm trying to make prometheus to alert when count of the containers that match a specific pattern in a geo region drops below some number:

IF count(container_last_seen{environment="prod",name=~"notification_sender.*",roles=~".*application-server.*"}) by (geo_region) < 4

So this works until there are no containers of this name in the region ... then the value becomes "no data" and that's not < 4 ... so there is no alert ...

I cant see how absent() may help me here...

@juliusv

This comment has been minimized.

Copy link
Member

juliusv commented Dec 15, 2016

@zerthimon

This comment has been minimized.

Copy link
Author

zerthimon commented Dec 15, 2016

@juliusv yeah, I tried count_scalar() but I can't use aggregation with it. As for absent() ... I'm still out of ideas here.

How would you address this use case:

  1. an EC2 regions with application servers running docker containers.
  2. Cadvisors on every server provide container names.
  3. The containers are named with a specific pattern:
  • notification_checker[0-9]
  • notification_sender[0-9]
  1. I need an alert when the number of container of the same pattern (eg. notification_sender-.*) in region drops below 4.
  2. alert also has to fire if there are no (0) containers that match the pattern in region.

The best query I could come up with is this:

count(container_last_seen{environment="prod",name=~"notification_sender.*",roles=~".*application-server.*"}) by (geo_region) < 4

The result of the query is:

{geo_region="tokyo"}	4
{geo_region="sydney"}	4
{geo_region="singapore"}	4
{geo_region="saopaulo"}	4
{geo_region="virginia"}	4
{geo_region="dublin"}	4

Which is great... but... It can't get me a region where there are no containers (0), cause for some reason count() doesn't work for 0 elements in vector ...
I'd expect to have also:

{geo_region="california"}   0
@grobie

This comment has been minimized.

Copy link
Member

grobie commented Mar 5, 2017

Please use the prometheus-users mailing list for questions.

@grobie grobie closed this Mar 5, 2017

@fortman

This comment has been minimized.

Copy link

fortman commented Oct 25, 2017

@zerthimon You might want to use 'bool' with your comparator
count(container_last_seen{environment="prod",name="notification_sender.*",roles=".application-server."}) by (geo_region) < bool 4
or something like that. Play with bool
Also the link to the mailing list doesn't work for me.

@baifeg

This comment has been minimized.

Copy link

baifeg commented Sep 6, 2018

@zerthimon The following expr works for me
count(ALERTS) or (1-absent(ALERTS))

@lilred

This comment has been minimized.

Copy link

lilred commented Feb 21, 2019

Alternatively, count(ALERTS) or vector(0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.