Can I create custom Cloudwatch metrics with Java?

Is it possible to create custom AWS CloudWatch metrics using the Java SDK provided by AWS?

The developer’s guide talks about publishing custom metrics through command line tools.
Is this possible with the Java SDK? If yes, provide links or tutorials for this.

+4
source share
2 answers

Yes, you can create software metrics using the AWS SDK. Here's a link to the CloudWatch client as part of the AWS SDK for Java:

http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/cloudwatch/AmazonCloudWatchClient.html

If I remember correctly, you just start entering data into CloudWatch using the putMetricData(..) method, and it will start to appear (after a short delay of a minute or two).

+4
source

The code below can be used to publish custom metrics to AWS CloudWatch using JAVA.

 AmazonCloudWatch amazonCloudWatch = AmazonCloudWatchClientBuilder.standard().withEndpointConfiguration( new AwsClientBuilder.EndpointConfiguration("monitoring.us-west-1.amazonaws.com","us-west-1")).build(); PutMetricDataRequest putMetricDataRequest = new PutMetricDataRequest(); putMetricDataRequest.setNamespace("CUSTOM/SQS"); MetricDatum metricDatum1 = new MetricDatum().withMetricName("MessageCount").withDimensions(new Dimension().withName("Personalization").withValue("123")); metricDatum1.setValue(-1.00); metricDatum1.setUnit(StandardUnit.Count); putMetricDataRequest.getMetricData().add(metricDatum1); PutMetricDataResult result = amazonCloudWatch.putMetricData(putMetricDataRequest); 

The only thing to remember is to enable aws-java-sdk-cloudwatch

+2
source

Source: https://habr.com/ru/post/1485010/


All Articles