A veces, necesitas determinar el tamaño total asignado a una cuenta de almacenamiento y el tamaño consumido para cada uno de sus tipos de almacenamiento (colas, tablas, blobs y archivos) y no hay manera directa de poder obtener esa información, a continuación, te compartir un script en PowerShell y otro en Kusto Query Language (KQL) que pueden ayudarte a conseguir esa información:
PowerShell
# Login to your Azure account
Connect-AzAccount
# Set the context to the subscription that contains your storage account
Set-AzContext -SubscriptionId <SubscriptionId>
# Retrieve the total allocated size of the storage account
$storageAccountName = "<StorageAccountName>"
$resourceId = "/subscriptions/<SubscriptionId>/resourceGroups/<ResourceGroupName>/providers/Microsoft.Storage/storageAccounts/$storageAccountName"
$metric = Get-AzMetric -ResourceId $resourceId -TimeGrain PT1H -MetricName BlobCapacity -AggregationType Total -StartDate (Get-Date).AddDays(-1) -EndTime (Get-Date)
$totalSize = $metric.Data | Select-Object -ExpandProperty Total | Select-Object -First 1
# Retrieve the consumed size for each storage type
$usage = Get-AzStorageAccountUsage -ResourceGroupName <ResourceGroupName> -Name $storageAccountName
$blobSize = $usage | Where-Object {$_.Name.Value -eq "BlobCapacity"} | Select-Object -ExpandProperty CurrentValue
$tableSize = $usage | Where-Object {$_.Name.Value -eq "TableCapacity"} | Select-Object -ExpandProperty CurrentValue
$queueSize = $usage | Where-Object {$_.Name.Value -eq "QueueCapacity"} | Select-Object -ExpandProperty CurrentValue
$fileSize = $usage | Where-Object {$_.Name.Value -eq "FileCapacity"} | Select-Object -ExpandProperty CurrentValue
# Print the results
Write-Host "Total allocated size: $totalSize bytes"
Write-Host "Blob consumed size: $blobSize bytes"
Write-Host "Table consumed size: $tableSize bytes"
Write-Host "Queue consumed size: $queueSize bytes"
Write-Host "File consumed size: $fileSize bytes"
Kusto Query Language (KQL)
AzureStorageCapacity
| where ResourceId contains "/providers/Microsoft.Storage/storageAccounts/"
| where ResourceId contains "<StorageAccountName>"
| summarize TotalAllocatedSize = sum(TotalCapacity) by StorageType
| join (
AzureStorageUsage
| where ResourceId contains "/providers/Microsoft.Storage/storageAccounts/"
| where ResourceId contains "<StorageAccountName>"
| summarize CurrentUsage = sum(CurrentValue) by StorageType
) on StorageType
| project StorageType, TotalAllocatedSize, CurrentUsage
Más información How to get the total size allocated to a Storage account and the for types like Queues, tables, blobs and files. – Stack Overflow
Puedes seguirme en Twitter o en LinkedIn, donde comparto mis proyectos, experiencias y próximos eventos en los que estaré participando.
Gracias por leerme y hasta la próxima.