0
votes

I have a measurement called reading where all the rows are of the form:

time                            channel  host       value
2018-03-05T05:38:41.952057914Z  "1"      "4176433"  3.46
2018-03-05T05:39:26.113880408Z  "0"      "5222355"  120.23
2018-03-05T05:39:30.013558256Z  "1"      "5222355"  5.66
2018-03-05T05:40:13.827140492Z  "0"      "4176433"  3.45
2018-03-05T05:40:17.868363704Z  "1"      "4176433"  3.42

where channel and host are tags.

Is there a way I can automatically generate a continuous query such that:

  • The CQ measurement's name is of the form host_channel

Until now I have been doing them 1 by 1, for example

CREATE CONTINUOUS QUERY 4176433_1 ON database_name 
BEGIN 
    SELECT mean(value) INTO 4176433_1 
    FROM reading 
    WHERE host = '4176433' AND channel = '1' 
    GROUP BY time(1m)
END

but is there a way I can automatically get 1m sampling per host & channel any time a new host is added to the database? Thanks!

1

1 Answers

0
votes

There is no way of doing this in InfluxDB, by the number of reasons. Encoding tag values in a measurements names contradicts InfluxDB official best practices and being discouraged.

I suggest you just going with:

CREATE CONTINUOUS QUERY reading_aggregator ON database_name 
BEGIN 
    SELECT mean(value), host + '_' + channel AS host_channel
    INTO mean_reading
    FROM reading 
    GROUP BY time(1m), host, channel
END