def get_used_avg_blob_capacity()

in azure-metrics-calc-storage-size/metrics-data.py [0:0]


def get_used_avg_blob_capacity(credentials,subscription_id):
    
    resource_client = ResourceManagementClient(credentials, subscription_id)
    storage_client = StorageManagementClient(credentials, subscription_id)
    
    lst = []
    count = 0
    resource_groups = resource_client.resource_groups.list()

    for group in resource_groups:        
        
        storage_accounts = storage_client.storage_accounts.list_by_resource_group(group.name)
        
        for storage_account in storage_accounts:

            print("Reading metric data from storage account: " + storage_account.name)
            count += 1
            
            blob_size = get_metric_data_capacity(group.name, storage_account.name, 
                                        subscription_id, Metric_type.blob_capacity)
            file_size = get_metric_data_capacity(group.name, storage_account.name, 
                                        subscription_id, Metric_type.fileshare_capacity)
            
            total_size = blob_size + file_size
            
            if math.isnan(total_size):
                total_size_friendly = ''
            else:
                total_size_friendly = humanfriendly.format_size(total_size)
            
            lst.append([storage_account.name, group.name, blob_size, file_size, total_size, total_size_friendly])
            
    print("Total number of storage accounts: "+ str(count))
    cols = ['Storage account', 'Resource group', 'Blob capacity', 'File capacity', 'Total capacity', 'Total capacity (friendly)']
    df = pd.DataFrame(lst, columns=cols)
    
    file_name = 'metrics_' + datetime.datetime.now().strftime('%m-%d-%y-%H%M%S') + '.csv'
    df.to_csv(file_name, header=cols, index=False)
    print("\n")
    print("Metrics saved to file: " + file_name)
    return file_name