假定有一个用于统计流量的表 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
create 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 实现呢?
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.