1

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

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());
Peter Pan
  • 23,476
  • 4
  • 25
  • 43

2 Answers2

1

According to your description and @FrancisYu-MSFT reply, I wrote a sample code and reproduced your current issue.

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.

enter image description here

Peter Pan
  • 23,476
  • 4
  • 25
  • 43
  • Thanks @Peter Pan i have activated all the metrics as you have suggested above now there is no error but there is no output either..does it take time to collect after i have activated it? Also the please suggest me how is the TimeStamp actually calculated for hourly metrics as i see for Partition key "20170602T1600" the time stamp is "Fri Jun 02 22:51:56 IST 2017" i'm confused isn't the Partition key the time ? – Abhishek B A Jun 05 '17 at 11:34
  • Pan i tried multiple times and i got the below result PartitionKey=20170605T1531 RowKey=system;All TimeStamp=Mon Jun 05 21:02:24 IST 2017 PartitionKey=20170605T1533 RowKey=system;All TimeStamp=Mon Jun 05 21:04:23 IST 2017 PartitionKey=20170605T1539 RowKey=system;All TimeStamp=Mon Jun 05 21:10:24 IST 2017 PartitionKey=20170605T1540 RowKey=system;All TimeStamp=Mon Jun 05 21:11:24 IST 2017 Please explain the concept /difference in PartitionKey and TimeStamp – Abhishek B A Jun 05 '17 at 16:22
  • @AbhishekBA After you had activated these Diagnostics options, the metrics data would be recorded when did the operations on Azure Storage. – Peter Pan Jun 06 '17 at 05:33
  • @AbhishekBA The `TimeStamp` column is that ["the Table service uses to track when the entity was last updated (this happens automatically and you cannot manually overwrite the timestamp with an arbitrary value)"](https://learn.microsoft.com/en-us/azure/storage/storage-table-design-guide#about-the-azure-table-service). The time in `PartitionKey` is the real time of the log/metrics event happended. – Peter Pan Jun 06 '17 at 05:37
  • Pan Thank you..I got the concept minute metrics is getting collected from logs.only when we will access logs will be collected and metrics will be collected.Please explain the second question concept /difference in PartitionKey and TimeStamp im confused here--Thank you in advance – Abhishek B A Jun 06 '17 at 05:38
  • @AbhishekBA Please see my second comment for explaining the difference. – Peter Pan Jun 06 '17 at 05:45
  • Pan Thank You for helping me understand – Abhishek B A Jun 06 '17 at 05:52
  • @Pan please help resolve https://stackoverflow.com/questions/46950222/azure-microsoft-insights-api-2016-09-01-error-while-collecting-metrics – Abhishek B A Oct 27 '17 at 07:32
0

There is no simple way to query last 5 minutes rows now. 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.

TableQuery.combineFilters(
    TableQuery.generateFilterCondition("PartitionKey", QueryComparisons.GreaterThanOrEqual, "20170602T1400"),
    TableOperators.And,
    TableQuery.generateFilterCondition("PartitionKey", QueryComparisons.LessThanOrEqual, "20170602T1420"));
Peter Pan
  • 23,476
  • 4
  • 25
  • 43
  • Yu i tried as u suggested but the code gives the following exception.java.util.NoSuchElementException: An error occurred while enumerating the result, check the original exception for details.at com.microsoft.azure.storage.core.LazySegmentedIterator.hasNext(LazySegmentedIterator.java:113) at com.mindtree.azure.testing.main(testing.java:118) Caused by: com.microsoft.azure.storage.table.TableServiceException: Not Found at com.microsoft.azure.storage.table.TableServiceException.generateTableServiceException(TableServiceException.java:52) – Abhishek B A Jun 05 '17 at 04:24