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

Azure Monitor Workbook如何随时间范围动态调整bin()时间间隔?

Azure Monitor Workbook 动态调整时间分箱间隔方案

你可以通过计算时间范围的跨度,结合Kusto的条件判断函数实现分箱间隔的动态切换,具体修改后的查询如下:

let timeRange = now() - {time};
requests
| where name == "Confirmation"
| where resultCode == 200
| where timestamp > {time}
| summarize c=count() by resultCode, bin(timestamp, case(timeRange <= 2d, 1h, 6h))
| render columnchart kind=stacked

逻辑说明

  1. 先定义timeRange变量,计算当前选择的时间范围总时长(当前时间减去{time}参数的起始时间)
  2. 使用case函数做条件判断:
    • 当时间范围≤2天(48小时)时,采用1小时分箱
    • 时间范围超过2天则自动切换为6小时分箱

如果需要覆盖更多时间范围场景,还可以扩展多档位的分箱规则,比如:

let timeRange = now() - {time};
let binInterval = case(
    timeRange <= 1d, 1h,
    timeRange <= 3d, 6h,
    timeRange <= 7d, 12h,
    1d
);
requests
| where name == "Confirmation"
| where resultCode == 200
| where timestamp > {time}
| summarize c=count() by resultCode, bin(timestamp, binInterval)
| render columnchart kind=stacked

你可以根据实际需求自由调整判断阈值(比如把3d改成其他天数)和对应的分箱间隔值。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 23:42:13