代码之家  ›  专栏  ›  技术社区  ›  Johny19

使用Spring cloud aws和cloudwatch指标的Springboot

  •  10
  • Johny19  · 技术社区  · 7 年前

    我想开始在我的Springboot应用程序中使用指标,我还想把它们发布到我的amazon cloudwatch上

    任何人都可以解释一下,将指标发送到cloudwatch的步骤是什么?

    5 回复  |  直到 7 年前
        1
  •  4
  •   dawid    5 年前
        2
  •  3
  •   Hendy Irawan    7 年前

    检查 this conversation

    @sachinlad确实很遗憾,文档丢失了,我们将 在下一个版本中创建更新版本。确实启用MEIT 导出到云形成时,需要配置命名空间 使用属性cloud.aws.cloudwatch.namespace

    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 这是一个集成测试,并将指标导出到云形成。

    希望这会有所帮助,如果有任何问题,请随时回来。

        3
  •  2
  •   DiNagpal    4 年前

    设置以下属性:

    management.metrics.export.cloudwatch.namespace=my-application
    management.metrics.export.cloudwatch.batchSize=20
    management.metrics.export.cloudwatch.step=5s
    

    <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-aws-actuator</artifactId>
    </dependency>
    <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-aws-messaging</artifactId>
    </dependency>
    

    一切都结束了。现在,您可以在cloudwatch上看到指标。 现在,如果您想将自定义指标推送到某个地方,那么可以自动连接MetricsRegistry的实例,只需创建您想要的任何指标。

    让我们创建一个用于发送短信的计数器,例如:

    Counter smsCounter = Counter.builder(COUNT_METRICS)
                .tag("type", "sms")
                .description("The number of sms sent")
                .register(meterRegistry);
    

    现在更新执行操作的计数器,如下所示:

    smsCounter.increment();
    
        4
  •  1
  •   Dipayan    6 年前

    如果您想要一个不涉及使用整个spring云库的现成解决方案,您可以使用: https://github.com/dipayan90/spring-actuator-cloudwatch

        5
  •  -1
  •   pbthorste    6 年前

    使用弹簧护套2.0.3。

    添加这些依赖项:

    <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>
    

    # 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