创建InfluxDB连续查询,其中度量名称基于标记值

时间:2018-03-09 16:27:11

标签: influxdb

我有一个名为reading的度量,其中所有行的格式为:

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

其中channelhost是标记。

有没有办法可以自动生成连续查询,以便:

  • CQ度量的名称格式为host_channel

到目前为止,我一直在逐一进行,例如

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

但有一种方法可以自动获得每个主机1m的采样时间。任何时候将新主机添加到数据库?谢谢!

1 个答案:

答案 0 :(得分:0)

由于原因,无法在InfluxDB中执行此操作。在测量名称中编码标记值与InfluxDB官方最佳实践和being discouraged相矛盾。

我建议你一起去:

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