hi
i am stuck with a simple thing and would be happy if someone could help (amnus9ng grafana10 on lînux)
context is My custom metric (measures published using pushgateway) is getting either 200 or 500 value every 5 minutes and I would like to display percentage of 200 (availibility rate indeed)
if I make count_over_time(mymetric)[$_range] and select one hour I obtain 12 which is number of measures and is fine
Now I want to measure availibility, hence trying to count nb of 200 status point divided by total number of points.
So I tried count_over_time(mymetric==200)[$_range] to only filter 200 values but I’m getting “ranges allowed for vector selectors”
I tried alternatively count(mymetric==200) I got 1 every point value is 200. Then I tried sum_over_time( count(mymetric==200) [$__range] but I’m getting same output
Tried couple of other things without success so far:/
would you have any hint?
Hello
Any suggestion ? this is basics need using basic concept and driving me mad not to understand where the issue is
The solution is count_over_time(mymetric==200)[$_range**:5m**])
if I add the intervall after the range, I am getting expected result
Still not so clear with the concept is prometheus subquery as mentioned here : Reddit - Dive into anything
That’s how I understand subqueries: So… insert deep breath
When you query your metric, Prometheus knows exactly the resolution of it, so it can tell exactly where the points are located. However, when you perform operations on the query (in your case comparing the metric value to 200), you created an entirely new vector. With the new vector, Prometheus doesn’t know what the resolution is. So when you try to operate on that query, Prometheus says “yo, what are the points”.
I’ve seen it somewhere, but I don’t remember where, so credits are in order but you can imagine subqueries like:
count_over_time(mymetric==200)[$_range:5m])
- your query with subqueries
You go to Grafana Explore page, type in just the inner query (in your case mymetric==200
). The time range you set in Grafana is the first argument of the lookbehind window []
- in your case $__range
and the second one 5m
in your case - is the step you can set in Query Options. Then the function (in your case count_over_time
) is performing on such a data, so you can do this by hand (counting all the points you see).
yeah the question is why prometheus is loosîng resolution when i add condition =200 and meantime grafana is able to plot my points correctly.
Prometheus is loosing that underneath. Grafana sends auto step, so it can plot points (at least that’s how I understand that). Meaning that when you do further operation on that, Prometheus doesn’t know what to do, Grafana knows because it doesn’t perform any new operations, it just take the prepared result.