1
votes

We have an Azure App Service Plan running a Web Job, I can see the CPU percentage used in the Azure portal when I look at the Service Plan, and I want to get this information from the REST API. I can get the information, however I don't know what I'm doing wrong as the information I get doesn't match up with what the portal shows.

Here's the URL I'm getting:

https://management.azure.com/subscriptions/{MySubscriptionId}/resourceGroups/My-Resouce-Group/providers/Microsoft.Web/serverFarms/My-App-Service-Plan/providers/microsoft.insights/metrics?$filter=name.value%20eq%20'CpuPercentage'%20and%20(aggregationType%20eq%20'None'%20or%20aggregationType%20eq%20'Average'%20or%20aggregationType%20eq%20'Minimum'%20or%20aggregationType%20eq%20'Maximum'%20or%20aggregationType%20eq%20'Total'%20or%20aggregationType%20eq%20'Count')%20and%20startTime%20eq%202017-10-03T08:55:00Z%20and%20endTime%20eq%202017-10-03T09:00:00Z&api-version=2016-09-01

At 8:55 the portal shows just under 20% CPU usage, however what I get back from the REST API at this time is this:

"total":1.0,"count":1.0,"average":1.0,"minimum":1.0,"maximum":1.0

What do I need to do to get the data that is shown in the portal?

1

1 Answers

1
votes

According to your description, I have create a test demo on my side, it works well.

The result is the same.

I guess may be something wrong with your filter parameters.

I suggest you could try my url and test again.

https://management.azure.com/subscriptions/{subscription}/resourceGroups/{name}/providers/Microsoft.Web/serverFarms/{name}/providers/microsoft.Insights/metrics?api-version=2016-09-01&$filter=(name.value%20eq%20'CpuPercentage')%20and%20(aggregationType%20eq%20'Average'%20or%20aggregationType%20eq%20'Minimum')%20and%20startTime%20eq%202017-10-04T01:26:41.812Z%20and%20endTime%20eq%202017-10-04T02:26:41.812Z%20and%20timeGrain%20eq%20duration'PT1M'

Result:

enter image description here

Besides, you could also get the filter directly from azure portal.

You could use browser F12 to check the request details from azure monitor.

Details, you could refer to this image:

enter image description here