本文整理汇总了Java中com.amazonaws.services.cloudwatch.model.PutMetricDataRequest.setNamespace方法的典型用法代码示例。如果您正苦于以下问题:Java PutMetricDataRequest.setNamespace方法的具体用法?Java PutMetricDataRequest.setNamespace怎么用?Java PutMetricDataRequest.setNamespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.cloudwatch.model.PutMetricDataRequest
的用法示例。
在下文中一共展示了PutMetricDataRequest.setNamespace方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: postToCloudwatch
import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest; //导入方法依赖的package包/类
private void postToCloudwatch(String namespace, List<CloudwatchStatistic> statistics) {
List<MetricDatum> metricDatumList = statistics.stream()
.map(CloudwatchStatistic::toMetricsDatum)
.collect(toList());
PutMetricDataRequest request = new PutMetricDataRequest();
request.setNamespace(namespace);
request.setMetricData(metricDatumList);
amazonCloudWatch.putMetricData(request);
}
示例3: write
import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest; //导入方法依赖的package包/类
public void write(Query query) {
PutMetricDataRequest metricDataRequest = new PutMetricDataRequest();
metricDataRequest.setNamespace(namespace);
MetricDatum metricDatum = new MetricDatum();
// Converts the Objects to Double-values for CloudWatch
metricDatum.setMetricName(query.getKey());
metricDatum.setValue(convertToDouble(query.getValue()));
metricDatum.setTimestamp(new Date());
metricDataRequest.withMetricData(metricDatum);
cloudWatchClient.putMetricData(metricDataRequest);
}
示例4: sendCloudWatchConsistencyAlert
import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest; //导入方法依赖的package包/类
private void sendCloudWatchConsistencyAlert() {
MetricDatum datum = new MetricDatum();
datum.setMetricName(cloudWatchConsistencyMetric);
datum.setUnit(StandardUnit.Count);
datum.setValue(1.0);
PutMetricDataRequest request = new PutMetricDataRequest();
request.setNamespace(namespace);
request.setMetricData(Collections.singleton(datum));
cloudWatch.putMetricData(request);
}
示例5: sendCloudWatchTimeoutAlert
import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest; //导入方法依赖的package包/类
private void sendCloudWatchTimeoutAlert() {
MetricDatum datum = new MetricDatum();
datum.setMetricName(cloudWatchTimeoutMetric);
datum.setUnit(StandardUnit.Count);
datum.setValue(1.0);
PutMetricDataRequest request = new PutMetricDataRequest();
request.setNamespace(namespace);
request.setMetricData(Collections.singleton(datum));
cloudWatch.putMetricData(request);
}
示例6: sendData
import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest; //导入方法依赖的package包/类
private void sendData( Collection<MetricDatum> metricData ) {
PutMetricDataRequest request = new PutMetricDataRequest();
request.setNamespace( namespace );
request.setMetricData( metricData );
metricsClient.putMetricData( request );
}
示例7: write
import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest; //导入方法依赖的package包/类
@Override
public void write(ArrayList<Stat> stats, long invokeTimeMs, Set<Tag> tags) {
Date dt = new Date();
dt.setTime(invokeTimeMs);
Collection<Dimension> parentDims = tagsToDimensions(tags);
List<MetricDatum> metrics = new ArrayList<MetricDatum>();
/*
* Create CW metric objects from bender internal Stat objects
*/
for (Stat stat : stats) {
/*
* Dimension are CW's version of metric tags. A conversion must be done.
*/
Collection<Dimension> metricDims = tagsToDimensions(stat.getTags());
metricDims.addAll(parentDims);
MetricDatum metric = new MetricDatum();
metric.setMetricName(stat.getName());
// TODO: add units to Stat object SYSTEMS-870
metric.setUnit(StandardUnit.None);
metric.setTimestamp(dt);
metric.setDimensions(metricDims);
metric.setValue((double) stat.getValue());
metrics.add(metric);
}
/*
* Not very well documented in java docs but CW only allows 20 metrics at a time.
*/
List<List<MetricDatum>> chunks = ListUtils.partition(metrics, 20);
for (List<MetricDatum> chunk : chunks) {
PutMetricDataRequest req = new PutMetricDataRequest();
req.withMetricData(chunk);
req.setNamespace(namespace);
this.client.putMetricData(req);
}
}
示例8: report
import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest; //导入方法依赖的package包/类
@Override
public void report(SortedMap<String, Gauge> gauges,
SortedMap<String, Counter> counters,
SortedMap<String, Histogram> histograms,
SortedMap<String, Meter> meters,
SortedMap<String, Timer> timers) {
Collection<MetricDatum> data = new ArrayList<>();
for (Map.Entry<String, Gauge> meg : gauges.entrySet()) {
if (meg.getValue().getValue() instanceof Number) {
Number num = (Number)meg.getValue().getValue();
double val = num.doubleValue();
if (LOG.isDebugEnabled()) {
LOG.debug("gauge {} val {}", meg.getKey(), val);
}
data.add(new MetricDatum().withMetricName(meg.getKey()).withValue(val).withDimensions(dimensions));
}
}
for (Map.Entry<String, Counter> mec : counters.entrySet()) {
if (LOG.isDebugEnabled()) {
LOG.debug("counter {} val {}", mec.getKey(), mec.getValue().getCount());
}
data.add(new MetricDatum().withMetricName(mec.getKey()).withValue((double) mec.getValue().getCount())
.withDimensions(dimensions));
}
for (Map.Entry<String, Histogram> meh : histograms.entrySet()) {
reportHistogram(data, meh);
}
for (Map.Entry<String, Timer> met : timers.entrySet()) {
reportTimer(met.getKey(), data, met);
}
if (!data.isEmpty()) {
PutMetricDataRequest put = new PutMetricDataRequest();
put.setNamespace(namespace);
put.setMetricData(data);
try {
client.putMetricData(put);
} catch (Throwable t) {
LOG.error("Failed to put metrics", t);
}
}
}