kc2001
kc2001

Reputation: 5247

How much disk is being used by Azure Blob Storage?

I'd like to determine how much disk space my Azure blobs are using via Azure's Java API. Basically, I'd like something similar to Unix's df command:

>df
Filesystem        1K-blocks      Used Available Use% Mounted on
C:/Tools/cygwin64 248717308 217102536  31614772  88% /

I've tried a variety of things, hoping that the information I want is in the CloudBlobContainer's metadata or properties, but apparently not. I've run the following code and examined the various variables in the debugger, but haven't seen anything close to what I'm looking for.

    CloudBlobContainer container = ...
    try {
        AccountInformation accountInfo = container.downloadAccountInfo();
        container.downloadAttributes();
        HashMap<String, String> metadata = container.getMetadata();
        BlobContainerProperties properties = container.getProperties();
        String string = metadata.toString();
    } catch (StorageException e) { // ...

I'm hoping I don't have to recursively process all of the blobs in the container. Is there a better way?

Upvotes: 0

Views: 595

Answers (1)

Gaurav Mantri
Gaurav Mantri

Reputation: 136196

For the individual blob container, the approach you're using is the only approach available today though I must say that it is not very efficient as it will only account for base blobs and not blob snapshots and versions. Furthermore if you're using page blobs then it will report the total capacity of those page blobs instead of occupied bytes.

However if you want to get the storage size for the entire storage account, one approach you can take a look at is Azure Storage Metrics. One of the metric available there is BlobCapacity which will tell you the total number of bytes occupied by all blobs in your storage account. You can learn more about the available metrics here: https://learn.microsoft.com/en-us/azure/azure-monitor/essentials/metrics-supported#microsoftstoragestorageaccountsblobservices.

Other option would be to look at consumption data through billing API. It's not that straightforward but it will give you the most accurate numbers because the numbers ultimately translate to your Azure bill. The REST API operation you would want to call is Usage Details - List.

Upvotes: 1

Related Questions