无法从Azure REST API获取指标

时间:2018-10-18 05:45:43

标签: azure azure-eventgrid azure-monitoring

我正在发送一个邮递员请求,以从这样的事件网格中获取指标:

https://management.azure.com/subscriptions/{suscription id}/resourceGroups/{name of resource group}/providers/microsoft.insights/metricDefinitions/?api-version=2018-01-01

我还附加了不记名令牌。

但是,我不断收到以下答复:

{
    "message": "An error has occurred.",
    "exceptionMessage": "ApiVersion: 2018-01-01 does not support query at non Arm resource Id level",
    "exceptionType": "Microsoft.Online.Metrics.MetricsMP.Utilities.RPRequestFormatException",
    "stackTrace": "   at Microsoft.Online.Metrics.MetricsMP.Controllers.MPController_MetricDefinitions_Base.<MetricDefinitionAtResourceGroup>d__4.MoveNext() in ...
                    ....
}

这是什么意思,我该如何解决?我一直在上网,信息不多。

3 个答案:

答案 0 :(得分:1)

您的网址有误。据我所知,如果要检索指标定义,其余的api是

方法:GET

请求URI: https://management.azure.com/subscriptions/ {subscriptionId} / resourceGroups / {resourceGroupName} / providers / {resourceProviderNamespace} / {resourceType} / {resourceName} /providers/microsoft.insights/metricDefinitions?api-version= {apiVersion}

有关更多详细信息,请参阅

https://docs.microsoft.com/en-us/rest/api/monitor/metricdefinitions/metricdefinitions_list https://docs.microsoft.com/en-us/azure/monitoring-and-diagnostics/monitoring-rest-api-walkthrough

答案 1 :(得分:1)

要获取指标定义,请使用此剩余API

  

https://management.azure.com/subscriptions/ {subscriptionId} / resourceGroups / {resourceGroupName} / providers / {resource   ProviderNamespace} / {资源   类型} / {resourceName} /providers/microsoft.insights/metricdefinitions?api-version=2018-01-01

要使用可选参数获取指标,请使用此剩余API

  

https://management.azure.com/subscriptions/ {subscriptionId} / resourceGroups / {resourceGroupName} /providers/microsoft.insights/metrics?timespan= {timeSpan}&interval = {timeGranularity}&aggregation = {AggregationType}&metricnames = {metricName}&api-version = 2018-01-01

答案 2 :(得分:1)

您错过了请求网址中的资源类型和名称,该网址应如下所示:

https://management.azure.com/{resourceUri}/providers/microsoft.insights/metricDefinitions

参考:https://docs.microsoft.com/en-us/rest/api/monitor/metricdefinitions/list

如果要列出事件网格的度量标准定义,则您的网址应为:

GET https://management.azure.com/subscriptions/{subscription id}/resourceGroups/{resource group name}/providers/Microsoft.EventGrid/topics/{event grid topic name}/providers/microsoft.insights/metricDefinitions?api-version=2018-01-01

测试结果:

enter image description here