Springboot with Spring-cloud-aws and cloudwatch metrics

不羁的心 提交于 2019-12-07 04:11:22

问题


I would like to start using metrics in my Springboot app and I would also like to publish them my amazon cloudwatch

I know that with Springboot we can activate spring-actuator that provides in memory metrics and published them to the /metrics endpoint.

I stumbled across Spring-cloud that seems to have some lib to periodically publish these metrics to Cloudwatch, however I have no clue how to set them up? There is absolutely 0 examples of how to use it.

Anyone could explain what are the step to enable the metric to be sent to cloudwatch?


回答1:


You can check my article here:

https://dkublik.github.io/2017/10/28/springboot-metrics-with-servo-and-aws-cloudwatch.html

I wrote it after setting this up in my project.

From header:

"Article explains how to send Spring Boot and Netflix Servo metrics to AWS CloudWatch. Morover it describes mechanisms making it happen. It also mentions problems I run into trying to do the same with Spring Boot and Spectator."

EDIT: new version: https://dkublik.github.io/2018/08/26/springboot-metrics-with-micrometer-and-aws-cloudwatch.html




回答2:


Check this conversation:

@sachinlad Indeed the documentation is unfortunately missing, we will create a updated version within the next releases. Do enable the metic export to Cloud Formation, you will need to configure the namespace with the property cloud.aws.cloudwatch.namespace

Have a look at the integration test https://github.com/spring-cloud/spring-cloud-aws/blob/master/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/metric/MetricExporterTest.java that is an integration test and export the metrics to cloud formation.

Hope that helps, feel free to come back in case of any problems.




回答3:


If you want a readymade solution that doesn't involve using the whole spring cloud library, you could use: https://github.com/dipayan90/spring-actuator-cloudwatch




回答4:


Here is a setup for spring boot 2.

Using spring boot 2.0.3.

Add these dependencies:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-aws-actuator</artifactId>
    <version>2.0.0.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-aws</artifactId>
    <version>2.0.0.RELEASE</version>
</dependency>

application.yml:

# you might want to set this to true depending on your setup
cloud.aws.stack.auto: false
# set static region to avoid s3 error - adjust region accordingly
cloud.aws.region.static: eu-west-1

management:
  metrics.export.cloudwatch.namespace: my-app
  metrics.export.cloudwatch.batch-size: 20


来源:https://stackoverflow.com/questions/45493350/springboot-with-spring-cloud-aws-and-cloudwatch-metrics

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