我一直在尝试让一个简单的应用程序运行,它返回一些 cloudwatch 指标。我尝试了 3 个不同的 Web 示例,但没有一个返回任何数据。我可以在 AWS 控制台上看到数据。也许有人可以发现我的错误或指出一个已知有效的简单示例?
我想要实现的原则是:我想知道我们的应用程序何时接近其 dynamoDB 读/写限制,然后增加它们。我假设我需要编写一些线程来轮询询问统计信息,如果它达到容量的 80%,则增加限制。
private static void findCloudWatchData() throws InterruptedException {
AmazonCloudWatchClient cloudWatch = new AmazonCloudWatchClient(new BasicAWSCredentials(key, secret));
cloudWatch.setEndpoint("monitoring.eu-west-1.amazonaws.com");
GetMetricStatisticsRequest getMetricStatisticsRequest = new GetMetricStatisticsRequest();
GregorianCalendar g = new GregorianCalendar(2012, 9, 17, 12, 0);
getMetricStatisticsRequest.setStartTime(g.getTime());
g.add(Calendar.DAY_OF_MONTH, 2);
getMetricStatisticsRequest.setEndTime(g.getTime());
getMetricStatisticsRequest.setNamespace("AWS/DynamoDB");
getMetricStatisticsRequest.setMetricName("SuccessfulRequestLatency");
getMetricStatisticsRequest.setPeriod(5*60);
Dimension tableDimension = new Dimension();
tableDimension.setName("TableName");
tableDimension.setValue("personalisation.user_favourite-int");
Dimension operationDimension = new Dimension();
operationDimension.setName("Operation");
operationDimension.setValue("Query");
getMetricStatisticsRequest.setDimensions(Arrays.asList(tableDimension, operationDimension));
Collection<String> statistics = new ArrayList<String>();
statistics.add("Average");
getMetricStatisticsRequest.setStatistics(statistics);
getMetricStatisticsRequest.setUnit(StandardUnit.Count);
//results
GetMetricStatisticsResult result = cloudWatch.getMetricStatistics(getMetricStatisticsRequest);
System.err.println(result.getDatapoints().size()); //this returns 0 always
for (Datapoint p : result.getDatapoints()) {
System.out.println(p.getTimestamp() + " " + p.getAverage());
}
}