英文:
Sum values based on Timestamp for InfluxDb (Flux)
问题
I have data for executions running on different machines(Agents). The data is like:
_time | AgentName | RunningSessions |
---|---|---|
001 | Agent1 | 1 |
002 | Agent1 | 4 |
003 | Agent1 | 10 |
004 | Agent1 | 12 |
005 | Agent1 | 15 |
001 | Agent2 | 1 |
002 | Agent2 | 5 |
003 | Agent2 | 8 |
004 | Agent2 | 10 |
005 | Agent2 | 15 |
For the above data, my plot is like this (showing two colors for different Agents)
I need to combine the data based on _time so that the final data is like:
_time | RunningSessions |
---|---|
001 | 2 |
002 | 9 |
003 | 18 |
004 | 22 |
005 | 30 |
What would be an optimal flux query to join the source data to produce the sum of RunningSessions based on time.
Note: There is a complexity here for data missing for a time instant from an Agent. Suppose for time=006, Agent1 is having 35 sessions, but Agent2 hasn't reported any change, so for time=006 Agent2 must still be running the last 30 sessions.
This is my current query:
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "RunningSessions")
|> filter(fn: (r) => r["_field"] == "totalSessionsCount")
|> group(columns: ["_time"])
|> sum(column: "_value")
|> group()
Update (1): Adding current Table view & query
英文:
I have data for executions running on different machines(Agents). The data is like:
_time | AgentName | RunningSessions |
---|---|---|
001 | Agent1 | 1 |
002 | Agent1 | 4 |
003 | Agent1 | 10 |
004 | Agent1 | 12 |
005 | Agent1 | 15 |
001 | Agent2 | 1 |
002 | Agent2 | 5 |
003 | Agent2 | 8 |
004 | Agent2 | 10 |
005 | Agent2 | 15 |
For the above data, my plot is like this(showing two colors for different Agents)
I need to combine the data based on _time so that the final data is like:
_time | RunningSessions |
---|---|
001 | 2 |
002 | 9 |
003 | 18 |
004 | 22 |
005 | 30 |
What would be an optimal flux query to join the source data to produce the sum of RunningSessions based on time.
Note: There is a complexity here for data missing for a time instant from an Agent. Suppose for time=006, Agent1 is having 35 sessions, but Agent2 hasn't reported any change, so for time=006 Agent2 must still be running the last() 30 sessions.
This is my current query:
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "RunningSessions")
|> filter(fn: (r) => r["_field"] == "totalSessionsCount")
|> group(columns: ["_time"])
|> sum(column: "_value")
|> group()
答案1
得分: 0
我不熟悉flux,但你可以在Grafana中对时间序列进行求和。
进入面板编辑模式 > 转换:
- 添加“从计算添加字段”变换,
- 选择“计算”:总和,
- 启用“替换所有字段”选项。
英文:
I'm not familiar with flux, but you can sum your time series at Grafana.
Go to panel edit mode > Transform:
- Add "Add field from calculation" transformation,
- select
Calculation
:Total
, - enable option
Replace all fields
.
答案2
得分: 0
我错失了毫秒级的时间精度,尽管在界面上没有显示出来,但确实存在,因此我无法与_time列分组。
> 截断时间列(单位:1秒)
from(bucket: "${bucket}")
|> 范围(start: v.timeRangeStart, stop: v.timeRangeStop)
|> 过滤(fn: (r) => r["_measurement"] == "RunningSessions")
|> 过滤(fn: (r) => r["_field"] == "totalSessionsCount")
|> 截断时间列(单位:1秒)
|> 聚合窗口(every: 5秒, fn: last, createEmpty: true)
|> 分组(columns: ["_time"])
|> 求和(column: "_value")
|> 分组()
|> 输出(name: "Total VU Load")
英文:
I was missing the time precision of milliseconds which was not being shown in the UI, but it was there due to which I couldn't group with the _time column.
> truncateTimeColumn(unit: 1s)
from(bucket: "${bucket}")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "RunningSessions")
|> filter(fn: (r) => r["_field"] == "totalSessionsCount")
|> truncateTimeColumn(unit: 1s)
|> aggregateWindow(every: 5s, fn: last, createEmpty: true)
|> group(columns: ["_time"])
|> sum(column: "_value")
|> group()
|> yield(name: "Total VU Load")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论