9

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?

Mandroid
  • 6,200
  • 12
  • 64
  • 134

1 Answers1

2

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.

Fencer
  • 1,026
  • 11
  • 27
  • Its not working for me, i provided my aws credentials using cloud.aws.credentials.accessKey: cloud.aws.credentials.secretKey: cloud.aws.region.static: – emilpmp Oct 25 '19 at 08:01
  • Well, I only tried the configuration using the instanceProfile. There are numerous ways to provide your own credentials, but that goes way beyond the scope of this SO-question and deserves an own. – Fencer Oct 27 '19 at 16:34
  • 2
    I tried different solutions and finally worked for me. Now, only my actuator metrics are being reported in aws cloudwatch, not the custom metrics that I created using micrometer. (counters, gauges). Do you have any idea about that? Thanks. – emilpmp Oct 28 '19 at 05:29
  • I'm sorry, no. I myself just started with this topic and have not created own metrics. But I will get back to you if I get to that. – Fencer Oct 29 '19 at 07:31