Norrin Rad
Norrin Rad

Reputation: 991

KQL Get Used Capacity on Storage Account

is there a way to query all storage accounts in subscriptions called "storage" and get the used capacity for each one. I'm trying to create an alert rule if they exceed 1024 gb capacity, but I'm not seeing used capacity anywhere. You can go into each storage account and configure the alert within the storage account, but that's not practical.

I can get some information from storage account using, this for availability:

AzureMetrics 
| where TimeGenerated > ago(1d)
| where ResourceProvider == "MICROSOFT.STORAGE"
| where _ResourceId contains "storage"
| where MetricName =~ "availability"
| project TimeGenerated, ResourceGroup, _SubscriptionId, Resource, MetricName, Average, UnitName

Thanks in advance :)

Upvotes: 1

Views: 3613

Answers (1)

David דודו Markovitz
David דודו Markovitz

Reputation: 44981

UsedCapacity

Exporting platform metrics to other locations

Using diagnostic settings is the easiest way to route the metrics, but there are some limitations:
Exportability. All metrics are exportable through the REST API, but some can't be exported through diagnostic

Microsoft.Storage/storageAccounts

Metric Exportable via Diagnostic Settings? Metric Display Name Unit Aggregation Type Description Dimensions
UsedCapacity Yes Used capacity Bytes Average The amount of storage used by the storage account. For standard storage accounts, it's the sum of capacity used by blob, table, file, and queue. For premium storage accounts and Blob storage accounts, it is the same as BlobCapacity or FileCapacity. No Dimensions
AzureMetrics
|   where ResourceProvider  == "MICROSOFT.STORAGE"
|   where MetricName        == "UsedCapacity"
|   where SubscriptionId    == "ebb79bc0-aa86-44a7-8111-cabbe0c43993"
|   summarize arg_max(TimeGenerated, ResourceGroup, Resource, Average) by _ResourceId

QueryResults

Fiddle

Upvotes: 1

Related Questions