How to emit Cloud-watch metrics

Sun, Mar 26, 2023

Read in 1 minutes


We can create cloud-watch metrics in two ways.

Creating metrics from log events using filters

  1. Add logs for particular scenario in our service (For example add log 503 error service unavailable when calling external service)
  2. Then add filter based on the log statement.
  3. [.., metrics = “METRICS”, metricName = “EXTERNAL CALL FAIL” metricValue]

Create Cloud-watch metrics in java SDK

Libraries Used:


Specify the dimension. Here the dimension is marketplace, productType.PutMetricDataRequest will actually emit the metrics.

public void emitProductMetrics (final String name , String marketplace , String productType){

final Dimension marketplaceDimension = new Dimension()

final Dimension productTypeDimension = new Dimension()

final MetricDatum ProductMetricDatum = new MetricDatum()

final List<MetricDatum> MetricDataToEmit = new ArrayList<>();


final PutMetricDataRequest putMetricDataRequest = new PutMetricDataRequest()