Reputation: 2483
Looking at the Metrics available through the azure Metrics API disk space, nor free memory, are available as metrics.
Now I know I can view these metrics through the portal using this.
But I'm specifically looking to query this data on a regular basis to alert me when any of my VMs disk space is nearly full (or memory is nearly full).
Is there any way of doing this?
Upvotes: 1
Views: 4150
Reputation: 992
If you collect disk space / free memory as custom metrics in Azure Monitor, you will be able to query them via the standard Azure Monitor Metrics REST API. For example, you can use Windows Azure Diagnostics (WAD) to collect these performance counters on Windows VM and send them as custom metrics.
https://learn.microsoft.com/en-us/azure/azure-monitor/platform/metrics-custom-overview
https://learn.microsoft.com/en-us/azure/azure-monitor/platform/rest-api-walkthrough
Upvotes: 1
Reputation: 3484
If you ultimate goal is to
For all the above mentioned ways to work, you would have to first
If your Azure VM is of Windows OS then query to find disk Total free space is:
Perf
| where ( ObjectName == "LogicalDisk" )
| where ( CounterName == "% Free Space" )
| where ( InstanceName == "_Total" )
| summarize AggregatedValue= avg(CounterValue) by Computer, bin(TimeGenerated, 30s)
If your Azure VM is of Windows OS then query to find disk C drive free space is:
Perf
| where ( ObjectName == "LogicalDisk" )
| where ( CounterName == "% Free Space" )
| where ( InstanceName == "C:" )
| summarize AggregatedValue= avg(CounterValue) by Computer, bin(TimeGenerated, 30s)
If your Azure VM is of Linux OS then query to find disk Total free space is:
Perf
| where ( ObjectName == "Logical Disk" )
| where ( CounterName == "% Free Space" )
| where ( InstanceName == "_Total" )
| summarize AggregatedValue= avg(CounterValue) by Computer, bin(TimeGenerated, 30s)
If your Azure VM is of Linux OS then query to find disk mounted on Root free space is:
Perf
| where ( ObjectName == "Logical Disk" )
| where ( CounterName == "% Free Space" )
| where ( InstanceName == "/" )
| summarize AggregatedValue= avg(CounterValue) by Computer, bin(TimeGenerated, 30s)
If your Azure VM is of Linux OS then query to find Available MBytes memory is:
Perf
| where ( ObjectName == "Memory" )
| where ( CounterName == "Available MBytes Memory" )
| summarize AggregatedValue= avg(CounterValue) by Computer, bin(TimeGenerated, 30s)
If your Azure VM is of Windows OS then query to Available MBytes is:
Perf
| where ( ObjectName == "Memory" )
| where ( CounterName == "Available MBytes" )
| summarize AggregatedValue= avg(CounterValue) by Computer, bin(TimeGenerated, 30s)
If your Azure VM is of Windows OS then query to find Committed Bytes In Use is:
Perf
| where ( ObjectName == "Memory" )
| where ( CounterName == "% Committed Bytes In Use" )
| summarize AggregatedValue= avg(CounterValue) by Computer, bin(TimeGenerated, 30s)
Note1: For all the above mentioned queries to work, make sure the respective performance counters are added in Azure Portal -> Log Analytics workspaces -> Your Log Analytics workspace -> Advanced settings -> Data -> Windows Performance Counters / Linux Performance Counters.
Note2: Using other performance counters, you can also fetch much more data like Disk read time, Disk write time, Idle time, current disk queue length, cache bytes, commited bytes, page faults, page reads, page writes, free inodes, etc.
Hope this helps! Cheers!
Upvotes: 5
Reputation: 18387
You can use powershell and execute scripts remotely:
https://learn.microsoft.com/en-us/azure/virtual-machines/windows/run-command
and/or
To get the metrics you want:
How to get free physical memory of remote computer using PowerShell
How to get disk capacity and free space of remote computer
Upvotes: 1