I am trying to get the maximum value of Data Disk Read Bytes/Sec and Data Disk Write Bytes/Sec over a period of 30days for all the data disks (Premium SSD) in my subscription using Get-AzMetric.
I am getting below error when using the Get-AzMetric command.
Get-AzMetric: Exception type: ErrorResponseException, Message: Microsoft.Azure.Management.Monitor.Models.ErrorResponseException: Operation returned an invalid status code 'BadRequest'
What should be changed? I have to use the DISK ID and not the VM ID and I need to use PowerShell for automating the values.
This is my code:
$write_metricName = "Data Disk Write Bytes/Sec"
$et = Get-Date
$st = (Get-Date).AddDays(-30)
# Resource Id is of data disk
$resourceId = "/subscriptions/XXXXX/resourceGroups/rg-xxxxx/providers/Microsoft.Compute/disks/disk-xxxx-01"
$write_metric_avg = Get-AzMetric -ResourceId $resourceId -StartTime $st -EndTime $et -TimeGrain 00:01:00 -MetricName $write_metricName -DetailedOutput -AggregationType Maximum
If I provide resourceId
of the VM instead of the Data Disk, this works just fine for me.
I am currently running this in Cloudshell from Azure portal. Below are the version details:
PS /home/o365> Get-InstalledModule -Name Az -AllVersions | select Name,Version
Name Version
---- -------
Az 9.4.0
PS /home/o365> $PSVersionTable.PSVersion
Major Minor Patch PreReleaseLabel BuildLabel
----- ----- ----- --------------- ----------
7 3 2