You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Application Insights中分组数据并获取每组最新记录?

Application Insights 自定义指标分组取最新记录查询方法

我在Application Insights中有如下格式的自定义指标数据:

时间戳(timestamp)指标名称(name)指标值(value)
05/05/2023, 15:46:43.000test110
05/05/2023, 16:43:54.000test254
05/05/2023, 12:32:56.000test376
05/05/2023, 04:23:41.000test234
05/05/2023, 09:41:40.000test123
05/05/2023, 11:09:03.000test112

需要编写查询语句,按name字段分组,筛选出每个分组中最新的记录,得到如下结果:

指标名称(name)指标值(value)
test112
test254
test376

实现查询语句

使用Kusto查询语言的arg_max()函数可以高效完成这个需求,语句如下:

customMetrics
// 若不需要过滤特定指标,可删除下面这行
| where name in ("test1", "test2", "test3")
| summarize arg_max(timestamp, value) by name
| project name, value

语句说明

  • customMetrics是Application Insights存储自定义指标的默认表,若你的数据存在其他表中,替换为对应表名即可
  • summarize arg_max(timestamp, value) by name:按name分组,直接提取每个分组内timestamp最大(最新)的记录对应的value值
  • project name, value:仅保留需要的字段,输出目标格式的结果

内容的提问来源于stack exchange,提问作者Paul

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 22:22:26