Same query in two panels but only one of them works

Hi,

I have a strange issue. At least it seems strange to me, hopefully someone can point me in the right direction.

I have the following query which i use in a single stat panel to show server availability as a percentage. The query works fine in this panel…

The query:
select sum("isUp") / count("isUp") from (select non_negative_derivative(mean("uptime")) / non_negative_derivative(mean("uptime")) as isUp from system where "host" =~ /^$NutanixHost$/ and $timeFilter group by time($__interval)fill(0));

However, when i apply the query to a graph panel instead (intended to show server availability over a time span) i get the message “Data Points Outside Time Range”

When i hover over the graph panel i can see that there is indeed a value, but the date is 1970-01-01.
if i check the Grafana query inspector it tells me there is no data, however i know there is data and one panel shows this.

I tried changing the time ranges, but a lot of the data never existed before the 26th August, so i figure using the time filters in Grafana and setting them to the last 7 days i should see data in both panels?

Has anybody encountered anything like this, can anyone explain why the query wouldn’t work as expected in the graph panel?

Regards,

Phil

Hi Phil,

I think that you need to insert a WHERE $timefilter and a GROUP BY time($__interval) clause into your main query, so it should look like this:

select sum("isUp") / count("isUp") from 
(select non_negative_derivative(mean("uptime")) / non_negative_derivative(mean("uptime")) as isUp from system where "host" =~ /^$NutanixHost$/ and $timeFilter group by time($__interval) fill(0))
where $timefilter group by time($__interval);

Subqueries tend to cause some unwanted timestamp behaviors; hopefully this helped.