【问题标题】:Configuring SpringBoot 2 application for Micrometer for AWS cloudwatch为 AWS cloudwatch 的 Micrometer 配置 SpringBoot 2 应用程序
【发布时间】:2018-11-03 10:07:28
【问题描述】:

我有一个 springboot 2 应用程序,我想在 AWS Cloudwatch 中显示指标。

我在 pom 中包含了 micrometer cloudwatch 依赖项。

Here 设置记录了各种公制系统,但没有记录 cloudwatch。

我还需要为 cloudwatch 做哪些配置?

【问题讨论】:

    标签: spring-boot micrometer


    【解决方案1】:

    首先,您可能需要添加一些额外的依赖项。我需要以下内容:

    • org.springframework.boot - spring-boot-starter-actuator
    • org.springframework.cloud - spring-cloud-starter-aws
    • io.micrometer - 微米核心
    • io.micrometer - micrometer-registry-cloudwatch

    在我的例子中,Boot 无法管理这些依赖项的版本,但执行器除外,因此您可能需要为自己找出正确的版本。

    此外,必须设置一些应用程序属性:

    # 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 权限。

    使用此配置应该为您的 Spring-Boot-Application 启用 CloudWatch-Monitoring。

    我遇到的一个消息来源说你应该使用:

    cloud.aws.credentials.instanceProfile=false
    

    这将阻止 Spring Boot 自动获取将指标推送到 CloudWatch 所需的凭据。您也可以通过其他方式提供自己的凭据,但我没有尝试过。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-15
      • 2020-07-03
      • 1970-01-01
      • 2020-06-11
      • 2020-02-19
      • 1970-01-01
      • 2021-10-30
      • 1970-01-01
      相关资源
      最近更新 更多