当前位置: 首页>>代码示例>>Java>>正文


Java PutMetricDataRequest类代码示例

本文整理汇总了Java中com.amazonaws.services.cloudwatch.model.PutMetricDataRequest的典型用法代码示例。如果您正苦于以下问题:Java PutMetricDataRequest类的具体用法?Java PutMetricDataRequest怎么用?Java PutMetricDataRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PutMetricDataRequest类属于com.amazonaws.services.cloudwatch.model包,在下文中一共展示了PutMetricDataRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: send

import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest; //导入依赖的package包/类
@Override
public void send() throws IOException {
	final List<MetricDatum> datumList;
	synchronized (buffer) {
		datumList = new ArrayList<MetricDatum>(buffer);
		buffer.clear();
	}

	// note: Each PutMetricData request is limited to 40 KB in size for HTTP POST requests.
	final PutMetricDataRequest request = new PutMetricDataRequest()
			.withNamespace(cloudWatchNamespace).withMetricData(datumList);
	try {
		awsCloudWatch.putMetricData(request);
	} catch (final Exception e) {
		// pas catch (AmazonCloudWatchException) sinon ClassNotFoundException dans Jenkins par ex
		throw new IOException("Error connecting to AWS CloudWatch", e);
	}
}
 
开发者ID:javamelody,项目名称:javamelody,代码行数:19,代码来源:CloudWatch.java

示例2: reportMetersCountersGaugesWithZeroValuesOnlyWhenConfigured

import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest; //导入依赖的package包/类
@Test
public void reportMetersCountersGaugesWithZeroValuesOnlyWhenConfigured() throws Exception {
    metricRegistry.register(ARBITRARY_GAUGE_NAME, (Gauge<Long>) () -> 0L);
    metricRegistry.meter(ARBITRARY_METER_NAME).mark(0);
    metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc(0);
    metricRegistry.timer(ARBITRARY_TIMER_NAME).update(-1L, TimeUnit.NANOSECONDS);

    buildReportWithSleep(reporterBuilder
            .withArithmeticMean()
            .withOneMinuteMeanRate()
            .withFiveMinuteMeanRate()
            .withFifteenMinuteMeanRate()
            .withZeroValuesSubmission()
            .withMeanRate());

    verify(mockAmazonCloudWatchAsyncClient, times(1)).putMetricDataAsync(metricDataRequestCaptor.capture());

    final PutMetricDataRequest putMetricDataRequest = metricDataRequestCaptor.getValue();
    final List<MetricDatum> metricData = putMetricDataRequest.getMetricData();
    for (final MetricDatum metricDatum : metricData) {
        assertThat(metricDatum.getValue()).isEqualTo(0.0);
    }
}
 
开发者ID:azagniotov,项目名称:codahale-aggregated-metrics-cloudwatch-reporter,代码行数:24,代码来源:CloudWatchReporterTest.java

示例3: shouldReportCounterValueDelta

import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest; //导入依赖的package包/类
@Test
public void shouldReportCounterValueDelta() throws Exception {
    metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();
    metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();
    final CloudWatchReporter cloudWatchReporter = reporterBuilder.build();

    cloudWatchReporter.report();
    MetricDatum metricDatum = firstMetricDatumFromCapturedRequest();
    assertThat(metricDatum.getValue().intValue()).isEqualTo(2);
    metricDataRequestCaptor.getAllValues().clear();

    metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();
    metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();
    metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();
    metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();
    metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();
    metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();

    cloudWatchReporter.report();
    metricDatum = firstMetricDatumFromCapturedRequest();
    assertThat(metricDatum.getValue().intValue()).isEqualTo(6);

    verify(mockAmazonCloudWatchAsyncClient, times(2)).putMetricDataAsync(any(PutMetricDataRequest.class));
}
 
开发者ID:azagniotov,项目名称:codahale-aggregated-metrics-cloudwatch-reporter,代码行数:25,代码来源:CloudWatchReporterTest.java

示例4: metricDatumByDimensionFromCapturedRequest

import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest; //导入依赖的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

示例5: runOneIteration

import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest; //导入依赖的package包/类
@Override
protected void runOneIteration() throws Exception {
    try {
        _cloudWatch.putMetricData(
                new PutMetricDataRequest()
                        .withNamespace(NAMESPACE)
                        .withMetricData(
                                new MetricDatum()
                                        .withTimestamp(new Date())
                                        .withMetricName(ACTIVE_AND_PENDING_SCANS)
                                        .withValue((double) (_activeScanCount + _pendingScanCount))
                                        .withUnit(StandardUnit.Count)
                                        .withDimensions(_dimensions)));
    } catch (AmazonClientException e) {
        _log.error("Failed to publish active and pending scans metric", e);
    }
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:18,代码来源:CloudWatchScanCountListener.java

示例6: sendMetricFromHeaderValues

import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest; //导入依赖的package包/类
@Test
public void sendMetricFromHeaderValues() throws Exception {
    template.send("direct:start", ExchangePattern.InOnly, new Processor() {
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(CwConstants.METRIC_NAMESPACE, "camel.apache.org/overriden");
            exchange.getIn().setHeader(CwConstants.METRIC_NAME, "OverridenMetric");
            exchange.getIn().setHeader(CwConstants.METRIC_VALUE, Double.valueOf(3));
            exchange.getIn().setHeader(CwConstants.METRIC_UNIT, StandardUnit.Bytes.toString());
            exchange.getIn().setHeader(CwConstants.METRIC_TIMESTAMP, LATER);
        }
    });


    ArgumentCaptor<PutMetricDataRequest> argument = ArgumentCaptor.forClass(PutMetricDataRequest.class);
    verify(cloudWatchClient).putMetricData(argument.capture());

    assertEquals("camel.apache.org/overriden", argument.getValue().getNamespace());
    assertEquals("OverridenMetric", argument.getValue().getMetricData().get(0).getMetricName());
    assertEquals(Double.valueOf(3), argument.getValue().getMetricData().get(0).getValue());
    assertEquals(StandardUnit.Bytes.toString(), argument.getValue().getMetricData().get(0).getUnit());
    assertEquals(LATER, argument.getValue().getMetricData().get(0).getTimestamp());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:CwComponentTest.java

示例7: sendManuallyCreatedMetric

import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest; //导入依赖的package包/类
@Test
public void sendManuallyCreatedMetric() throws Exception {
    template.send("direct:start", ExchangePattern.InOnly, new Processor() {
        public void process(Exchange exchange) throws Exception {
            MetricDatum metricDatum = new MetricDatum()
                    .withMetricName("errorCount")
                    .withValue(Double.valueOf(0));
            exchange.getIn().setBody(metricDatum);
        }
    });


    ArgumentCaptor<PutMetricDataRequest> argument = ArgumentCaptor.forClass(PutMetricDataRequest.class);
    verify(cloudWatchClient).putMetricData(argument.capture());

    assertEquals("errorCount", argument.getValue().getMetricData().get(0).getMetricName());
    assertEquals(Double.valueOf(0), argument.getValue().getMetricData().get(0).getValue());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:CwComponentTest.java

示例8: useDefaultValuesForMetricUnitAndMetricValue

import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest; //导入依赖的package包/类
@Test
public void useDefaultValuesForMetricUnitAndMetricValue() throws Exception {
    template.send("direct:start", ExchangePattern.InOnly, new Processor() {
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(CwConstants.METRIC_NAME, "errorCount");
        }
    });


    ArgumentCaptor<PutMetricDataRequest> argument = ArgumentCaptor.forClass(PutMetricDataRequest.class);
    verify(cloudWatchClient).putMetricData(argument.capture());

    assertEquals("errorCount", argument.getValue().getMetricData().get(0).getMetricName());
    assertEquals(Double.valueOf(1), argument.getValue().getMetricData().get(0).getValue());
    assertEquals(StandardUnit.Count.toString(), argument.getValue().getMetricData().get(0).getUnit());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:CwComponentTest.java

示例9: setsMeticDimensions

import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest; //导入依赖的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());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:CwComponentTest.java

示例10: run

import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest; //导入依赖的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());
    }
}
 
开发者ID:Cantara,项目名称:ConfigService,代码行数:22,代码来源:CloudWatchMetricsPublisher.java

示例11: sendBatch

import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest; //导入依赖的package包/类
protected void sendBatch(Map<String, Collection<MetricDatum>> datums) {
    for (final Map.Entry<String, Collection<MetricDatum>> e : datums.entrySet()) {
        for (final List<MetricDatum> batch : Lists.partition(Lists.newLinkedList(e.getValue()), BATCH_SIZE)) {
            cloudWatch.putMetricDataAsync(new PutMetricDataRequest().withNamespace(e.getKey())
                                                                    .withMetricData(batch),
                                          new AsyncHandler<PutMetricDataRequest, Void>() {

                                            @Override
                                            public void onError(Exception exception) {
                                                LOG.error("PutMetricData failed", exception);
                                                LOG.info("Requeueing metric data.");
                                                queuedDatums.putAll(e.getKey(), batch);
                                            }

                                            @Override
                                            public void onSuccess(PutMetricDataRequest request, Void result) {
                                                LOG.info("Successfully put " + request.getMetricData().size() +
                                                                        " datums for namespace " + request.getNamespace());
                                                LOG.debug("Request", request);
                                            }

            });
        }
    }
}
 
开发者ID:awslabs,项目名称:amediamanager,代码行数:26,代码来源:MetricBatcher.java

示例12: addHistograms

import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest; //导入依赖的package包/类
private void addHistograms(SortedMap<String, Histogram> histograms, LinkedList<PutMetricDataRequest> requests, Date timestamp) {
    logger.debug("Adding Histograms...");
    for (String name : histograms.keySet()) {
        Histogram histogram = histograms.get(name);
        Snapshot snapshot = histogram.getSnapshot();
        checkAndAddDatum(MetricFilter.Stat.COUNT, name, histogram.getCount(), requests, timestamp);
        checkAndAddDatum(MetricFilter.Stat.MIN, name, snapshot.getMin(), requests, timestamp);
        checkAndAddDatum(MetricFilter.Stat.MAX, name, snapshot.getMax(), requests, timestamp);
        checkAndAddDatum(MetricFilter.Stat.MEAN, name, snapshot.getMean(), requests, timestamp);
        checkAndAddDatum(MetricFilter.Stat.STDDEV, name, snapshot.getStdDev(), requests, timestamp);
        checkAndAddDatum(MetricFilter.Stat.PERCENTILE_75, name, snapshot.get75thPercentile(), requests, timestamp);
        checkAndAddDatum(MetricFilter.Stat.PERCENTILE_95, name, snapshot.get95thPercentile(), requests, timestamp);
        checkAndAddDatum(MetricFilter.Stat.PERCENTILE_98, name, snapshot.get98thPercentile(), requests, timestamp);
        checkAndAddDatum(MetricFilter.Stat.PERCENTILE_99, name, snapshot.get99thPercentile(), requests, timestamp);
        checkAndAddDatum(MetricFilter.Stat.PERCENTILE_999, name, snapshot.get999thPercentile(), requests, timestamp);
    }
}
 
开发者ID:Kixeye,项目名称:chassis,代码行数:18,代码来源:MetricsCloudWatchReporter.java

示例13: matches

import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest; //导入依赖的package包/类
@Override
public boolean matches(Object o) {
    if (!(o instanceof PutMetricDataRequest)) {
        errorText = "Invalid arg type " + o;
        return false;
    }
    PutMetricDataRequest request = (PutMetricDataRequest) o;
    if (validators.length != request.getMetricData().size()) {
        errorText = "Got " + request.getMetricData().size() + " data elements, but had only " + validators.length + " validators.";
        return false;
    }
    for (int i = 0; i < request.getMetricData().size(); i++) {
        try {
            validators[i].validate(request.getMetricData().get(i));
        } catch (Exception e) {
            errorText = e.getMessage();
            return false;
        }
    }
    return true;
}
 
开发者ID:Kixeye,项目名称:chassis,代码行数:22,代码来源:CloudWatchReporterTest.java

示例14: runOnce

import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest; //导入依赖的package包/类
@Override
protected void runOnce() throws Exception {
    ClickEvent event = inputQueue.take();
    String partitionKey = event.getSessionId();
    ByteBuffer data = ByteBuffer.wrap(
            event.getPayload().getBytes("UTF-8"));
    recordsPut.getAndIncrement();

    PutRecordResult res = kinesis.putRecord(
            STREAM_NAME, data, partitionKey);

    MetricDatum d = new MetricDatum()
        .withDimensions(
            new Dimension().withName("StreamName").withValue(STREAM_NAME),
            new Dimension().withName("ShardId").withValue(res.getShardId()),
            new Dimension().withName("Host").withValue(
                    InetAddress.getLocalHost().toString()))
        .withValue(1.0)
        .withMetricName("RecordsPut");
    cw.putMetricData(new PutMetricDataRequest()
        .withMetricData(d)
        .withNamespace("MySampleProducer"));
}
 
开发者ID:awslabs,项目名称:aws-big-data-blog,代码行数:24,代码来源:MetricsEmittingBasicClickEventsToKinesis.java

示例15: sendValue

import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest; //导入依赖的package包/类
/**
 * Send a datum object to this metric.
 *
 * @param value the measurement to record
 */
public void sendValue(double value) {
    MetricDatum datum = new MetricDatum();
    datum.setMetricName(name);
    datum.setUnit(unit);
    datum.setValue(value);

    PutMetricDataRequest request = new PutMetricDataRequest();
    request.setNamespace(namespace);
    request.withMetricData(datum);

    logger.info(String.format("logging %.2f to cloudwatch metric %s/%s", value, namespace, name));
    client.putMetricData(request);
}
 
开发者ID:zachpendleton,项目名称:sidekiq-reporter,代码行数:19,代码来源:CloudwatchMetric.java


注:本文中的com.amazonaws.services.cloudwatch.model.PutMetricDataRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。