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

Copper Contributor

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

https://docs.microsoft.com/en-us/azure/virtual-machines/linux/metrics-vm-usage-rest

 

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

 

https://dev.loganalytics.io/apiexplorer/query?apiKey=DEMO_KEY&appId=DEMO_WORKSPACE&timespan=PT12H&qu...

 

{
"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

Hi,

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:

 

Perf 
| 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 "https://api.loganalytics.io/v1/workspaces/DEMO_WORKSPACE/query" (url for the demo workspace API) and add the 2 required headers, as shown below:

API query.png

You can find the details here.

 

HTH,

Noa