0

Java API を使用して Azure WADPerformanceCounters テーブルから特定の間隔のレコードを取得する方法は?

次のコードを試してみましたが、テーブル内のすべてのレコードが表示されます。タイムスタンプ ベースのフィルターが機能していないようです。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;
    }

}
4

1 に答える 1

1

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

于 2016-09-07T18:34:11.543 に答える