[英]Getting metrics data of two servers using Amazon Cloudwatch
I am writing a java code for retrieving Amazon EC2 metrics
data using Amazon Cloudwatch
. 我正在编写Java代码以使用
Amazon Cloudwatch
检索Amazon EC2 metrics
数据。 Below is the sample code which is working fine. 下面是运行良好的示例代码。
Dimension instanceDimension = new Dimension();
instanceDimension.setName("InstanceId);
instanceDimension.setValue(instanceId);
GetMetricStatisticsRequest request = new GetMetricStatisticsRequest().withStartTime(startTime)
.withNamespace("AWS/EC2")
.withPeriod(60 * 5)
.withDimensions(instanceDimension)
.withMetricName("CPUUtilization")
.withStatistics("Average")
.withEndTime(endTime);
GetMetricStatisticsResult getMetricStatisticsResult = cloudWatch.getMetricStatistics(request);
In the above code, I am passing one server's instance id. 在上面的代码中,我正在传递一台服务器的实例ID。 I need to get the metrics data of two servers having different instance id.
我需要获取具有不同实例ID的两台服务器的指标数据。 So, my query is can i do it in a single call by specifying two dimensions as list and pass it to
withDimensions
OR do i need to make two different calls altogether to get the metrics data of two servers? 因此,我的查询是我可以通过将两个维度指定为列表并将其传递给
withDimensions
来在一次调用中完成此操作,还是需要总共进行两次不同的调用才能获取两个服务器的指标数据?
It's a common question. 这是一个常见的问题。 You need to make two separate requests for each entity, combining multiple instances in one request is not currently supported by the CloudWatch API.
您需要为每个实体发出两个单独的请求,CloudWatch API当前不支持在一个请求中组合多个实例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.