1

我已经编写了一个独立的代码来获取 Azure 存储 Blob 服务的指标,但我只想获得最后 5 分钟的指标,如何从 $MetricsMinutePrimaryTransactionsBlob 获取它请建议

CloudTable cloudMetric = tableClient.getTableReference(cloud
                .getHourMetricsTable(StorageService.BLOB).getName());
        String partitionFilter2 = TableQuery.generateFilterCondition(
                "PartitionKey", QueryComparisons.EQUAL, "20170602T1400");
        String rowFilter3 = TableQuery.generateFilterCondition("RowKey",
                QueryComparisons.EQUAL, "user;All");
        String combinedFilter = TableQuery.combineFilters(partitionFilter2,
                Operators.AND, rowFilter3);
        TableQuery<MetricsPojo> partitionQuery2 = TableQuery.from(
                MetricsPojo.class).where(combinedFilter);
        for (MetricsPojo capacityMetrics2 : cloudMetric
                .execute(partitionQuery2)) {
            System.out.println(capacityMetrics2);
            System.out.println(capacityMetrics2.getPartitionKey() + "\n"
                    + capacityMetrics2.getRowKey() + "\n"
                    + capacityMetrics2.getTimestamp());
4

2 回答 2

1

根据您的描述和@FrancisYu-MSFT 的回复,我写了一个示例代码并复制了您当前的问题。

这是我的示例代码。

String connectionString = String.format("DefaultEndpointsProtocol=http;AccountName=%s;AccountKey=%s", ACCOUNT_NAME, ACCOUNT_KEY);
CloudStorageAccount account = CloudStorageAccount.parse(connectionString);
CloudAnalyticsClient client = account.createCloudAnalyticsClient();
CloudTable metrics = client.getMinuteMetricsTable(StorageService.BLOB);
System.out.println(metrics.getName());
String queryString = TableQuery.combineFilters(
                TableQuery.generateFilterCondition("PartitionKey", QueryComparisons.GREATER_THAN_OR_EQUAL, "20170602T1400"),
                Operators.AND,
                TableQuery.generateFilterCondition("PartitionKey", QueryComparisons.LESS_THAN_OR_EQUAL, "20170602T1420"));
TableQuery<TableServiceEntity> query = TableQuery.from(TableServiceEntity.class).where(queryString);
for(TableServiceEntity entity : metrics.execute(query)) {
    System.out.println(entity.getPartitionKey()+"\t"+entity.getRowKey());
}

然后我在运行我的代码时遇到了同样的问题,这是由于metrics表$MetricsMinutePrimaryTransactionsBlob不存在导致的,因此需要启用相关Diagnostics选项来创建它,如下图。

在此处输入图像描述

于 2017-06-05T10:10:33.260 回答
0

现在没有简单的方法来查询最后 5 分钟的行。由于 PartitionKey 是以分钟为单位的时间戳,您可以针对最近 20 分钟的行提出查询过滤器,并在本地从结果中查找最近 5 分钟的行。

TableQuery.combineFilters(
    TableQuery.generateFilterCondition("PartitionKey", QueryComparisons.GreaterThanOrEqual, "20170602T1400"),
    TableOperators.And,
    TableQuery.generateFilterCondition("PartitionKey", QueryComparisons.LessThanOrEqual, "20170602T1420"));
于 2017-06-02T22:13:22.077 回答