I am trying to select some values from influxdb datbase. For this below query, the output is null but the values are there.
SELECT mean(load1), max(load1) FROM system WHERE time >= '2016-02-22T09:47:00Z' and time <= '2016-02-22T09:47:00Z' AND ( host ='daniel-Vostro-2520' ) GROUP BY time(1m);
I need to take values between 1 minute from particular time.
What is wrong in the query.
You have the same time (2016-02-22T09:47:00Z) defined twice in two different clauses. Nothing will match because you basically defined a time interval of 0.
Related
I am trying to get the MAX/MIN values of an interval of time, and I would like to get the correspond timestamp of the value.
If I run: SELECT max(value) FROM data WHERE time > 1549034249000000000 and time < 1550157449000000000 GROUP BY time(10s)
I am receiving the timestamp of the range beginning instead of the max(value) timestamp.
What alternatives could there be for receiving the max(value) of an interval and his timestamp?
In SQL is possible to execute a query like: SELECT value DENSE_RANK () OVER (PARTITION BY time ORDER BY variableName DESC) AS Rank FROM tableName Is not possible to run something like that in InfluxDB?
Yout can not. When you use group by you get ever the beginning timestamp of the group by.
The alternative is not to use group by.
I have some measurement data in my influxdb database which I can query with:
select * from E_real_con
name: E_real_con
time value
---- -----
1537920001044785525 | 57160036.00
1538006401069651036 | 57227208.00
1538092800108297103 | 57294112.00
1538179200697333731 | 57366108.00
However, "value" is a cumulative value and I would like to get the delta/difference between two consecutive values.
I tried the following:
SELECT difference(last(value)) FROM E_real_con WHERE time >= now() - 7d GROUP BY time(1d) fill(null)
However, I get the following error message:
ERR: unsupported difference iterator type: *query.stringInterruptIterator
I would be happy to get some hints and feedback how to solve my issue.
I am using influxdb 1.6.1
Thanks a lot!
Christoph
I found the solution. The following two mistakes had to be corrected:
1) The values in the measurement were of type "string" and not "float". As the data was coming from nodered, I cleared the database and used parseFloat() in nodered before writing the data to influxdb.
BTW: you can check the datatype of your measurement field by:
SHOW FIELD KEYS FROM E_real_con
2) It seems that the query command requires a "where"
This works:
SELECT difference(last(value)) FROM E_real_del WHERE time >= now() - 7d GROUP BY time(1d)
whereas:
SELECT difference(last(value)) FROM E_real_del GROUP BY time(1d)
does not work.
I hope this might help someone else.
2) It seems that the query command requires a "where"
It's even more restricted than that. It requires a where with a minimum timestamp.
For example, the following gives me no result:
select difference(last(value)) from WaterConsumption_Total where time < now() - 1d group by time(1d) fill(previous)
While this does:
select difference(last(value)) from WaterConsumption_Total where time > '2019-08-23T00:00:00Z' group by time(1d) fill(previous)
This effectively makes it impossible to use such a query as a continuous query.
I have a Influx database that is getting filled with values. These values are presented by Grafana. What I need is to get the actual values depending on the selected time interval.
Currently I have the following query for a single metric:
SELECT mean("value") FROM "table" WHERE $timeFilter GROUP BY time($interval) fill(null)
What I want is to subtract the lowest value from that interval, so it only counts the values from within that interval. So the graph needs to start at zero. To get the lowest value from that interval I use:
SELECT min("value") FROM "table" WHERE $timeFilter
So I thought combining those two (with a subquery) like this should work:
SELECT mean("value") - (SELECT min("value") FROM "table" WHERE $timeFilter) FROM "table" WHERE $timeFilter GROUP BY time($interval) fill(null)
Unfortunately this doesnt work. The query is not accepted as a subquery.
This is possible using InfluxDB's built-in functions:
SELECT cumulative_sum(difference((mean("value")))) FROM "table" WHERE $timeFilter GROUP BY time($interval) fill(null)
This takes the difference between consecutive data points (ignoring the absolute value), and cumulatively sums this over the selected time range.
I'm not entirely sure, but this query requires an additional mean() associated with the GROUP BY clause. Perhaps it's better to use max or first instead, depending on your needs.
Update
Alternatively, you can indeed use subqueries and GROUP BY to achieve this, but this way you can only get time ranges that can be represented by GROUP BY (e.g. from 14:13 to 15:16 on July 6 2010 is more difficult).
SELECT (energy_live-energy_fill) as Energy FROM
(SELECT first(value) as energy_fill from energyv3 WHERE $timeFilter GROUP BY time(1d)),
(SELECT first(value) as energy_live from energyv3 WHERE $timeFilter GROUP BY time($__interval))
fill(previous)
Is it possible to filter values from comlex metric in grafana?
For example:
SELECT sum(one) + sum(two) FROM "table" WHERE $timeFilter GROUP BY time($interval)
I need to show only positive sum sum(one) + sum(two) > 0
In sql I would use alias and HAVING clause like:
SELECT sum(one) + sum(two) AS S FROM "table" WHERE $timeFilter GROUP BY time($interval) HAVING S > 0
However that does not work in grafana.
How can I achieve this result without creating a new sum column in back-end database?
[EDIT]: My grafana GUI looks like this:
After clicking on "pen" button:
As of August 2016, the HAVING clause is not yet available in InfluxDB so finding all points where sum(one) + sum(two) > 0 is not possible directly in InfluxDB without using a continuous query to create an intermediate series.
However, Grafana does allow a minimum y-axis value to be set, which means any negative values will not be shown.
Hope that helps!
This answers just a part of your question but I was able to do the following in grafana+influxdb datasource:
Which selects the sum of one value if >0.
The problem is that it is not possible to select two different values in one query. But maybe you can workaround this problem with two querys in one graph.
I want to know how many events we send to InfluxDB for a given period. If I use the following query SELECT COUNT(value) FROM /./ WHERE time > now() - 1h GROUP BY time(10m), I get that grouped for each metric but I want the total for all metrics.
If I use SELECT COUNT(*) FROM /./ WHERE time > now() - 1h GROUP BY time(10m), I get an error:
Server returned error: expected field argument in count()
The COUNT function takes one and only one field key as an argument. If you have field keys that are not named value you will have to run a separate query to count them.
Alternately, you can run them together like:
SELECT COUNT(value), COUNT(otherfield), COUNT(anotherfield) FROM /./ WHERE time > now() - 1h GROUP BY time(10m)