2016-09-07 1 views
0

Java APIを使用してAzure WADPerformanceCountersテーブルから特定の間隔のレコードを取得する方法はありますか?Azure WADPerformanceCountertable特定の間隔でクエリを実行中にすべてのレコードを返すクエリ

次のコードを試してみましたが、そのテーブルにすべてのレコードを渡しました。タイムスタンプベースのフィルタは機能していないようです。 PartitionKey、Timestamp、EventTick、およびTIMESTAMP列のフィルタリングを試みましたが、すべて同じです。

public static void main(String arg[]){ 
     try 
     { 

      CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString); 

      CloudTableClient tableClient = storageAccount.createCloudTableClient(); 


      CloudTable cloudTable = tableClient.getTableReference("WADPerformanceCountersTable"); 



     Long currTime = System.currentTimeMillis(); 
     Date currentDate = new Date(currTime); 


      Date endTime = getFormattedTimestamp(currentDate); 
      System.out.println("endTime:" + endTime); 

      // calculation of start Time to DB format in UTC 
      long offsetInMilliseconds = 1000 * 60 * 2; 
      Date startTime = getFormattedTimestamp(new Date(currentDate 
        .getTime() 
        - offsetInMilliseconds)); 

      System.out.println("startTime:" + startTime); 

      long startPartitionKey = 621355968000000000L + startTime 
        .getTime() * 10000; 
      long endPartitionKey = 621355968000000000L + endTime.getTime() * 10000; 



     //Query using PartitionKey 
     TableQuery<PerfTableEntity> SQL = TableQuery.from(PerfTableEntity.class).where(
       "PartitionKey ge '0" + startPartitionKey + "'").where(
       "PartitionKey le '0" + endPartitionKey + "'").where(
       "DeploymentId eq '<deplymentid>'").where(
       "RoleInstance eq 'WebRole1_IN_0'").where(
       "CounterName eq '\\Memory\\Page Faults/sec' or CounterName eq '\\Memory\\Page Reads/sec'"); 



     for (PerfTableEntity pd : cloudTable.execute(SQL)) { 

      System.out.println("\ncounterName = " +pd.getCounterName() + "= " + pd.getCounterValue() + "||" + pd.getTimestamp()); 

     } 



     }catch (Exception e){ 
       // Output the stack trace. 
       e.printStackTrace(); 
     } 

}//main 

private static Date getFormattedTimestamp(Date date) { 
    try { 

     SimpleDateFormat df = new SimpleDateFormat(
       "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); 
     df.setTimeZone(TimeZone.getTimeZone("UTC")); 
     String datestr = df.format(date); 
     return df.parse(datestr); 
    } catch (Exception e) { 
     return null; 
    } 

} 
+0

startPartitionKeyとendPartitionKeyの値を共有できますか? –

+0

@Gaurav startPartitionKey = 636088504373440000 endPartitionKey = 636088505573440000クエリの前に「0」が付加されています。 – Prit

+0

これは答えとして入力する必要があります。 –

答えて

1

stringBuilderを使用してPartitionKeyに0を追加すると、問題が解決されました。

+0

私はこの答えで実際のコードを置くだろう:)。 –

関連する問題