【问题标题】:How to get blobs size through $MetricsCapacityBlob如何通过 $MetricsCapacityBlob 获取 blob 大小
【发布时间】:2017-08-22 16:41:08
【问题描述】:

我正在尝试访问 $MetricsCapacityBlob(SO:Azure Storage Table size)以查看我的 azure 帐户中 blob 的总大小。这就是我所拥有的:

        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);

        var cloudTableClient = storageAccount.CreateCloudTableClient();

        var table = cloudTableClient.GetTableReference("$MetricsCapacityBlob");

        var query = new TableQuery();
        var result = table.ExecuteQuery(query).ToList();

问题是,result 的长度始终为 0。我做错了什么?

【问题讨论】:

  • 文档 (msdn.microsoft.com/library/azure/hh343264.aspx) sais 存储容量指标每天仅更新一次。因此,如果您刚刚启用存储分析并尝试此代码,它将返回 0 条记录。同时您可以使用任何存储工具来检查表格内容并与您的代码进行比较以避免混淆。

标签: c# azure azure-storage


【解决方案1】:

问题是,结果总是 0 长度。我做错了什么?

您的代码在我看来没问题。事实上,我在我的一个存储帐户中针对这张表运行了这段代码,它返回了结果。您可能没有得到任何结果,因为表中可能没有数据。您最近是否创建了存储帐户?给它一些时间,数据就会显示出来。

替代解决方案

此外,还有另一种处理存储分析数据的方法,即在存储客户端库中使用 AnalyticsClient 命名空间。请参阅下面的示例代码,该代码获取昨天的存储大小。

        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);
        }

【讨论】:

  • “Microsoft.WindowsAzure.Storage.CloudStorageAccount”不包含“CreateCloudAnalyticsClient”的定义。我错过了什么吗?
  • 您使用的是哪个版本的库?这是在较新的版本之一中引入的。
  • 2.1.我想大概就是这样。分析客户端除了从监控表中提取数据之外还有什么其他功能吗?
  • 我同意这个版本。它是在版本 4.0.0.0 (github.com/Azure/azure-storage-net/blob/master/…) 中引入的。关于Does the analytics client does anything other than pull data from the monitoring tables? - 它负责将表数据反序列化为适当的实体,如果您使用 TableClient 代替,您需要自己完成。 HTH。
  • 您的意思是 SDK 2.5,对吗?请检查项目中存储客户端库的版本。应该是 4+。
【解决方案2】:

这是在 Asp.NET Core 1.1 中使用 Microsoft.WindowsAzure.Storage 版本 8.1.1.0 的另一个替代解决方案。

            CloudTableClient tableClient = _storageAccount.CreateCloudTableClient();
            CloudTable metricsCapacityTable = tableClient.GetTableReference(Constants.AnalyticsConstants.MetricsCapacityBlob);

            List<string> selectedColumns = new List<string>();
            selectedColumns.Add("Capacity");

            string yesterday = DateTime.UtcNow.Date.AddDays(-1).ToString("yyyyMMddT0000");

            dataResult = await metricsCapacityTable.ExecuteAsync(TableOperation.Retrieve(yesterday, "data", selectedColumns));

            DynamicTableEntity ddte = (DynamicTableEntity)dataResult.Result;
            double? dataValueInBytes = ddte.Properties["Capacity"].Int64Value;

【讨论】:

    猜你喜欢
    • 2015-09-16
    • 2014-10-06
    • 1970-01-01
    • 2018-05-07
    • 1970-01-01
    • 2011-09-26
    • 1970-01-01
    • 1970-01-01
    • 2011-08-05
    相关资源
    最近更新 更多