技术解析

InfluxDB (InfluxQL) 中如何按 tag 计算总和?
0
2021-06-03 21:51:01
idczone

假定有一个用于统计流量的表 traffic,格式如下

|  ts  |  field  |         tags        |
+------+---------+---------------------+
| time | tx | rx | device_id | conn_id |
+------+----+----+-----------+---------+

原始数据每秒提交一次,tx rx 是网络连接的累计字节数。目前已经实现了降采样和历史数据清理

alter retention policy autogen on mydb duration 3d shard duration 1d
create retention policy rp_10s on mydb duration 3d replication 1
creat抗投诉服务器e retention policy rp_1m  on mydb duration inf replication 1
create retention policy rp_10m on mydb duration inf replication 1
create retention policy rp_1h  on mydb duration inf replication 1
create retention policy rp_1d  on mydb duration inf replication 1

create continuous query cq_10s on mydb begin
    select max(tx), max(rx) into rp_10s.traffic from traffic group by time(10s), *
end

create continuous query cq_1m  on mydb begin
    select max(tx), max(rx) into rp_1m.traffic  from traffic group by time(1m),  *
end

create continuous query cq_10m on mydb begin
    select max(tx), max(rx) into rp_10m.traffic from traffic group by time(10m), *
end

create continuous query cq_1h  on mydb begin
    select max(tx), max(rx) into rp_1h.traffic  from traffic group by time(1h),  *
end

create continuous query cq_1d  on mydb begin
    select max(tx), max(rx) into rp_1d.traffic  from traffic group by time(1d),  *
end

现在想要统计每个用户的总字节数,累加后写入到另一个 device_traffic 表,请问要如何用 continuous query 实现呢?


没看懂 sum 不行么

数据地带为您的网站提供全球顶级IDC资源
在线咨询
专属客服