Kusto查询:在Azure工作簿中展示分组请求总数(不修改图表)
解决方案
要在保留原有按天+系统分组的时间序列柱状图的同时,用指标展示所有请求的总次数,有两种简单的实现方式:
方式1:用同一个查询输出两种数据(推荐)
使用Kusto的fork运算符,让一次查询同时生成分组统计数据和总次数数据,之后在工作簿中分别配置可视化:
requests | where operation_Name == "Create History" | where customDimensions.SystemStatus == "Production" | extend systemid = tostring(customDimensions.SystemId) | extend system = tostring(system_lookup()[systemid]) | fork // 分支1:原有分组统计,用于时间序列柱状图 (summarize Services_Done = count() by bin(timestamp, 1d), system) // 分支2:总次数统计,用于指标卡 (summarize Total_Services_Done = count())
在Azure Log Analytics工作簿中:
- 添加第一个可视化组件,选择“时间序列柱状图”,数据源选择上述查询的第一个分支结果,按原有设置配置图表;
- 添加第二个可视化组件,选择“指标”,数据源选择查询的第二个分支结果,将指标字段设为
Total_Services_Done即可。
方式2:用两个独立查询
保留你原有的查询用于生成柱状图,再新增一个单独的查询计算总次数:
原有查询(用于柱状图)
requests | where operation_Name == "Create History" | where customDimensions.SystemStatus == "Production" | extend systemid = tostring(customDimensions.SystemId) | extend system = tostring(system_lookup()[systemid]) | summarize Services_Done = count() by bin(timestamp, 1d), system
新增查询(用于指标卡)
requests | where operation_Name == "Create History" | where customDimensions.SystemStatus == "Production" | count
在工作簿中分别为这两个查询配置对应的可视化组件即可,这种方式逻辑更直白,适合新手快速上手。
内容的提问来源于stack exchange,提问作者trial_and_error
相关产品推荐
相关产品推荐

