Azure Monitor 日志(Kusto 查询语言)中一列内的日期时间差
Date time difference within a column in Azure Monitor Logs (Kusto Query Language)
我在 Azure Monitor 日志中有以下格式的点击流数据:
Timestamp Category Session_ID Step_Name
10/22/2019, 9:28:14.868 AM A ++9Ti step 1
10/22/2019, 9:28:18.034 AM A ++9Ti step 2
10/22/2019, 9:28:22.487 AM A ++9Ti step 3
10/23/2019, 7:02:02.527 AM B ++MoY step 1
10/23/2019, 7:02:09.244 AM B ++MoY step 2
10/23/2019, 7:02:21.156 AM B ++MoY step 3 <--
10/23/2019, 7:02:27.195 AM B ++MoY step 3 <--
10/23/2019, 7:15:13.544 AM A ++0a3 step 1
10/23/2019, 7:15:35.438 AM A ++0a3 step 2
我需要获取消费者在类别中每一步花费的平均时间
此外,当步骤重复时(如session_ID = '++MoY'中的第3步),我们需要在计算平均值时采用最新的时间戳。
示例:类别 A 中第 2 步花费的平均时间为 (3.166 + 21.894)/2 = 12.53 秒。 (注意:时间戳给出完成步骤的时间)
你可以试试下面的方法
a) 使用 arg_max()
获取最新 step/category
b) 在 order by
之后使用 prev()
来计算每个步骤的持续时间
datatable(Timestamp:datetime, Category:string, Session_ID:string, Step_Name:string)
[
datetime(10/22/2019, 9:28:14.868 AM), 'A', '++9Ti', 'step 1',
datetime(10/22/2019, 9:28:18.034 AM), 'A', '++9Ti', 'step 2',
datetime(10/22/2019, 9:28:22.487 AM), 'A', '++9Ti', 'step 3',
datetime(10/23/2019, 7:02:02.527 AM), 'B', '++MoY', 'step 1',
datetime(10/23/2019, 7:02:09.244 AM), 'B', '++MoY', 'step 2',
datetime(10/23/2019, 7:02:21.156 AM), 'B', '++MoY', 'step 3',
datetime(10/23/2019, 7:02:27.195 AM), 'B', '++MoY', 'step 3',
datetime(10/23/2019, 7:15:13.544 AM), 'A', '++0a3', 'step 1',
datetime(10/23/2019, 7:15:35.438 AM), 'A', '++0a3', 'step 2',
]
| summarize arg_max(Timestamp, *) by Step_Name, Session_ID
| order by Session_ID asc, Timestamp asc
| extend duration = iff(Session_ID == prev(Session_ID), Timestamp - prev(Timestamp), 0s)
| summarize avg(duration) by Step_Name, Category
| where Step_Name == "step 2" and Category == "A"
我在 Azure Monitor 日志中有以下格式的点击流数据:
Timestamp Category Session_ID Step_Name
10/22/2019, 9:28:14.868 AM A ++9Ti step 1
10/22/2019, 9:28:18.034 AM A ++9Ti step 2
10/22/2019, 9:28:22.487 AM A ++9Ti step 3
10/23/2019, 7:02:02.527 AM B ++MoY step 1
10/23/2019, 7:02:09.244 AM B ++MoY step 2
10/23/2019, 7:02:21.156 AM B ++MoY step 3 <--
10/23/2019, 7:02:27.195 AM B ++MoY step 3 <--
10/23/2019, 7:15:13.544 AM A ++0a3 step 1
10/23/2019, 7:15:35.438 AM A ++0a3 step 2
我需要获取消费者在类别中每一步花费的平均时间
此外,当步骤重复时(如session_ID = '++MoY'中的第3步),我们需要在计算平均值时采用最新的时间戳。
示例:类别 A 中第 2 步花费的平均时间为 (3.166 + 21.894)/2 = 12.53 秒。 (注意:时间戳给出完成步骤的时间)
你可以试试下面的方法
a) 使用 arg_max()
获取最新 step/category
b) 在 order by
之后使用 prev()
来计算每个步骤的持续时间
datatable(Timestamp:datetime, Category:string, Session_ID:string, Step_Name:string)
[
datetime(10/22/2019, 9:28:14.868 AM), 'A', '++9Ti', 'step 1',
datetime(10/22/2019, 9:28:18.034 AM), 'A', '++9Ti', 'step 2',
datetime(10/22/2019, 9:28:22.487 AM), 'A', '++9Ti', 'step 3',
datetime(10/23/2019, 7:02:02.527 AM), 'B', '++MoY', 'step 1',
datetime(10/23/2019, 7:02:09.244 AM), 'B', '++MoY', 'step 2',
datetime(10/23/2019, 7:02:21.156 AM), 'B', '++MoY', 'step 3',
datetime(10/23/2019, 7:02:27.195 AM), 'B', '++MoY', 'step 3',
datetime(10/23/2019, 7:15:13.544 AM), 'A', '++0a3', 'step 1',
datetime(10/23/2019, 7:15:35.438 AM), 'A', '++0a3', 'step 2',
]
| summarize arg_max(Timestamp, *) by Step_Name, Session_ID
| order by Session_ID asc, Timestamp asc
| extend duration = iff(Session_ID == prev(Session_ID), Timestamp - prev(Timestamp), 0s)
| summarize avg(duration) by Step_Name, Category
| where Step_Name == "step 2" and Category == "A"