0
votes

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?

1
Hey, did you get this resolved?Jeff Patton

1 Answers

0
votes

if you're getting an empty response (and not any kind of failure) then i'd suggest verifying that your query is doing what you expect and not filtering out all your data?

your filter looks really suspicious to me, this part timeGrain eq duration'PT5M' seems like an odd filter to me. normally you'd specify the range and the grain as other parts of the query, not inside the $filter part

i'd suggest verifying all of your REST stuff with the API docs at https://dev.applicationinsights.io, and try testing your query at https://dev.applicationinsights.io/apiexplorer/metrics