如何从Powershell查询Azure AppInsights自定义度量

如何从Powershell查询Azure AppInsights自定义度量,powershell,azure,azure-application-insights,Powershell,Azure,Azure Application Insights,我正在AppInsights组件上发布一个名为“ConnectionCount”的自定义度量。 我正在寻找一种在PowerShell脚本中查询该度量的最后值的方法 我以前使用过这个命令: $resourceId = "/subscriptions/$subscriptionId/resourceGroups/MyResourceGroup/providers/microsoft.insights/components/MyAppInsight" Get-AzureRmMetric -Resou

我正在AppInsights组件上发布一个名为“ConnectionCount”的自定义度量。 我正在寻找一种在PowerShell脚本中查询该度量的最后值的方法

我以前使用过这个命令:

$resourceId = "/subscriptions/$subscriptionId/resourceGroups/MyResourceGroup/providers/microsoft.insights/components/MyAppInsight" Get-AzureRmMetric -ResourceId $resourceId -TimeGrain $timeGrain -StartTime $startTime -MetricNames $metric` 但它只是给了我一个空洞的回答


有人知道Metrics API中是否发生了某些变化,从而阻止从PowerShell或REST API检索自定义度量值吗?

如果您得到的是空响应(而不是任何类型的失败),那么我建议验证您的查询是否按预期进行,而不是过滤掉所有数据

我觉得你的过滤器很可疑,这部分
timeGrain eq duration'PT5M'
对我来说似乎是个奇怪的过滤器。通常,您会将范围和粒度指定为查询的其他部分,而不是在
$filter
部分中

我建议您使用API文档验证所有REST内容,并尝试在测试您的查询

嘿,你解决了这个问题吗?谢谢你的URL,我正在查看它,你是否需要在应用程序中安装AppInsights才能解决这些问题?我正在尝试提取CosmosDB的指标,并得到与OP相同的错误 $resourceGroupId = "subscriptions/$subscriptionId/resourceGroups/$resourceGroupName" $filter = "(name.value eq 'ConnectionCount') and timeGrain eq duration'PT5M' and " + "startTime eq 2017-07-20T17:00:47.8791884Z and endTime eq 2017-07-25T17:30:47.8832111Z" $apiVersion = "2015-05-01" $uri = "https://management.azure.com/$resourceGroupId/providers/microsoft.insights/components/$appInsightName/metrics?api-version=$apiVersion&`$filter=$filter" Invoke-RestMethod $uri -Headers $headers