我正在尝试使用aws java sdk来收集有关单个ec2实例的度量标准统计信息。我可以成功获取聚合数据,但是当我尝试指定任何维度(例如实例类型或ID)时,我开始得到一个空结果集。下面是我的测试代码,该代码返回一个空的数据集,但是如果我删除了.withDimensions()调用,则可以使用。关于我在做什么错的任何建议吗?
final BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials("accesskey", "secretkey");
final AWSStaticCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(basicAWSCredentials);
final AmazonCloudWatch cw =
AmazonCloudWatchClientBuilder.standard()
.withRegion(Regions.US_EAST_1)
.withCredentials(credentialsProvider)
.build();
final int oneHour = 60 * 60;
final long oneDay = oneHour * 24 * 1000;
GetMetricStatisticsRequest request = new GetMetricStatisticsRequest()
.withStartTime(new Date(new Date().getTime() - oneDay))
.withNamespace("AWS/EC2")
.withPeriod(60 * 5)
.withDimensions(new Dimension().withName("InstanceType").withValue("m4.large"))
.withMetricName("CPUUtilization")
.withStatistics("Maximum", "Average", "Sum", "Minimum", "SampleCount")
.withEndTime(new Date());
GetMetricStatisticsResult result = cw.getMetricStatistics(request);
System.out.print(result);