Kusto 查询,如何保存查询结果以备后用
Kusto Query, How to Save Query Result and Use Later
在 App Insight 中,如何编写将查询结果保存到变量中的 KQL,并在稍后的第二个查询中使用该变量?
例如,查找事件发生时的时间戳:
let incidentTime = traces
| where message = "UNIQUE IDENTIFIER"
| limit 1
稍后在第二次查询中使用此时间戳以在事件发生时查找附近的踪迹
traces
| where timestamp between (datetime_diff('minute', -1, incidentTime)..incidentTime)
第二个查询给了我一个错误,基本上说无法从 incidentTime 检索标量值。
如何从 incidentTime 读取值并将其放入第二个查询?
您可以使用 toscalar()
和 around()
:
- https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/toscalarfunction
- https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/around-function
例如:
let incidentTime = toscalar(
traces
| where message = "UNIQUE IDENTIFIER"
| project timestamp
| limit 1
);
traces
| where around(timestamp, incidentTime, 1m)
类似地,如果您想对多列执行此操作:
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])
在 App Insight 中,如何编写将查询结果保存到变量中的 KQL,并在稍后的第二个查询中使用该变量?
例如,查找事件发生时的时间戳:
let incidentTime = traces
| where message = "UNIQUE IDENTIFIER"
| limit 1
稍后在第二次查询中使用此时间戳以在事件发生时查找附近的踪迹
traces
| where timestamp between (datetime_diff('minute', -1, incidentTime)..incidentTime)
第二个查询给了我一个错误,基本上说无法从 incidentTime 检索标量值。
如何从 incidentTime 读取值并将其放入第二个查询?
您可以使用 toscalar()
和 around()
:
- https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/toscalarfunction
- https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/around-function
例如:
let incidentTime = toscalar(
traces
| where message = "UNIQUE IDENTIFIER"
| project timestamp
| limit 1
);
traces
| where around(timestamp, incidentTime, 1m)
类似地,如果您想对多列执行此操作:
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])