Publishing Custom Metric Data - AWS SDK for Java

Publishing Custom Metric Data

A number of AWS services publish their own metrics in namespaces beginning with " AWS " You can also publish custom metric data using your own namespace (as long as it doesn’t begin with " AWS ").

Publish Custom Metric Data

To publish your own metric data, call the AmazonCloudWatchClient’s putMetricData method with a PutMetricDataRequest. The PutMetricDataRequest must include the custom namespace to use for the data, and information about the data point itself in a MetricDatum object.


You cannot specify a namespace that begins with " AWS ". Namespaces that begin with " AWS " are reserved for use by Amazon Web Services products.


import; import; import; import; import; import; import;


final AmazonCloudWatch cw = AmazonCloudWatchClientBuilder.defaultClient(); Dimension dimension = new Dimension() .withName("UNIQUE_PAGES") .withValue("URLS"); MetricDatum datum = new MetricDatum() .withMetricName("PAGES_VISITED") .withUnit(StandardUnit.None) .withValue(data_point) .withDimensions(dimension); PutMetricDataRequest request = new PutMetricDataRequest() .withNamespace("SITE/TRAFFIC") .withMetricData(datum); PutMetricDataResult response = cw.putMetricData(request);

More Information