Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I create Cloudwatch custom metrics with Java?

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

The developer guide talks about publishing custom metrics through Command line tools.
Is it possible with the Java SDK? If yes, please provide the links or tutorials for that.

like image 487
ѕтƒ Avatar asked Jun 07 '13 09:06

ѕтƒ


People also ask

Can we Create a custom CloudWatch metrics?

You can use CloudWatch to create custom metrics and, through an SNS topic, have AMS alarm you appropriately.

How CloudWatch metrics are created?

CloudWatch provides statistics based on the metric data points provided by your custom data or provided by other AWS services to CloudWatch. Aggregations are made using the namespace, metric name, dimensions, and the data point unit of measure, within the time period you specify.

How do I get AWS CloudWatch logs in Java?

Using the CloudWatch console You can use the Amazon CloudWatch console to view logs for all Lambda function invocations. Open the Log groups page on the CloudWatch console. Choose the log group for your function (/aws/lambda/ your-function-name ). Choose a log stream.


1 Answers

The below code can be used to Publish Custom Metrics in 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);

Only thing to remember is to include aws-java-sdk-cloudwatch

like image 143
dassum Avatar answered Sep 20 '22 01:09

dassum