Reputation: 191
I'm using the AZ metrics command found in the answer posted below which usually works but every so often the result returns 0, even though I know the account is consuming storage. Also, if I run the same command against the same resource a little while later it returns the real result. Is anyone else using this method and finding similar results? Any suggestions to get around this?
Also, is it possible to use timegrain/timespan against a Storage Account?
List used space for blobs, files, tables, queues using PowerShell?
For reference, the command I'm using is: (Get-AzMetric -ResourceId "{resource_id}" -MetricName "UsedCapacity").Data
Upvotes: 0
Views: 1810
Reputation: 49
The issue is that Azure does not always record a reading if the storage account is not in continuous use or its glitched. You can see this when you view the usage graph within the resource, it shows a dotted line this is the missing data. Azure only records a reading when the storage account is active which makes sense from a performance perspective.
The way to get a valid result is to increase the window for the data points to return. My fix was as follows
$UsedCapacityDay = (Get-AzMetric -ResourceId <storage account ID> -StartTime (Get-Date).adddays(-1) -EndTime (Get-Date) -MetricName "UsedCapacity")
# need to use this method as some data points have a null reading, query above returns 24 hours (24 readings)
# with a value in the "average" property other properties min/max are always null
# we don't actually want an average for space so we get the max
$UsedCapacity = $UsedCapacityDay.data.average | measure-object -max
Azure Storage Resource Provider only reports the Availability data to Azure Monitor when there is ongoing activity Link for above statement
Upvotes: 0
Reputation: 22597
I tried to reproduce the same in my environment and faced the same issue.
When I ran the command again after some time, got null value like below:
After a while, when I ran the above command again, it gave the response successfully.
This issue usually happens because capacity metrics values will be refreshed daily (up to 24 Hours).
$DebugPreference = "Continue"
.As a workaround, you can make use of timegrain/timespan against the storage account like below:
(Get-AzMetric -ResourceId "your_resource_id" -MetricName "UsedCapacity" -AggregationType Average -StartTime "02:00:00" -EndTime "04:00:00").Data
If still the issue persists, raise a bug/Azure support ticket.
References:
0-Value Result Get-AzMetric (UsedCapacity) · Issue #15863 · Azure/azure-powershell · GitHub
Get-AzMetric Returns Blank Results - githubmemory
Upvotes: 2