Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Storage container size

How can I get a size of container in Azure Storage? I access Azure storage via C# API:

var account = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["AzureStoragePrimary"]);
var client = account.CreateCloudBlobClient();
var container = client.GetContainerReference("myContainer");
like image 363
Václav Dajbych Avatar asked Jan 17 '13 10:01

Václav Dajbych


People also ask

How do I tell the size of my Azure storage container?

There's a Calculate size on Azure portal, right click on our container and click Container properties, we can see panel as below. Please let us know if you have any further queries.

How many containers does an Azure storage hold?

No, there's no limit on the number of storage containers in a storage account. You're limited by the size of the storage account which was recently increased to 500 TB from 200 TB .

How to get the size of all storage accounts in azure?

How to get the size of all Storage Accounts using the Azure portal Log into the Azure portal Select Monitor from the left hand panel or use the search bar at the top Select Storage Accounts from the left hand pane under the Insights section

What is the Blob Storage size for Azure?

The 200 TB blob size is available for preview in all Azure public regions with hot, cool, archive, and premium tiers. There are no billing changes. Learn more to get started. Azure Blob Storage Features Back to Azure Updates

How do I calculate storage capacity in azure?

2. Calculate the capacity at the single storage account and different service level (Blob/Queue/Table/File) – via Portal. In the Azure portal, select Storage accounts. From the list, choose a storage account. In the Monitoring section, choose Insights (preview).

How to get the size of a container in a storage account?

Inside the Properties view you will have a button at the bottom to “Calculate Size”. Click on this button to get the size of the Container. 8. Now you are presented with the Blob Container Size. Phew we finally got there. So that is how you can get the size of a Container in a Storage Account using the Azure portal.


2 Answers

A potentially more complete approach. The key difference, is the second param in the listblobs() call, which enforces a flat listing:

public class StorageReport
{
    public int FileCount { get; set; }
    public int DirectoryCount { get; set; }
    public long TotalBytes { get; set; }
}

//embdeded in some method
StorageReport report = new StorageReport() { 
    FileCount = 0,
    DirectoryCount = 0,
    TotalBytes = 0
};


foreach (IListBlobItem blobItem in container.ListBlobs(null, true, BlobListingDetails.None))
{
    if (blobItem is CloudBlockBlob)
    {
        CloudBlockBlob blob = blobItem as CloudBlockBlob;
        report.FileCount++;
        report.TotalBytes += blob.Properties.Length;
    }
    else if (blobItem is CloudPageBlob)
    {
        CloudPageBlob pageBlob = blobItem as CloudPageBlob;

        report.FileCount++;
        report.TotalBytes += pageBlob.Properties.Length;
    }
    else if (blobItem is CloudBlobDirectory)
    {
        CloudBlobDirectory directory = blobItem as CloudBlobDirectory;

        report.DirectoryCount++;
    }                        
}
like image 178
pim Avatar answered Sep 19 '22 03:09

pim


CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["AzureStoragePrimary"]);
CloudBlobClient blobClient = account.CreateCloudBlobClient();
CloudBlobContainer blobContainer = blobClient.GetContainerReference("myContainer");
int fileSize = 0;
foreach (var blobItem in blobContainer.ListBlobs())
{
    fileSize += blobItem.Properties.Length;
} 

fileSize contains the size of container, i.e. total size of blobs (files) contained.

Reference: CloudBlob: http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storageclient.cloudblob_methods.aspx

like image 29
Raptor Avatar answered Sep 19 '22 03:09

Raptor