Lei*_*Pan 2 azure-application-insights kql azure-data-explorer
在 App Insight 中,如何编写 KQL 将查询结果保存到变量中,并稍后在第二个查询中使用该变量?
例如,查找事件发生时的时间戳:
let incidentTime = traces
| where message = "UNIQUE IDENTIFIER"
| limit 1
Run Code Online (Sandbox Code Playgroud)
稍后在第二个查询中使用此时间戳来查找事件发生时附近的痕迹
traces
| where timestamp between (datetime_diff('minute', -1, incidentTime)..incidentTime)
Run Code Online (Sandbox Code Playgroud)
第二个查询给了我一个错误,基本上说无法从事件时间检索标量值。
如何从 eventTime 读取值并将其放入第二个查询中?
您可以使用toscalar()和around():
例如:
let incidentTime = toscalar(
traces
| where message = "UNIQUE IDENTIFIER"
| project timestamp
| limit 1
);
traces
| where around(timestamp, incidentTime, 1m)
Run Code Online (Sandbox Code Playgroud)
同样,如果您想对多列执行此操作:
let params = toscalar(
traces
| where message = "UNIQUE IDENTIFIER"
| project pack_array(timestamp, username)
| limit 1
);
traces
| where around(timestamp, todatetime(params[0]), 1m)
| where username == tostring(params[1])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4470 次 |
| 最近记录: |