在App Insights使用timechart拆分Y轴失败,如何排查解决?
Y轴拆分(
ysplit=axes)未生效的原因及解决方案 功能支持情况
Azure Monitor(包含Application Insights的日志查询体验)支持ysplit=axes参数,但该功能触发有明确前提,并非所有场景都会自动拆分Y轴。
查询未生效的核心原因
ysplit=axes仅在多个数据系列的数值量级存在显著差异时才会触发拆分。你的查询中,DurationSeries是原始平均耗时,LineFit是拟合后的趋势线,两者数值高度接近,图表引擎会判定无需拆分Y轴,因此不会显示双Y轴。
此外,当前通过make_list+mv-expand的嵌套汇总方式,虽然逻辑正确,但可能让图表引擎对数据系列的识别不够直观,建议简化查询结构。
修正后的查询示例(简化版)
直接在汇总后生成拟合线,避免列表转换步骤;若要强制验证拆分效果,可加入一个量级差异明显的指标(比如调用计数):
Application Insights 版本
let grain = 1h; let ago = 30d; let dependencyName = "SQL: <servername>.database.windows.net | <database>"; dependencies | where timestamp > ago(ago) | where name has dependencyName | summarize avgDuration=avg(duration), callCount=count() by bin(timestamp, grain) | order by timestamp asc | extend LineFit = series_fit_line(avgDuration).line_fit | project timestamp, avgDuration, callCount, todecimal(LineFit) | render timechart with (ysplit=axes, ytitle="Duration / Count")
Azure Monitor 版本
let grain = 1h; let ago = 30d; let dependencyName = "SQL: <servername>.database.windows.net | <database>"; AppDependencies | where TimeGenerated > ago(ago) | where Name has dependencyName | summarize avgDuration=avg(DurationMs), callCount=count() by bin(TimeGenerated, grain) | order by TimeGenerated asc | extend LineFit = series_fit_line(avgDuration).line_fit | project TimeGenerated, avgDuration, callCount, todecimal(LineFit) | render timechart with (ysplit=axes, ytitle="Duration / Count")
验证方法
- 运行上述包含
callCount的查询,由于计数和耗时量级差异明显,图表会自动显示双Y轴,验证功能正常。 - 若仅需对比耗时与拟合线,可人为调整其中一个系列的数值(如乘以100)强制触发拆分:
// 示例:将拟合线放大100倍 | project timestamp, avgDuration, LineFit = todecimal(LineFit) * 100 | render timechart with (ysplit=axes)
内容的提问来源于stack exchange,提问作者Oskar
相关产品推荐
相关产品推荐

