Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring SpringBoot 2 application for Micrometer for AWS cloudwatch

I have a springboot 2 application, and I want to display metrics in AWS Cloudwatch.

I have included micrometer cloudwatch dependency in pom.

Here setting is documented for various metric systems but not cloudwatch.

Whar else configurations I need to do for cloudwatch?

like image 451
Mandroid Avatar asked May 24 '18 08:05

Mandroid


1 Answers

First of all you may have to add some additional dependecies. I needed the following:

  • org.springframework.boot - spring-boot-starter-actuator
  • org.springframework.cloud - spring-cloud-starter-aws
  • io.micrometer - micrometer-core
  • io.micrometer - micrometer-registry-cloudwatch

Boot was not able to manage the versions for these dependencies except for actuator in my case, so you might have to figure out the right versions for you.

Firthermore some application properties have to be set:

# disable unwanted features to prevent autoconfigure which will produce errors and abort of application startup eventually
# alternatively you can try to configure those features correctly if you intend to use them
cloud.aws.stack.auto=false
# enable micrometer for cloudwatch (only where there is actually access to it)
management.metrics.export.cloudwatch.enabled=true
# set the namespace that will contain the metrics for this application
management.metrics.export.cloudwatch.namespace=test
# set max batch size to the actual maximum (if not a bug in certain versions of micrometer for cloudwatch will send
# batches that are too big) 
management.metrics.export.cloudwatch.batchSize=20

The next step will be in AWS. The role associated with your EC2-instance (or whatever you are using) needs to have the permission CloudWatch:PutMetricData.

Using this configuration should enable CloudWatch-Monitoring for your Spring-Boot-Application.

One of the sources I encountered stated that you should use:

cloud.aws.credentials.instanceProfile=false

This will prevent Spring Boot from automatically obtaining credentials that are necessary to push metrics to CloudWatch. You could also provide own credentials another way, but I didn't try that.

like image 199
Fencer Avatar answered Nov 03 '22 18:11

Fencer