I'm trying to access $MetricsCapacityBlob (SO: Azure Storage Table size) to see the total size of blobs on my azure account. This is what I have:
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
var cloudTableClient = storageAccount.CreateCloudTableClient();
var table = cloudTableClient.GetTableReference("$MetricsCapacityBlob");
var query = new TableQuery();
var result = table.ExecuteQuery(query).ToList();
Problem is, result
is always 0 length. What am I doing wrong?
Problem is, result is always 0 length. What am I doing wrong?
Your code looks OK to me. In fact I ran this code against this table in one of my storage accounts and it returned results. You could be getting no results back because there may be no data in the table. Did you create the storage account recently? Give it some time and data will show up.
Alternate Solution
Also, there's another way of working with Storage Analytics data and that is by using AnalyticsClient
namespace in storage client library. See the sample code below which fetches the storage size for yesterday.
CloudStorageAccount account = new CloudStorageAccount(new StorageCredentials(StorageAccount, StorageAccountKey), true);
var client = account.CreateCloudAnalyticsClient();
var yesterday = DateTime.UtcNow.Date.AddDays(-1).ToString("yyyyMMddT0000");
var queryResult = client.CreateCapacityQuery().Where(q => q.PartitionKey == yesterday).ToList();
foreach (var item in queryResult)
{
Console.WriteLine(item.RowKey + " = " + item.Capacity);
}