基本語法
CREATE CONTINUOUS QUERY <cq_name> ON <database_name>
BEGIN
<cq_query>
END
Create CQ
CREATE CONTINUOUS QUERY cpu_3m ON telegraf
BEGIN
SELECT mean("Percent_Processor_Time") INTO win_cpu_used_3m FROM "win_cpu" GROUP BY time(3m)
END
每3分鐘彙總 win_cpu 中 Percent_Processor_Time的平均資料,並新增至 win_cpu_used_3m。
注意:一定要有一個彙總函示和group by time
SHOW CONTINUOUS QUERIES (顯示所有CQ)
DROP CONTINUOUS QUERY cpu_3m ON telegraf(刪除CQ)
進階語法
CREATE CONTINUOUS QUERY <cq_name> ON <database_name>
RESAMPLE EVERY <interval> FOR <interval>
BEGIN
<cq_query>
END
CREATE CONTINUOUS QUERY "mem_every_1m" ON "telegraf"
RESAMPLE EVERY 1m
BEGIN
SELECT mean("Available_Bytes") INTO "win_mem_every" FROM "win_mem" GROUP BY time(5m)
END
每1分鐘執行該query,資料區間為5分鐘,並新增至win_mem_every。
參考