use*_*783 2 spring-boot spring-boot-actuator
我正在尝试使用
org.springframework.boot.actuate.metrics.repository.MetricRepository
Run Code Online (Sandbox Code Playgroud)
吐出指标
private final MetricRepository repository;
@Autowired
public MetricExporterService(MetricRepository repository) {
this.repository = repository;
}
Run Code Online (Sandbox Code Playgroud)
但由于我使用的是 Java 1.8,我得到了
Parameter 0 of constructor in com.example.actuator.MetricExporterService required a bean of type 'org.springframework.boot.actuate.metrics.repository.MetricRepository' that could not be found.
- Bean method 'actuatorMetricRepository' not loaded because @ConditionalOnJava (older than 1.8) found 1.8
Run Code Online (Sandbox Code Playgroud)
有没有办法覆盖这种行为?
使用 java 8,您应该使用CounterService,GaugeService和BufferMetricReader:
@Autowired
private BufferMetricReader metricReader;
@Autowired
private CounterService counterService;
@Autowired
private GaugeService gaugeService;
...
counterService.increment("metric1");
gaugeService.submit("metric2", 10d);
metricReader.findAll();
Run Code Online (Sandbox Code Playgroud)
弹簧文档:
Spring Boot 提供的 GaugeService 和 CounterService 的默认实现取决于您使用的 Java 版本。使用 Java 8(或更好),实现切换到为快速写入优化的高性能版本,由原子内存缓冲区支持,而不是由不可变但相对昂贵的 Metric 类型(计数器大约快 5 倍,测量大约两倍)与基于存储库的实现一样快)。
...
[注意] 如果您使用的是 Java 8 或使用 Dropwizard 指标,则默认情况下不会使用旧的 MetricRepository 及其 InMemoryMetricRepository 实现。
...
要记录您自己的指标,请将 CounterService 和/或 GaugeService 注入您的 bean。CounterService 公开了 increment、decrement 和 reset 方法;GaugeService 提供了一个提交方法。
| 归档时间: |
|
| 查看次数: |
2071 次 |
| 最近记录: |