首页 > 解决方案 > 无法在使用 statsd 为 Springboot 应用程序发送的数据狗中查看自定义指标

问题描述

我有一个spring boot应用程序,我正在尝试使用statsd和meterregistry将自定义指标发送到datadog,我可以使用'/actuator/metrics' url查看指标,但在datadog中看不到任何内容。

pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
    <groupId>com.datadoghq</groupId>
    <artifactId>java-dogstatsd-client</artifactId>
    <version>2.10.1</version>
</dependency>

班级:

  private final MeterRegistry meterRegistry;


    public Starter(@Lazy @Autowired MeterRegistry meterRegistry) {
        

        this.meterRegistry = new SimpleMeterRegistry();

        Counter counter = Counter
                .builder("test_counter")
                .baseUnit("beans") // optional
                .description("a description of what this counter does") // optional
                .tags("region", "test") // optional
                .register(meterRegistry);

        Timer.builder("test.timer")
                .publishPercentiles(0.95)
                .register(meterRegistry);

应用程序.yml

management:
  metrics:
    enable:
      all: true
    export:
      statsd:
        flavor: datadog
        host: localhost
        port: 8125
        protocol: udp

标签: springmetricsdatadogstatsdspring-micrometer

解决方案


推荐阅读