Azure WADPerformanceCountertable查询在查询特定间隔时返回所有记录



如何使用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;
    }
}

使用stringBuilder向PartitionKey追加0解决了这个问题。

相关内容

  • 没有找到相关文章

最新更新