Azure Storage Accounts are a fundamental part of cloud storage in Microsoft Azure, providing various types of storage services such as blobs, files, tables, and queues. Understanding the total size allocated to a storage account and the usage breakdown per service type is crucial for optimizing costs, managing capacity, and ensuring efficient data storage management.
In this article, we’ll explore how to retrieve storage allocation and usage details for an Azure Storage Account using different methods, including PowerShell, Azure CLI, and Kusto Query Language (KQL). By following these steps, you will gain better visibility into your storage consumption and take informed actions to optimize your resources.
Why Monitor Azure Storage Usage?
Monitoring your Azure Storage usage is a proactive step toward efficient cloud resource management. Without proper tracking, storage costs can escalate, performance may degrade, and compliance requirements may be overlooked. By keeping an eye on storage consumption, organizations can optimize their cloud storage investment and maintain a well-structured data management strategy.
Before diving into the methods, let’s understand why monitoring storage usage is important:
- Cost Management – Azure Storage costs are based on the amount of data stored. Monitoring storage usage helps avoid unexpected expenses.
- Performance Optimization – Excessive storage usage can lead to performance bottlenecks. Keeping track of storage distribution helps in optimizing workloads.
- Capacity Planning – Understanding the usage trends aids in planning for future capacity needs.
- Compliance & Governance – Some regulatory frameworks require regular monitoring and reporting of storage usage.
By regularly reviewing storage consumption, businesses can not only control costs but also ensure data integrity, security, and optimal performance.
Methods to Retrieve Storage Account Usage Information
Retrieving storage usage information in Azure can be done using multiple methods, each suited for different needs. Whether you prefer scripting with PowerShell, using command-line tools like Azure CLI, or leveraging Azure Monitor’s built-in telemetry with Kusto Query Language (KQL), these approaches provide powerful insights into your storage consumption.
Each method varies in complexity and depth of information, allowing users to choose the most suitable approach based on their technical proficiency and specific monitoring requirements. Below, we explore three key methods to retrieve storage account usage information.
1. Using Azure PowerShell
Azure PowerShell is a command-line scripting environment that allows users to manage Azure resources programmatically. It is particularly useful for automating storage management tasks and retrieving detailed metrics on storage consumption. By using Azure PowerShell, you can efficiently monitor storage account usage, check resource allocation, and generate reports for capacity planning. This method is ideal for administrators who prefer scripting-based management and need to execute batch operations across multiple storage accounts.
PowerShell Script to Get Storage Usage
# Set variables
$resourceGroupName = "YourResourceGroupName"
$storageAccountName = "YourStorageAccountName"
# Get storage account details
$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName
# Retrieve usage details
$usage = Get-AzStorageUsage -StorageAccount $storageAccount
# Display storage usage information
$usage | Format-Table Name, CurrentValue, Limit
This script retrieves the total allocated storage and current consumption. The Limit
value represents the maximum quota available.
2. Using Azure CLI
Azure CLI is a cross-platform command-line tool that enables users to manage Azure resources efficiently. It is particularly useful for those who prefer a command-line approach over scripting with PowerShell. With Azure CLI, you can quickly retrieve storage usage metrics, automate storage management tasks, and integrate storage monitoring into larger automation workflows. This method is ideal for developers and IT professionals who need a straightforward and fast way to check storage allocation and usage details.
CLI Command to Get Storage Usage
az storage account show-usage --resource-group YourResourceGroupName --name YourStorageAccountName
This command returns storage usage details, including the allocated and consumed capacity.
3. Using Azure Monitor Metrics with KQL Queries
Azure Monitor is a powerful tool that provides deep insights into Azure resource utilization, including storage account metrics. By leveraging Kusto Query Language (KQL), users can extract, analyze, and visualize storage usage data over time. This method is particularly beneficial for those who need historical storage usage trends, real-time monitoring, and automated alerts based on storage consumption thresholds.
KQL queries enable users to interact with structured log data efficiently, making it a preferred choice for data analysts and administrators looking to optimize Azure storage costs and capacity planning. If you are managing multiple storage accounts or large-scale applications, Azure Monitor and KQL provide a scalable way to monitor storage allocation and consumption trends.
Prerequisites:
- Enable Azure Monitor for your storage account.
- Access Log Analytics in the Azure Portal.
KQL Query to Get Storage Consumption
AzureMetrics
| where ResourceId contains "YourStorageAccountName"
| where MetricName == "UsedCapacity"
| summarize TotalUsedStorage = max(Total) by bin(TimeGenerated, 1d)
This query retrieves the maximum storage used for a given time period.
Analyzing Storage Usage by Type (Blobs, Files, Tables, Queues)
Azure Storage provides different types of storage services. To get usage per service type, you can use PowerShell or KQL queries.
1. Blob Storage Usage
Get-AzStorageBlobContainer -Context $storageAccount.Context | Select-Object Name, @{Name="SizeGB"; Expression={($_.Properties.Length/1GB)}}
This script lists all blob containers and their respective sizes.
2. File Share Storage Usage
Get-AzStorageShare -Context $storageAccount.Context | Select-Object Name, @{Name="SizeGB"; Expression={($_.Properties.Quota/1GB)}}
Retrieves allocated and used space for file shares.
3. Queue and Table Storage Usage
Queue and Table storage usage can be retrieved via Azure Metrics Explorer or Log Analytics using queries similar to the KQL query mentioned earlier.
Conclusion
Monitoring Azure Storage usage is essential for cost efficiency, performance, and scalability. By using PowerShell, Azure CLI, and KQL queries, you can retrieve detailed storage allocation and consumption insights.
By implementing these methods, you can:
✅ Optimize costs by tracking and managing unused storage.
✅ Plan storage capacity efficiently based on real-time insights.
✅ Ensure compliance with data governance policies.
Start monitoring your Azure Storage Accounts today to take control of your cloud storage resources!
Original Article Source: Get Total Size Allocated to Azure Storage Account (Blobs, Files, Tables and Queues) written by Chris Pietschmann (If you’re reading this somewhere other than Build5Nines.com, it was republished without permission.)