I set up a weather station with a rain gauge, which is writing data into an Influx 1.7.7 DB.
For this gauge I 'm collecting data into a 7 day shard with a value every 10 seconds.
I set up a continuous query after collecting data for 3 days like this:
CREATE CONTINUOUS QUERY collectd_cq_10min_sum ON collectd_db BEGIN SELECT sum(value) AS value INTO collectd_db."ten_min_sum".rain FROM collectd_db."default".rain GROUP BY time(10m), * END
Now I’d like to get the 3 days into the database as well.
I tried this:
SELECT sum(value),host,region,unit,unit_type,instance AS value INTO collectd_db."ten_min_sum".rain FROM collectd_db."default".rain where time >= now() - 7d GROUP BY time(10m)
which returns: ERR: mixing aggregate and non-aggregate queries is not supported
If I do this:
SELECT sum(value) AS value INTO collectd_db."ten_min_sum".rain FROM collectd_db."default".rain where time >= now() - 7d GROUP BY time(10m)
The values get written, but I lose all other information like host and unit. See below:
time host instance region unit unit_type value
---- ---- -------- ------ ---- --------- -----
1563003000000000000 0
1563003600000000000 weather rain europe ml volume 0
How can I get at least the host name into the database?
You can try using the “last” function for the host.
Something like
SELECT sum("value") AS "value", last("host") AS "host", last("region") AS "region", last("instance") AS "instance" INTO "database"."retentionpolicy".measurement FROM "database"."autogen"."measurement"')
I don’t know a great deal about CQ’s, i use Kapacitor but the query should be similar. You might not need the double quotes if you’re defining it within Influx as a CQ.