Configuring SpringBoot 2 application for Micrometer for AWS cloudwatch

二次信任 提交于 2019-12-03 14:44:17

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!