【发布时间】:2019-08-14 14:21:32
【问题描述】:
我有两个 Rawdata 事件,其中一个是具有一个时间戳的请求,另一个是具有不同时间跨度的响应,是否有一个 kusto 函数可以从 rawdata 中提取这两个日期并在两者之间进行时间差
【问题讨论】:
我有两个 Rawdata 事件,其中一个是具有一个时间戳的请求,另一个是具有不同时间跨度的响应,是否有一个 kusto 函数可以从 rawdata 中提取这两个日期并在两者之间进行时间差
【问题讨论】:
是的,有。
在不查看输入数据样本的情况下为您提供最佳选择有点挑战性,但您可能想查看parse 运算符:https://docs.microsoft.com/en-us/azure/kusto/query/parseoperator,或extract() 函数:https://docs.microsoft.com/en-us/azure/kusto/query/extractfunction
或者,在您的问题中包含一个示例输入,例如:
print request = "this<>is!!!my-request from 2019-08-14 17:54:36.8892211, the end",
response = "this is the matching 2019-08-14 17:55:36.0000033 response"
| parse request with * "from " request_datetime:datetime "," *
| parse response with * "matching " response_datetime:datetime " response"
| project diff = response_datetime - request_datetime
// this returns a single table with a single column named 'diff', whose value is '00:00:59.1107822'
或
datatable(event_text:string, correlation_id:long) [
"this<>is!!!my-request from 2019-08-14 17:54:36.8892211, the end", 1,
"this is the matching 2019-08-14 17:55:36.0000033 response", 1,
]
| extend dt = extract(@"(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{7})", 1, event_text, typeof(datetime))
| summarize diff = max(dt) - min(dt) by correlation_id
// this returns a single table with 2 columns named 'correlation_id' and 'diff', whose values are are '1' and '00:00:59.1107822'
【讨论】:
print value = 'ERROR 2019-08-14 10:14:18,599 4648303ms MessageInspector' | parse value with * " " timestamp:datetime "," ms:int " " * | project timestamp + ms * 1ms
Yoni 的回答向您展示了如何提取时间戳。拥有它们后,您可以使用datetime_diff 函数。假设您想知道 2 个时间戳之间有多少秒的差异:
| extend TimeDiff = datetime_diff('second', SigninTime, EventTime)
您可以使用此信息进行过滤。假设您只想保留这些时间戳在 20 秒内的行:
| filter TimeDiff < 20
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/datetime-difffunction
【讨论】: