[英]How to Query Azure Storage metrics for last five minutes using Java SDK
I have written a stand alone code to get the metrics for Azure Storage Blob Services but i want to get only last 5mins metric how can i get it from $MetricsMinutePrimaryTransactionsBlob please suggest 我已经编写了一个独立的代码来获取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());
There is no simple way to query last 5 minutes rows now. 现在没有简单的方法来查询最近5分钟的行。 As PartitionKey is the time stamp in minute unit, you can propose the query filter for last 20 minutes rows and find last 5 minutes rows from the result locally.
由于PartitionKey是以分钟为单位的时间戳,因此您可以为最近20分钟的行建议查询过滤器,并从本地结果中查找最近5分钟的行。
TableQuery.combineFilters(
TableQuery.generateFilterCondition("PartitionKey", QueryComparisons.GreaterThanOrEqual, "20170602T1400"),
TableOperators.And,
TableQuery.generateFilterCondition("PartitionKey", QueryComparisons.LessThanOrEqual, "20170602T1420"));
According to your description and @FrancisYu-MSFT reply, I wrote a sample code and reproduced your current issue. 根据您的描述和@ FrancisYu-MSFT的回复,我编写了示例代码并复制了您当前的问题。
Here is my sample code. 这是我的示例代码。
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());
}
Then I got the same issue when running my code, which was caused by the metrics table $MetricsMinutePrimaryTransactionsBlob
not exists, so you need to enable the related Diagnostics
options to create it, as the figure below. 然后我在运行代码时遇到了同样的问题,这是由于指标表
$MetricsMinutePrimaryTransactionsBlob
不存在引起的,因此您需要启用相关的Diagnostics
选项来创建它,如下图所示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.