Azure Storage Classic Metrics

Alex 495 Reputation points
2023-12-19T03:39:35.6966667+00:00

Hello,

Is there a way to get the list of storage accounts that use classic metrics, through Resource Graph Explorer queries or Powershell or CLI script?

Thank you.

Azure Storage
Azure Storage
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
3,540 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Alex 495 Reputation points
    2023-12-20T05:16:14.34+00:00

    Thanks @Ravi Kanth Koppala .

    I wrote a PS script to fetch the list of storage accounts that have classic metrics enabled.

    Below is the script for fellow Azure enthusiasts who might be looking for the same.

    NOTE:

    1. This checks if the Hourly Metrics is enabled or not, which I understood from the documentation that Hourly Metrics are part of Classic metrics and is not present for SA that have Azure monitor metrics enabled.
    2. This checks only for the Blob and File types of storage account, modify the script to include other types (Table, Queue, Web, DFS,...) as needed.
    $az_tenant = Read-Host "Enter the Directory ID of Azure"
    Connect-AzAccount -TenantId $az_tenant -WarningAction SilentlyContinue | Out-Null
    
    # Get a list of subscriptions
    $subscriptions = Get-AzSubscription -TenantId $az_tenant
    
    # Create an empty array to store the results
    $results = @()
    
    # Iterate through each subscription
    foreach ($subscription in $subscriptions) {
    
        Select-AzSubscription -SubscriptionName $subscription -WarningAction SilentlyContinue | Out-Null
    
        # Get all the storage accounts in the subscription
        $storageAccounts = Get-AzStorageAccount
    
        # Loop through each storage account and check if it has classic metrics enabled
        foreach ($account in $storageAccounts) {
            if ($account.PrimaryEndpoints.Blob) {
                $diagnosticSettings = $account | Get-AzStorageServiceMetricsProperty -ServiceType Blob -MetricsType Hour
            } else {
                # Get the diagnostic settings for the storage account
                $diagnosticSettings = $account | Get-AzStorageServiceMetricsProperty -ServiceType File -MetricsType Hour
            }
            # Check if the diagnostic settings contain any metrics data
            if ($diagnosticSettings.MetricsLevel) {
                # Create a custom object to store the information for each storage account
                $object = [PSCustomObject]@{
                    SubscriptionName = $subscription.Name
                    AccountName = $account.StorageAccountName
                    Kind = $account.Kind
                    ClassicMetrics = "Enabled"
                    MetricsLevel = $diagnosticSettings.MetricsLevel
                    MetricsRetentionDays = $diagnosticSettings.RetentionDays
                }
            } else {
                # Create a custom object to store the information for each storage account
                $object = [PSCustomObject]@{
                    SubscriptionName = $subscription.Name
                    AccountName = $account.StorageAccountName
                    Kind = $account.Kind
                    ClassicMetrics = "Disabled"
                    MetricsLevel = $diagnosticSettings.MetricsLevel
                    MetricsRetentionDays = $diagnosticSettings.RetentionDays
                }
            }
            # Add the object to the results array
            $results += $object
        }
    }
    
    # Convert the results array to a table and display it
    $results | Format-Table -AutoSize
    
    2 people found this answer helpful.

  2. Ravi Kanth Koppala 3,391 Reputation points Microsoft Employee Moderator
    2023-12-19T10:10:00.2733333+00:00

    @Alex
    There is no direct way to get the list of storage accounts that use classic metrics through Resource Graph Explorer queries or PowerShell or CLI script. However, you can use the Azure portal to view which storage accounts have classic metrics enabled. To do this, go to the Azure portal, select "Storage accounts" from the left-hand menu, and then select the "Classic metrics" tab. This will show you a list of all storage accounts that have classic metrics enabled.


    References:

    AI Note: This answer is generated by the Microsoft Q&A AI Assist tool.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.