我编写了一个独立代码来获取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());
答案 0 :(得分:0)
现在没有简单的方法可以查询最后5分钟的行。由于PartitionKey是以分钟为单位的时间戳,因此您可以建议最后20分钟行的查询过滤器,并在本地查找结果的最后5分钟行。
TableQuery.combineFilters(
TableQuery.generateFilterCondition("PartitionKey", QueryComparisons.GreaterThanOrEqual, "20170602T1400"),
TableOperators.And,
TableQuery.generateFilterCondition("PartitionKey", QueryComparisons.LessThanOrEqual, "20170602T1420"));
答案 1 :(得分:0)
根据你的描述和@ 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());
}
然后我在运行代码时出现了同样的问题,这是由度量表$MetricsMinutePrimaryTransactionsBlob
不存在引起的,因此您需要启用相关的Diagnostics
选项来创建它,如下图所示