V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
feng32
V2EX  ›  程序员

InfluxDB (InfluxQL) 中如何按 tag 计算总和?

  •  
  •   feng32 · 2021-04-21 14:42:39 +08:00 · 919 次点击
    这是一个创建于 1316 天前的主题,其中的信息可能已经有所发展或是发生改变。

    假定有一个用于统计流量的表 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 实现呢?

    1 条回复    2021-04-21 19:10:07 +08:00
    PiersSoCool
        1
    PiersSoCool  
       2021-04-21 19:10:07 +08:00
    没看懂 sum 不行么
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1027 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 21:27 · PVG 05:27 · LAX 13:27 · JFK 16:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.