I'm publishing a custom metric called "ConnectionCount" on my AppInsights component. I'm looking for a way to query the last values for that metric in a PowerShell script.
I've used this command in the past:
$resourceId = "/subscriptions/$subscriptionId/resourceGroups/MyResourceGroup/providers/microsoft.insights/components/MyAppInsight" Get-AzureRmMetric -ResourceId $resourceId -TimeGrain $timeGrain -StartTime $startTime -MetricNames $metric`
But when run this, I just get an error back:
Get-AzureRmMetric : Operation returned an invalid status code 'NotFound'
I also tried the REST API, using this code:
$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
But it simply gives me back an empty response.
Does anyone know if something has changed in the Metrics API that would prevent custom metrics values to be retrieve from PowerShell or the REST API?