本文整理汇总了Java中com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult类的典型用法代码示例。如果您正苦于以下问题:Java GetMetricStatisticsResult类的具体用法?Java GetMetricStatisticsResult怎么用?Java GetMetricStatisticsResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GetMetricStatisticsResult类属于com.amazonaws.services.cloudwatch.model包,在下文中一共展示了GetMetricStatisticsResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInstanceAverageLoad
import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult; //导入依赖的package包/类
private double getInstanceAverageLoad(AmazonCloudWatchClient cloudWatchClient, String instanceId) {
long offsetInMilliseconds = 1000 * 60 * 60;
GetMetricStatisticsRequest request = new GetMetricStatisticsRequest()
.withStartTime(new Date(new Date().getTime() - offsetInMilliseconds))
.withNamespace("AWS/EC2")
.withPeriod(60 * 60)
.withDimensions(new Dimension().withName("InstanceId").withValue(instanceId))
.withMetricName("CPUUtilization")
.withStatistics("Average", "Maximum")
.withEndTime(new Date());
GetMetricStatisticsResult getMetricStatisticsResult = cloudWatchClient.getMetricStatistics(request);
double avgCPUUtilization = 0;
List dataPoint = getMetricStatisticsResult.getDatapoints();
for (Object aDataPoint : dataPoint) {
Datapoint dp = (Datapoint) aDataPoint;
avgCPUUtilization = dp.getAverage();
}
return avgCPUUtilization;
}
示例2: getBacklogBytes
import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult; //导入依赖的package包/类
/**
* Gets total size in bytes of all events that remain in Kinesis stream between specified
* instants.
*
* @return total size in bytes of all Kinesis events after specified instant
*/
public long getBacklogBytes(final String streamName, final Instant countSince,
final Instant countTo) throws TransientKinesisException {
return wrapExceptions(new Callable<Long>() {
@Override
public Long call() throws Exception {
Minutes period = Minutes.minutesBetween(countSince, countTo);
if (period.isLessThan(Minutes.ONE)) {
return 0L;
}
GetMetricStatisticsRequest request = createMetricStatisticsRequest(streamName,
countSince, countTo, period);
long totalSizeInBytes = 0;
GetMetricStatisticsResult result = cloudWatch.getMetricStatistics(request);
for (Datapoint point : result.getDatapoints()) {
totalSizeInBytes += point
.getSum()
.longValue();
}
return totalSizeInBytes;
}
});
}
示例3: shouldCountBytesWhenSingleDataPointReturned
import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult; //导入依赖的package包/类
@Test
public void shouldCountBytesWhenSingleDataPointReturned() throws Exception {
Instant countSince = new Instant("2017-04-06T10:00:00.000Z");
Instant countTo = new Instant("2017-04-06T11:00:00.000Z");
Minutes periodTime = Minutes.minutesBetween(countSince, countTo);
GetMetricStatisticsRequest metricStatisticsRequest =
underTest.createMetricStatisticsRequest(STREAM, countSince, countTo, periodTime);
GetMetricStatisticsResult result = new GetMetricStatisticsResult()
.withDatapoints(new Datapoint().withSum(1.0));
given(cloudWatch.getMetricStatistics(metricStatisticsRequest)).willReturn(result);
long backlogBytes = underTest.getBacklogBytes(STREAM, countSince, countTo);
assertThat(backlogBytes).isEqualTo(1L);
}
示例4: shouldCountBytesWhenMultipleDataPointsReturned
import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult; //导入依赖的package包/类
@Test
public void shouldCountBytesWhenMultipleDataPointsReturned() throws Exception {
Instant countSince = new Instant("2017-04-06T10:00:00.000Z");
Instant countTo = new Instant("2017-04-06T11:00:00.000Z");
Minutes periodTime = Minutes.minutesBetween(countSince, countTo);
GetMetricStatisticsRequest metricStatisticsRequest =
underTest.createMetricStatisticsRequest(STREAM, countSince, countTo, periodTime);
GetMetricStatisticsResult result = new GetMetricStatisticsResult()
.withDatapoints(
new Datapoint().withSum(1.0),
new Datapoint().withSum(3.0),
new Datapoint().withSum(2.0)
);
given(cloudWatch.getMetricStatistics(metricStatisticsRequest)).willReturn(result);
long backlogBytes = underTest.getBacklogBytes(STREAM, countSince, countTo);
assertThat(backlogBytes).isEqualTo(6L);
}
示例5: testMetricPeriod
import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult; //导入依赖的package包/类
@Test
public void testMetricPeriod() {
new CloudWatchCollector(
"---\nregion: reg\nmetrics:\n- aws_namespace: AWS/ELB\n aws_metric_name: RequestCount\n period_seconds: 100\n range_seconds: 200\n delay_seconds: 300", client).register(registry);
Mockito.when(client.getMetricStatistics((GetMetricStatisticsRequest) anyObject()))
.thenReturn(new GetMetricStatisticsResult());
registry.getSampleValue("aws_elb_request_count_average", new String[]{"job", "instance"}, new String[]{"aws_elb", ""});
Mockito.verify(client).getMetricStatistics((GetMetricStatisticsRequest) argThat(
new GetMetricStatisticsRequestMatcher()
.Namespace("AWS/ELB")
.MetricName("RequestCount")
.Period(100)
));
}
示例6: testDefaultPeriod
import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult; //导入依赖的package包/类
@Test
public void testDefaultPeriod() {
new CloudWatchCollector(
"---\nregion: reg\nperiod_seconds: 100\nrange_seconds: 200\ndelay_seconds: 300\nmetrics:\n- aws_namespace: AWS/ELB\n aws_metric_name: RequestCount", client).register(registry);
Mockito.when(client.getMetricStatistics((GetMetricStatisticsRequest) anyObject()))
.thenReturn(new GetMetricStatisticsResult());
registry.getSampleValue("aws_elb_request_count_average", new String[]{"job", "instance"}, new String[]{"aws_elb", ""});
Mockito.verify(client).getMetricStatistics((GetMetricStatisticsRequest) argThat(
new GetMetricStatisticsRequestMatcher()
.Namespace("AWS/ELB")
.MetricName("RequestCount")
.Period(100)
));
}
示例7: testAllStatistics
import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult; //导入依赖的package包/类
@Test
public void testAllStatistics() throws Exception {
new CloudWatchCollector(
"---\nregion: reg\nmetrics:\n- aws_namespace: AWS/ELB\n aws_metric_name: RequestCount", client).register(registry);
Mockito.when(client.getMetricStatistics((GetMetricStatisticsRequest)argThat(
new GetMetricStatisticsRequestMatcher().Namespace("AWS/ELB").MetricName("RequestCount"))))
.thenReturn(new GetMetricStatisticsResult().withDatapoints(
new Datapoint().withTimestamp(new Date()).withAverage(1.0)
.withMaximum(2.0).withMinimum(3.0).withSampleCount(4.0).withSum(5.0)));
assertEquals(1.0, registry.getSampleValue("aws_elb_request_count_average", new String[]{"job", "instance"}, new String[]{"aws_elb", ""}), .01);
assertEquals(2.0, registry.getSampleValue("aws_elb_request_count_maximum", new String[]{"job", "instance"}, new String[]{"aws_elb", ""}), .01);
assertEquals(3.0, registry.getSampleValue("aws_elb_request_count_minimum", new String[]{"job", "instance"}, new String[]{"aws_elb", ""}), .01);
assertEquals(4.0, registry.getSampleValue("aws_elb_request_count_sample_count", new String[]{"job", "instance"}, new String[]{"aws_elb", ""}), .01);
assertEquals(5.0, registry.getSampleValue("aws_elb_request_count_sum", new String[]{"job", "instance"}, new String[]{"aws_elb", ""}), .01);
}
示例8: testDimensions
import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult; //导入依赖的package包/类
@Test
public void testDimensions() throws Exception {
new CloudWatchCollector(
"---\nregion: reg\nmetrics:\n- aws_namespace: AWS/ELB\n aws_metric_name: RequestCount\n aws_dimensions:\n - AvailabilityZone\n - LoadBalancerName", client).register(registry);
Mockito.when(client.listMetrics((ListMetricsRequest)argThat(
new ListMetricsRequestMatcher().Namespace("AWS/ELB").MetricName("RequestCount").Dimensions("AvailabilityZone", "LoadBalancerName"))))
.thenReturn(new ListMetricsResult().withMetrics(
new Metric().withDimensions(new Dimension().withName("AvailabilityZone").withValue("a"), new Dimension().withName("LoadBalancerName").withValue("myLB")),
new Metric().withDimensions(new Dimension().withName("AvailabilityZone").withValue("a"), new Dimension().withName("LoadBalancerName").withValue("myLB"), new Dimension().withName("ThisExtraDimensionIsIgnored").withValue("dummy")),
new Metric().withDimensions(new Dimension().withName("AvailabilityZone").withValue("b"), new Dimension().withName("LoadBalancerName").withValue("myOtherLB"))));
Mockito.when(client.getMetricStatistics((GetMetricStatisticsRequest)argThat(
new GetMetricStatisticsRequestMatcher().Namespace("AWS/ELB").MetricName("RequestCount").Dimension("AvailabilityZone", "a").Dimension("LoadBalancerName", "myLB"))))
.thenReturn(new GetMetricStatisticsResult().withDatapoints(
new Datapoint().withTimestamp(new Date()).withAverage(2.0)));
Mockito.when(client.getMetricStatistics((GetMetricStatisticsRequest)argThat(
new GetMetricStatisticsRequestMatcher().Namespace("AWS/ELB").MetricName("RequestCount").Dimension("AvailabilityZone", "b").Dimension("LoadBalancerName", "myOtherLB"))))
.thenReturn(new GetMetricStatisticsResult().withDatapoints(
new Datapoint().withTimestamp(new Date()).withAverage(3.0)));
assertEquals(2.0, registry.getSampleValue("aws_elb_request_count_average", new String[]{"job", "instance", "availability_zone", "load_balancer_name"}, new String[]{"aws_elb", "", "a", "myLB"}), .01);
assertEquals(3.0, registry.getSampleValue("aws_elb_request_count_average", new String[]{"job", "instance", "availability_zone", "load_balancer_name"}, new String[]{"aws_elb", "", "b", "myOtherLB"}), .01);
assertNull(registry.getSampleValue("aws_elb_request_count_average", new String[]{"job", "instance", "availability_zone", "load_balancer_name", "this_extra_dimension_is_ignored"}, new String[]{"aws_elb", "", "a", "myLB", "dummy"}));
}
示例9: testDimensionSelect
import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult; //导入依赖的package包/类
@Test
public void testDimensionSelect() throws Exception {
new CloudWatchCollector(
"---\nregion: reg\nmetrics:\n- aws_namespace: AWS/ELB\n aws_metric_name: RequestCount\n aws_dimensions:\n - AvailabilityZone\n - LoadBalancerName\n aws_dimension_select:\n LoadBalancerName:\n - myLB", client).register(registry);
Mockito.when(client.listMetrics((ListMetricsRequest)argThat(
new ListMetricsRequestMatcher().Namespace("AWS/ELB").MetricName("RequestCount").Dimensions("AvailabilityZone", "LoadBalancerName"))))
.thenReturn(new ListMetricsResult().withMetrics(
new Metric().withDimensions(new Dimension().withName("AvailabilityZone").withValue("a"), new Dimension().withName("LoadBalancerName").withValue("myLB")),
new Metric().withDimensions(new Dimension().withName("AvailabilityZone").withValue("b"), new Dimension().withName("LoadBalancerName").withValue("myLB")),
new Metric().withDimensions(new Dimension().withName("AvailabilityZone").withValue("a"), new Dimension().withName("LoadBalancerName").withValue("myOtherLB"))));
Mockito.when(client.getMetricStatistics((GetMetricStatisticsRequest)argThat(
new GetMetricStatisticsRequestMatcher().Namespace("AWS/ELB").MetricName("RequestCount").Dimension("AvailabilityZone", "a").Dimension("LoadBalancerName", "myLB"))))
.thenReturn(new GetMetricStatisticsResult().withDatapoints(
new Datapoint().withTimestamp(new Date()).withAverage(2.0)));
Mockito.when(client.getMetricStatistics((GetMetricStatisticsRequest)argThat(
new GetMetricStatisticsRequestMatcher().Namespace("AWS/ELB").MetricName("RequestCount").Dimension("AvailabilityZone", "b").Dimension("LoadBalancerName", "myLB"))))
.thenReturn(new GetMetricStatisticsResult().withDatapoints(
new Datapoint().withTimestamp(new Date()).withAverage(2.0)));
assertEquals(2.0, registry.getSampleValue("aws_elb_request_count_average", new String[]{"job", "instance", "availability_zone", "load_balancer_name"}, new String[]{"aws_elb", "", "a", "myLB"}), .01);
assertEquals(2.0, registry.getSampleValue("aws_elb_request_count_average", new String[]{"job", "instance", "availability_zone", "load_balancer_name"}, new String[]{"aws_elb", "", "b", "myLB"}), .01);
assertNull(registry.getSampleValue("aws_elb_request_count_average", new String[]{"job", "instance", "availability_zone", "load_balancer_name"}, new String[]{"aws_elb", "", "a", "myOtherLB"}));
}
示例10: testDimensionSelectRegex
import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult; //导入依赖的package包/类
@Test
public void testDimensionSelectRegex() throws Exception {
new CloudWatchCollector(
"---\nregion: reg\nmetrics:\n- aws_namespace: AWS/ELB\n aws_metric_name: RequestCount\n aws_dimensions:\n - AvailabilityZone\n - LoadBalancerName\n aws_dimension_select_regex:\n LoadBalancerName:\n - myLB(.*)", client).register(registry);
Mockito.when(client.listMetrics((ListMetricsRequest) argThat(
new ListMetricsRequestMatcher().Namespace("AWS/ELB").MetricName("RequestCount").Dimensions("AvailabilityZone", "LoadBalancerName"))))
.thenReturn(new ListMetricsResult().withMetrics(
new Metric().withDimensions(new Dimension().withName("AvailabilityZone").withValue("a"), new Dimension().withName("LoadBalancerName").withValue("myLB1")),
new Metric().withDimensions(new Dimension().withName("AvailabilityZone").withValue("b"), new Dimension().withName("LoadBalancerName").withValue("myLB2")),
new Metric().withDimensions(new Dimension().withName("AvailabilityZone").withValue("a"), new Dimension().withName("LoadBalancerName").withValue("myOtherLB"))));
Mockito.when(client.getMetricStatistics((GetMetricStatisticsRequest) argThat(
new GetMetricStatisticsRequestMatcher().Namespace("AWS/ELB").MetricName("RequestCount").Dimension("AvailabilityZone", "a").Dimension("LoadBalancerName", "myLB1"))))
.thenReturn(new GetMetricStatisticsResult().withDatapoints(
new Datapoint().withTimestamp(new Date()).withAverage(2.0)));
Mockito.when(client.getMetricStatistics((GetMetricStatisticsRequest) argThat(
new GetMetricStatisticsRequestMatcher().Namespace("AWS/ELB").MetricName("RequestCount").Dimension("AvailabilityZone", "b").Dimension("LoadBalancerName", "myLB2"))))
.thenReturn(new GetMetricStatisticsResult().withDatapoints(
new Datapoint().withTimestamp(new Date()).withAverage(2.0)));
assertEquals(2.0, registry.getSampleValue("aws_elb_request_count_average", new String[]{"job", "instance", "availability_zone", "load_balancer_name"}, new String[]{"aws_elb", "", "a", "myLB1"}), .01);
assertEquals(2.0, registry.getSampleValue("aws_elb_request_count_average", new String[]{"job", "instance", "availability_zone", "load_balancer_name"}, new String[]{"aws_elb", "", "b", "myLB2"}), .01);
assertNull(registry.getSampleValue("aws_elb_request_count_average", new String[]{"job", "instance", "availability_zone", "load_balancer_name"}, new String[]{"aws_elb", "", "a", "myOtherLB"}));
}
示例11: testGetDimensionsUsesNextToken
import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult; //导入依赖的package包/类
@Test
public void testGetDimensionsUsesNextToken() throws Exception {
new CloudWatchCollector(
"---\nregion: reg\nmetrics:\n- aws_namespace: AWS/ELB\n aws_metric_name: RequestCount\n aws_dimensions:\n - AvailabilityZone\n - LoadBalancerName\n aws_dimension_select:\n LoadBalancerName:\n - myLB", client).register(registry);
Mockito.when(client.listMetrics((ListMetricsRequest)argThat(
new ListMetricsRequestMatcher().Namespace("AWS/ELB").MetricName("RequestCount").Dimensions("AvailabilityZone", "LoadBalancerName"))))
.thenReturn(new ListMetricsResult().withNextToken("ABC"));
Mockito.when(client.listMetrics((ListMetricsRequest)argThat(
new ListMetricsRequestMatcher().Namespace("AWS/ELB").MetricName("RequestCount").Dimensions("AvailabilityZone", "LoadBalancerName").NextToken("ABC"))))
.thenReturn(new ListMetricsResult().withMetrics(
new Metric().withDimensions(new Dimension().withName("AvailabilityZone").withValue("a"), new Dimension().withName("LoadBalancerName").withValue("myLB"))));
Mockito.when(client.getMetricStatistics((GetMetricStatisticsRequest)argThat(
new GetMetricStatisticsRequestMatcher().Namespace("AWS/ELB").MetricName("RequestCount").Dimension("AvailabilityZone", "a").Dimension("LoadBalancerName", "myLB"))))
.thenReturn(new GetMetricStatisticsResult().withDatapoints(
new Datapoint().withTimestamp(new Date()).withAverage(2.0)));
assertEquals(2.0, registry.getSampleValue("aws_elb_request_count_average", new String[]{"job", "instance", "availability_zone", "load_balancer_name"}, new String[]{"aws_elb", "", "a", "myLB"}), .01);
}
示例12: testExtendedStatistics
import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult; //导入依赖的package包/类
@Test
public void testExtendedStatistics() throws Exception {
new CloudWatchCollector(
"---\nregion: reg\nmetrics:\n- aws_namespace: AWS/ELB\n aws_metric_name: Latency\n aws_extended_statistics:\n - p95\n - p99.99", client).register(registry);
HashMap<String, Double> extendedStatistics = new HashMap<String, Double>();
extendedStatistics.put("p95", 1.0);
extendedStatistics.put("p99.99", 2.0);
Mockito.when(client.getMetricStatistics((GetMetricStatisticsRequest)argThat(
new GetMetricStatisticsRequestMatcher().Namespace("AWS/ELB").MetricName("Latency"))))
.thenReturn(new GetMetricStatisticsResult().withDatapoints(
new Datapoint().withTimestamp(new Date()).withExtendedStatistics(extendedStatistics)));
assertEquals(1.0, registry.getSampleValue("aws_elb_latency_p95", new String[]{"job", "instance"}, new String[]{"aws_elb", ""}), .01);
assertEquals(2.0, registry.getSampleValue("aws_elb_latency_p99_99", new String[]{"job", "instance"}, new String[]{"aws_elb", ""}), .01);
}
示例13: monitorCPUUsage
import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult; //导入依赖的package包/类
public void monitorCPUUsage() {
AmazonCloudWatchClient cloudClient = new AmazonCloudWatchClient(
getAwsCredentials());
GetMetricStatisticsRequest request = new GetMetricStatisticsRequest();
Calendar cal = Calendar.getInstance();
request.setEndTime(cal.getTime());
cal.add(Calendar.MINUTE, -5);
request.setStartTime(cal.getTime());
request.setNamespace("AWS/EC2");
List<String> statistics = new ArrayList<String>();
statistics.add("Maximium");
statistics.add("Average");
request.setStatistics(statistics);
request.setMetricName("CPUUtilization");
request.setPeriod(300);
Dimension dimension = new Dimension();
dimension.setName("InstanceId");
dimension.setValue("i-d93fa2a4");
List<Dimension> dimensions = new ArrayList<Dimension>();
dimensions.add(dimension);
request.setDimensions(dimensions);
GetMetricStatisticsResult result = cloudClient
.getMetricStatistics(request);
List<Datapoint> dataPoints = result.getDatapoints();
for (Datapoint dataPoint : dataPoints) {
System.out.println(dataPoint.getAverage());
}
}
示例14: getMetricStaticticsTest
import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult; //导入依赖的package包/类
/**
* GetMetricStaticticsTest to get the data points
*
* @return Datapoint
*/
protected final Datapoint getMetricStaticticsTest(String metricName) {
Datapoint dataPoint = null;
GetMetricStatisticsRequest request = new GetMetricStatisticsRequest();
request.setStartTime(new DateTime().plusHours(HOURS).toDate());
request.withNamespace(NAMESPACE);
request.withPeriod(60 * 60);
request.withMetricName(metricName);
request.withStatistics("Average", "SampleCount");
request.withEndTime(new Date());
GetMetricStatisticsResult result = amazonCloudWatchClient.getMetricStatistics(request);
if (result != null && !result.getDatapoints().isEmpty()) {
dataPoint = result.getDatapoints().get(0);
}
return dataPoint;
}
示例15: getCpuUtilization
import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult; //导入依赖的package包/类
public GetMetricStatisticsResult getCpuUtilization(String name) {
Dimension instanceDimension = new Dimension();
if (namespace.endsWith("EC2")) {
instanceDimension.setName("InstanceId");
} else {
instanceDimension.setName("DBInstanceIdentifier");
}
instanceDimension.setValue(name);
Calendar startCal = Calendar.getInstance();
Calendar endCal = Calendar.getInstance();
startCal.add(Calendar.MINUTE, -10);
startCal.set(Calendar.SECOND, 0);
GetMetricStatisticsRequest request = new GetMetricStatisticsRequest()
.withStartTime(startCal.getTime())
.withEndTime(endCal.getTime())
.withNamespace(namespace)
.withPeriod(60)
.withMetricName("CPUUtilization")
.withStatistics("Average")
.withStatistics("Maximum")
.withDimensions(Arrays.asList(instanceDimension));
GetMetricStatisticsResult result = sort(cloudWatch.getMetricStatistics(request).getDatapoints());
if (logger.isDebugEnabled()) {
if (result.getDatapoints() != null && result.getDatapoints().size() > 0) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
logger.debug("[{}:{}] {}, {} ~ {}", new Object[] {namespace, pulse.getId(), result, sdf.format(startCal.getTime()), sdf.format(endCal.getTime())});
}
}
return result;
}