-
Notifications
You must be signed in to change notification settings - Fork 100
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
Smooth noncontinuous lines in line chart by casting null value to zero #135
Comments
Hi, could you please provide an example of a query for such metrics? Is there a case where you can't just use |
Thanks for your reply. Let's say we have a table orders :
Now I want to monitor the number of orders by each day. So I query this table by: select date,
count(distinct order_id) as order_count
from orders
group by date
order by date Then I got query results as:
With scrape interval set to 1 day, query exporter reports two records. Then Prometheus can not find the order_count on missing 10/02/2022 and will set metric value on this date to 2 in time series chart. But, we want order_count to be 0 on 10/02/2022 even when there is no record in table orders. I fixed this in my use case by checking if previously reported metric was reported in current time. If not, modified query exporter will still report this metric but with value set to 0. |
How is the metric defined in query-exporter? Specifically, how does the date get reported? |
OK, sorry for the unclear. Let me rephrase here.
select count(distinct order_id) as order_count
from orders
where date between '$scrape_time-1day' and '$scrape_time' -- pseudo code We define the metric as
The real list of number of orders should be:
But we got:
Then we can use |
Hi, thanks for the explaination, but it would be useful to have a sample of config file you're using (both for the query and the metric configuration) I'm not sure how you get |
Is your feature request related to a problem? Please describe.
I have this use case: I need to monitor the fluctuation of metrics stored in database where if a metric value reduces to zero, the corresponding record doesn't exist at all in the database. This is a pretty common use case in monitoring noncontinuous metrics(e.g. order count, user count). When there is not any order in one day, we want the order count to be zero instead of null.
In current situation, query exporter would stop reporting one metric when the corresponding records in database doesn't exist. Prometheus can not read the update value of this metric and will keep reporting its last value. So what we see in the chart is that the line doesn't go down to zero but keep flat.
This is a real use case in my work. It would be great if query exporter have a switch that can cope with this situation.
Describe the solution you'd like
My desired solution is query exporter have a switch by which query exporter can automatically cast null to zero then Prometheus can display lines that reflect real changes of metrics.
I've added this feature to fix this as the way I described above. I'm willing to commit my code to help query exporter more powerful and can be applied in multiple scenarios. Does this make sense?
Describe alternatives you've considered
Another alternative is we add an extra database table that stores all the existed metric attributes. Even when a metric value disappears, query exporter can still read this metric and set value to zero.
I don't think this is a better idea since this adds complexity to database design and changes original scheme.
Additional context
For some use cases, metrics are always continuous so that this issue won't happen. But for those noncontinuous metrics monitoring problem, this feature can vastly reduce user's inconvenience in developing.
The text was updated successfully, but these errors were encountered: