How to get Azure VM Guest Metrics (Performance Counters) through an API?

Occasional Visitor

Able to retrieve Azure VM Host Metrics using Azure Management API call.


When trying to fetch performance counters using Azure Log Analytics API as per below reference link, it is  generating below error.


"error": {
"message": "Valid authentication was not provided",
"code": "AuthorizationRequiredError",
"innererror": {
"code": "UnsupportedKeyError",
"message": "The given API Key is not valid for the request"


Can you please provide anyone how to obtain these by correcting above error?

DEMO_KEY : key generated after registering app under Azure AD App registrations and providing owner permissions for registered app to access Log Analytics services.

1 Reply


I think you might have mixed the logs and metrics APIs, which are separate. Logs contain a lot of performance data, some of which also covered by Metrics, which might be confusing.

To query, for example, the top 3 highest-memory using computers you want to run this query over Log Analytics:


| where TimeGenerated > ago(1h) 
| where ObjectName == \"Memory\" and CounterName == \"Used Memory MBytes\" 
| summarize average_used_memory=avg(CounterValue) by Computer 
| top 3 by average_used_memory

(note this specific counter name is reported for Linux machines only). To run this through the API, post the query in a JSON format (shown below) to "" (url for the demo workspace API) and add the 2 required headers, as shown below:

API query.png

You can find the details here.