【问题标题】:Application Insights requests count metrics vs query don't matchApplication Insights 请求计数指标与查询不匹配
【发布时间】:2022-01-12 21:16:16
【问题描述】:

我正在尝试使用 API 从 Application Insights 检索最后一天的请求数。

  • 当我通过/metrics/requests/count?timespan=P1D 端点执行此操作时 我得到了 35871 的 总和
  • 但如果我通过 /query?query=requests | where timestamp > ago(1d) | count;端点 我得到了 4510 个计数
  • 最后,如果我通过 /events/requests?timespan=P1D&$count=true端点我得到一个 @odata.count 4510,与“查询”相同。

为什么指标和查询之间的请求计数差异如此之大?

编辑:

我在 Application Insights 日志中运行了以下查询:

requests
| summarize totalCount=sum(itemCount) by bin(timestamp, 1d)

然后返回(目前是12/7/2021, 8:14:47.562 PM):

timestamp [UTC]              totalCount
12/7/2021, 12:00:00.000 AM   35,871 

这会检索(我相信)从今天开始以来的请求数量。
令人惊讶的是,这与通过/metrics 获得的计数相匹配:

{'value': {'start': '2021-12-06T20:13:46.054Z', 'end': '2021-12-07T20:13:46.054Z', 'requests/count': {'sum': 35871}}}

/metrics/ 的日期范围大致涵盖了过去 24 小时 (1d)。

【问题讨论】:

    标签: azure-application-insights


    【解决方案1】:

    我认为“Application Insights 日志”(/query 端点)中的 requests 表包含一个请求列表,其中每个条目可以是相同的 name (uri) 但具有不同的结果代码
    虽然这清楚地表明了这一点,但我还没有找到文档。

    有了这个假设,我已经能够将请求计数与/metrics 的计数相匹配。

    这是我一直在追的查询:

    let TOTAL = requests | where timestamp > ago(1d) | summarize TotalRequests=sum(itemCount) | extend Foo=1;
    let CACHED_TOTAL = materialize(TOTAL);
    let FAILED = requests
    | where timestamp > ago(1d)
    | where resultCode hasprefix "4"
    | summarize Failed=sum(itemCount)
    | extend Foo=1;
    let CACHED_FAILED = materialize(FAILED);
    CACHED_FAILED 
    | join kind=inner CACHED_TOTAL on Foo
    | extend PercentFailed = round(todouble(Failed * 100) / TotalRequests, 2)
    | project TotalRequests, Failed, PercentFailed;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-20
      • 2018-08-09
      • 1970-01-01
      相关资源
      最近更新 更多