问题描述
我有一个springboot 2应用程序,我想在AWS Cloudwatch中显示指标.
I have a springboot 2 application, and I want to display metrics in AWS Cloudwatch.
我在pom中包括了测微表对cloudwatch的依赖.
I have included micrometer cloudwatch dependency in pom.
此处设置适用于各种指标系统,但不适用于cloudwatch.
Here setting is documented for various metric systems but not cloudwatch.
我需要为cloudwatch做哪些其他配置?
Whar else configurations I need to do for cloudwatch?
推荐答案
首先,您可能必须添加一些其他依赖项.我需要以下条件:
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-千分尺芯
- io.micrometer-微米注册表云观察
在我的情况下,Boot无法管理这些依赖项的版本,但执行器除外,因此您可能必须为自己找出正确的版本.
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
下一步将在AWS中进行.与您的EC2实例(或您使用的任何对象)相关联的角色需要具有权限CloudWatch:PutMetricData
.
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
.
使用此配置应为您的Spring-Boot-Application启用CloudWatch-Monitoring.
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
这将阻止Spring Boot自动获取将指标推送到CloudWatch所必需的凭据.您也可以通过其他方式提供自己的凭据,但我没有尝试过.
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.
这篇关于为适用于AWS Cloudwatch的Micrometer配置SpringBoot 2应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!