【问题标题】:How to add custom MeterRegisty for Spring Boot 2如何为 Spring Boot 2 添加自定义 MeterRegisty
【发布时间】:2020-03-21 14:13:22
【问题描述】:

我目前正在以 10 秒的间隔将我的 Spring Boot Webflux 项目的执行器指标导出到 DataDog。我想为我们的一个内部系统添加另一个导出器,该系统不在支持的后端列表中。查看DataDogMeterRegistry 的实现,我想到了以下内容。

public interface ExternalConfig extends StepRegistryConfig {

  ExternalConfig DEFAULT = k -> null;

  @Override
  default String prefix() {
    return "vwexternal";
  }
}

@Slf4j
public class ExternalMeterRegistry extends StepMeterRegistry {

  public ExternalMeterRegistry() {
    this(ExternalConfig.DEFAULT, Clock.SYSTEM);
  }

  public ExternalMeterRegistry(StepRegistryConfig config, Clock clock) {
    super(config, clock);
  }

  @Override
  protected void publish() {
    log.info("HERE");
  }

  @Override
  protected TimeUnit getBaseTimeUnit() {
    return TimeUnit.MILLISECONDS;
  }
}

@SpringBootApplication
public class MyApplication {
  public static void main(String[] args) {
    SpringApplication.run(MyApplication.class, args);
    Metrics.addRegistry(new ExternalMeterRegistry());
  }
}

但是这不起作用,因为没有打印日志。

我的问题是如何为 Spring Boot Micrometer 添加和实现另一个 MeterRegistry?

【问题讨论】:

  • 我相信你需要在你的发布方法中调用super.publish()
  • 不,那是抽象方法,不能直接调用。

标签: java spring spring-boot micrometer spring-micrometer


【解决方案1】:

您需要start 发布。与LoggingMeterRegistry比较

在您的构造函数中类似于:

start(new NamedThreadFactory("vw-metrics-publisher"))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-01
    • 2019-11-15
    • 1970-01-01
    • 2019-01-04
    • 2019-12-29
    • 2022-01-10
    • 2017-12-04
    相关资源
    最近更新 更多