0
votes

Is there a way to get the total size of the blobs in a storage account blobs container without iterating over them and summing up the length?

Preferably from the Java API or CLI.

We are required to get the up to date size on a regular basis and will have a large amount of blobs in the container, and we will have a lot of containers, therefore its not feasible to iterate over the blobs every time to get the sizes.

2
for cli, you can refer to this link, but the bc command seams cannot be used.Ivan Yang
Ye although that iterates over the blobs list and bc is summing the length of each blob. This takes too long for our purpose and to do this on a regular basis will cost a lot in the amount of reads that will be done.Clive
@Clive Could you accept the answer to close your question since it's by design?Jerry Liu

2 Answers

1
votes

I am afraid it's not possible to bypass blob listing and summing up operation to get the size of container(i.e. blobs inside it). All SDKs are based on REST API, which includes all operation interfaces exposed to us. According to those APIs, we can only get the list of blobs and sum up their content length.

See an official example. There's a Calculate size on Azure portal, right click on our container and click Container properties, we can see panel as below. Try to catch the http traffic, we can see it calls list blob operation. The Learn more link shows a powershell script to realize the unavoidable process. (Note that once blob count is over 5000, Calculate size displays Blob Count>5000 and Size>XXMiB).

Calculate size

0
votes

Maybe you can use Azure Monitor API which in itself would be using Azure Metrics, so call its API via REST and it over the time keeps stats so maybe that way you can get to what you need, otherwise i do not see any other way.