首页 > 解决方案 > Azure ApplicationInsights 指标语法?- 内部服务器故障

问题描述

我正在使用 ApplicationInsights API Explorer 来测试过滤器子句。但这会导致错误。

我发现了我从中派生过滤器的语法 (startswith(request/name, 'GET')) 的罕见示例。

在 API Explorer 上: https ://dev.applicationinsights.io/apiexplorer/metrics 我输入了我的帐户凭据。

我的参数是:

指标 ID:

    requests/count

筛选:

    startswith(request/cloud_RoleInstance, 'development')

在 Kusto 语言中,查询应该是:

requests
| where cloud_RoleInstance startswith "development" 
| count 

并且工作正常:结果:~ 47,000

我的查询结果是:

  "error": {
    "message": "Unexpected error occurred",
    "code": "InternalServerFault",
    "innererror": {
      "code": "QueryCompilationError"
    }

但我预计从“开发”开始的任何 cloud_RoleInstance 到达 AppInsights 的请求数量。

文档链接通常指向https://dev.applicationinsights.io/ 但我似乎找不到任何有关过滤器语法的有用信息。不支持属性 cloud_RoleInstance 吗?

标签: azuresyntaxazure-application-insightsmetrics

解决方案


根据规范,过滤器查询是一个OData 查询“其中每个子句的键应该是您正在检索的指标的适用维度”。如果我将您的过滤器查询稍微更改为,cloud_RoleInstance eq 'development'那么我会收到一个更有用的错误:“以下维度在此指标的过滤器子句中无效:cloud_RoleInstance”。我将与产品团队联系,以首先返回更有用的错误消息。

执行此操作的正确方法是查询 API。无需将查询转换为 OData,您可以对 Kusto 查询进行编码并按原样发送。

requests
| where cloud_RoleInstance startswith "development" 
| count 

编码为:

GET /v1/apps/{YOUR_APP}/query?query=requests%7C%20where%20cloud_RoleInstance%20startswith%20%22development%22%20%7C%20count%20 

并返回您正在寻找的结果。


推荐阅读