本文整理汇总了Java中com.amazonaws.services.cloudwatch.model.Dimension类的典型用法代码示例。如果您正苦于以下问题:Java Dimension类的具体用法?Java Dimension怎么用?Java Dimension使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Dimension类属于com.amazonaws.services.cloudwatch.model包,在下文中一共展示了Dimension类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInstanceAverageLoad
import com.amazonaws.services.cloudwatch.model.Dimension; //导入依赖的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: add
import com.amazonaws.services.cloudwatch.model.Dimension; //导入依赖的package包/类
/**
* Add a metric event to be aggregated.
* Events with the same name, unit, and dimensions will have their values
* aggregated into {@link StatisticSet}s, with the aggregated data
* available via {@link #flush}.
*
* @param context Metric context to use for dimension information
* @param name Metric name
* @param value Recorded value for the metric event
* @param unit Unit for interpreting the value
*/
public void add(
final TypedMap context,
final Metric name,
final double value,
final StandardUnit unit)
{
//TODO: avoid doing this every time for a context - caching, or?
List<Dimension> dimensions = dimensionMapper.getDimensions(name, context);
DatumKey key = new DatumKey(name.toString(), unit, dimensions);
statisticsMap.merge(
key,
new StatisticSet()
.withMaximum(value)
.withMinimum(value)
.withSampleCount(1D)
.withSum(value),
MetricDataAggregator::sum);
}
示例3: one_global
import com.amazonaws.services.cloudwatch.model.Dimension; //导入依赖的package包/类
@Test
public void one_global() throws Exception {
Metric metric = Metric.define("BarMetric");
String id = UUID.randomUUID().toString();
TypedMap context = ContextData.withId(id)
.add(StandardContext.SERVICE, "BarService")
.build();
DimensionMapper mapper = new DimensionMapper.Builder()
.addGlobalDimension(ContextData.ID)
.build();
List<Dimension> dims = mapper.getDimensions(metric, context);
assertEquals("Unexpected size of dimension list", 1, dims.size());
assertEquals("Unexpected name for dimension", ContextData.ID.name, dims.get(0).getName());
assertEquals("Unexpected value for dimension", id, dims.get(0).getValue());
}
示例4: makeDatum
import com.amazonaws.services.cloudwatch.model.Dimension; //导入依赖的package包/类
private MetricDatum makeDatum(
final String id,
final String name,
final double sum,
final double min,
final double max,
final int count,
final StandardUnit unit)
{
MetricDatum md = new MetricDatum().withMetricName(name).withUnit(unit);
final StatisticSet statSet = new StatisticSet()
.withSampleCount(Double.valueOf(count))
.withSum(sum)
.withMinimum(min)
.withMaximum(max);
md.setStatisticValues(statSet);
List<Dimension> dimensions = new ArrayList<>(1);
Dimension trace = new Dimension().withName(ContextData.ID.name).withValue(id);
dimensions.add(trace);
md.setDimensions(dimensions);
return md;
}
示例5: stageMetricDatum
import com.amazonaws.services.cloudwatch.model.Dimension; //导入依赖的package包/类
/**
* Please note, the reported values submitted only if they show some data (greater than zero) in order to:
* <p>
* 1. save some money
* 2. prevent com.amazonaws.services.cloudwatch.model.InvalidParameterValueException if empty {@link Snapshot}
* is submitted
* <p>
* If {@link Builder#withZeroValuesSubmission()} is {@code true}, then all values will be submitted
*/
private void stageMetricDatum(final boolean metricConfigured,
final String metricName,
final double metricValue,
final StandardUnit standardUnit,
final String dimensionValue,
final List<MetricDatum> metricData) {
// Only submit metrics that show some data, so let's save some money
if (metricConfigured && (builder.withZeroValuesSubmission || metricValue > 0)) {
final Set<Dimension> dimensions = new LinkedHashSet<>(builder.globalDimensions);
dimensions.add(new Dimension().withName(DIMENSION_NAME_TYPE).withValue(dimensionValue));
metricData.add(new MetricDatum()
.withTimestamp(new Date(builder.clock.getTime()))
.withValue(cleanMetricValue(metricValue))
.withMetricName(metricName)
.withDimensions(dimensions)
.withUnit(standardUnit));
}
}
开发者ID:azagniotov,项目名称:codahale-aggregated-metrics-cloudwatch-reporter,代码行数:29,代码来源:CloudWatchReporter.java
示例6: stageMetricDatumWithConvertedSnapshot
import com.amazonaws.services.cloudwatch.model.Dimension; //导入依赖的package包/类
private void stageMetricDatumWithConvertedSnapshot(final boolean metricConfigured,
final String metricName,
final Snapshot snapshot,
final StandardUnit standardUnit,
final List<MetricDatum> metricData) {
if (metricConfigured) {
double scaledSum = convertDuration(LongStream.of(snapshot.getValues()).sum());
final StatisticSet statisticSet = new StatisticSet()
.withSum(scaledSum)
.withSampleCount((double) snapshot.size())
.withMinimum(convertDuration(snapshot.getMin()))
.withMaximum(convertDuration(snapshot.getMax()));
final Set<Dimension> dimensions = new LinkedHashSet<>(builder.globalDimensions);
dimensions.add(new Dimension().withName(DIMENSION_NAME_TYPE).withValue(DIMENSION_SNAPSHOT_SUMMARY));
metricData.add(new MetricDatum()
.withTimestamp(new Date(builder.clock.getTime()))
.withMetricName(metricName)
.withDimensions(dimensions)
.withStatisticValues(statisticSet)
.withUnit(standardUnit));
}
}
开发者ID:azagniotov,项目名称:codahale-aggregated-metrics-cloudwatch-reporter,代码行数:25,代码来源:CloudWatchReporter.java
示例7: stageMetricDatumWithRawSnapshot
import com.amazonaws.services.cloudwatch.model.Dimension; //导入依赖的package包/类
private void stageMetricDatumWithRawSnapshot(final boolean metricConfigured,
final String metricName,
final Snapshot snapshot,
final StandardUnit standardUnit,
final List<MetricDatum> metricData) {
if (metricConfigured) {
double total = LongStream.of(snapshot.getValues()).sum();
final StatisticSet statisticSet = new StatisticSet()
.withSum(total)
.withSampleCount((double) snapshot.size())
.withMinimum((double) snapshot.getMin())
.withMaximum((double) snapshot.getMax());
final Set<Dimension> dimensions = new LinkedHashSet<>(builder.globalDimensions);
dimensions.add(new Dimension().withName(DIMENSION_NAME_TYPE).withValue(DIMENSION_SNAPSHOT_SUMMARY));
metricData.add(new MetricDatum()
.withTimestamp(new Date(builder.clock.getTime()))
.withMetricName(metricName)
.withDimensions(dimensions)
.withStatisticValues(statisticSet)
.withUnit(standardUnit));
}
}
开发者ID:azagniotov,项目名称:codahale-aggregated-metrics-cloudwatch-reporter,代码行数:25,代码来源:CloudWatchReporter.java
示例8: metricDatumByDimensionFromCapturedRequest
import com.amazonaws.services.cloudwatch.model.Dimension; //导入依赖的package包/类
private MetricDatum metricDatumByDimensionFromCapturedRequest(final String dimensionValue) {
final PutMetricDataRequest putMetricDataRequest = metricDataRequestCaptor.getValue();
final List<MetricDatum> metricData = putMetricDataRequest.getMetricData();
final Optional<MetricDatum> metricDatumOptional =
metricData
.stream()
.filter(metricDatum -> metricDatum.getDimensions()
.contains(new Dimension().withName(DIMENSION_NAME_TYPE).withValue(dimensionValue)))
.findFirst();
if (metricDatumOptional.isPresent()) {
return metricDatumOptional.get();
}
throw new IllegalStateException("Could not find MetricDatum for Dimension value: " + dimensionValue);
}
开发者ID:azagniotov,项目名称:codahale-aggregated-metrics-cloudwatch-reporter,代码行数:18,代码来源:CloudWatchReporterTest.java
示例9: CloudWatchReporter
import com.amazonaws.services.cloudwatch.model.Dimension; //导入依赖的package包/类
private CloudWatchReporter(MetricRegistry registry,
AmazonCloudWatchClient client,
String namespace,
TimeUnit rateUnit,
TimeUnit durationUnit,
boolean reportAggregates,
MetricFilter filter, Map<String, String> dimensions) {
super(registry, "cloudwatch-reporter", filter, rateUnit, durationUnit);
this.client = client;
this.namespace = namespace;
this.dimensions = new ArrayList<>();
this.reportAggregates = reportAggregates;
for (Map.Entry<String, String> me : dimensions.entrySet()) {
this.dimensions.add(new Dimension().withName(me.getKey()).withValue(me.getValue()));
}
}
示例10: setDimension
import com.amazonaws.services.cloudwatch.model.Dimension; //导入依赖的package包/类
private void setDimension(MetricDatum metricDatum, Exchange exchange) {
String name = exchange.getIn().getHeader(CwConstants.METRIC_DIMENSION_NAME, String.class);
String value = exchange.getIn().getHeader(CwConstants.METRIC_DIMENSION_VALUE, String.class);
if (name != null && value != null) {
metricDatum.withDimensions(new Dimension().withName(name).withValue(value));
} else {
Map<String, String> dimensions = exchange.getIn().getHeader(CwConstants.METRIC_DIMENSIONS, Map.class);
if (dimensions != null) {
Collection<Dimension> dimensionCollection = new ArrayList<Dimension>();
for (Map.Entry<String, String> dimensionEntry : dimensions.entrySet()) {
Dimension dimension = new Dimension().withName(dimensionEntry.getKey()).withValue(dimensionEntry.getValue());
dimensionCollection.add(dimension);
}
metricDatum.withDimensions(dimensionCollection);
}
}
}
示例11: setsMeticDimensions
import com.amazonaws.services.cloudwatch.model.Dimension; //导入依赖的package包/类
@Test
public void setsMeticDimensions() throws Exception {
template.send("direct:start", ExchangePattern.InOnly, new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(CwConstants.METRIC_NAME, "errorCount");
Map<String, String> dimensionsMap = new LinkedHashMap<String, String>();
dimensionsMap.put("keyOne", "valueOne");
dimensionsMap.put("keyTwo", "valueTwo");
exchange.getIn().setHeader(CwConstants.METRIC_DIMENSIONS, dimensionsMap);
}
});
ArgumentCaptor<PutMetricDataRequest> argument = ArgumentCaptor.forClass(PutMetricDataRequest.class);
verify(cloudWatchClient).putMetricData(argument.capture());
List<Dimension> dimensions = argument.getValue().getMetricData().get(0).getDimensions();
Dimension dimension = dimensions.get(0);
assertThat(dimensions.size(), is(2));
assertEquals("keyOne", dimension.getName());
assertEquals("valueOne", dimension.getValue());
}
示例12: createAlarmIfNotAlreadyExist
import com.amazonaws.services.cloudwatch.model.Dimension; //导入依赖的package包/类
public void createAlarmIfNotAlreadyExist(String topicArn) {
List<Dimension> dimensions = new ArrayList<>();
dimensions.add(new Dimension().withName("Currency").withValue("USD"));
PutMetricAlarmRequest request = new PutMetricAlarmRequest();
request.setAlarmName("s3video Billing Alarm");
request.setAlarmActions(Arrays.asList(topicArn));
request.setMetricName("EstimatedCharges");
request.setNamespace("AWS/Billing");
request.setDimensions(dimensions);
request.setThreshold(alarmThreshold);
request.setPeriod(SIX_HOUR_IN_SECONDS);
request.setStatistic("Maximum");
request.setComparisonOperator("GreaterThanThreshold");
request.setEvaluationPeriods(1);
cloudWatchClient.putMetricAlarm(request);
}
示例13: run
import com.amazonaws.services.cloudwatch.model.Dimension; //导入依赖的package包/类
@Override
public void run() {
try {
List<MetricDatum> metricData = new ArrayList<>();
Date now = new Date();
metricData.addAll(heartbeats.entrySet().stream().map(entry -> new MetricDatum().withMetricName("Heartbeats")
.withDimensions(new Dimension().withName("Client").withValue(entry.getKey()))
.withTimestamp(now)
.withUnit(StandardUnit.Count)
.withValue(entry.getValue().doubleValue())).collect(Collectors.toList()));
heartbeats.clear();
for (List<MetricDatum> chunk :partitionList(metricData, 20)) {
awsClient.putMetricData(new PutMetricDataRequest().withNamespace(namespace).withMetricData(chunk));
}
} catch (Throwable e) {
log.error("Failed to publish CloudWatch metrics: {}", e.toString());
}
}
示例14: toString
import com.amazonaws.services.cloudwatch.model.Dimension; //导入依赖的package包/类
/**
* @return a string representation of this object
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder("{ElapsedTimeAggregator: {");
String namespace = putMetricDataRequest.getNamespace();
sb.append("region: ").append(region).append(", ");
sb.append("namespace: ").append(namespace).append(", ");
sb.append("metrics: [");
String msep = "";
for (MetricDatum metricDatum : putMetricDataRequest.getMetricData()) {
sb.append(msep).append("{metricName: ").append(metricDatum.getMetricName()).append(", ");
sb.append("dimensions: [");
String dsep = "";
for (Dimension dimension : metricDatum.getDimensions()) {
sb.append(dsep).append(dimension);
dsep = ", ";
}
sb.append("]}");
msep = ", ";
}
sb.append("]}}");
return sb.toString();
}
示例15: testDimensions
import com.amazonaws.services.cloudwatch.model.Dimension; //导入依赖的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"}));
}