Reputation: 86627
I'm using spring-boot.1.3.0
, which provides ability to store custom metrics
in memory as follows:
@Service
public class MyService {
private CounterService counterService;
private GaugeService gaucheService;
@Autowired
public MyService(CounterService counterService) {
this.counterService = counterService;
}
public void exampleMethod() {
this.counterService.increment("services.system.myservice.invoked");
}
}
Question: how can I read the counted values from the CounterService
and GaugeService
programmatically?
Upvotes: 3
Views: 3975
Reputation: 190
@membersound's answer works, but I think it's better use
@Autowired
private MetricReader metricReader;
instead of
@Autowired
private BufferMetricReader metrics;
Upvotes: 0
Reputation: 86627
@Autowired
private BufferMetricReader metrics;
int count = metrics.findOne("my.metrics.key").getValue().intValue();
Upvotes: 5
Reputation: 26848
The Javadoc shows a reset
method: http://docs.spring.io/autorepo/docs/spring-boot/1.3.0.RELEASE/api/org/springframework/boot/actuate/metrics/CounterService.html
Reading has to be done from an exporter: http://docs.spring.io/autorepo/docs/spring-boot/1.3.0.RELEASE/api/org/springframework/boot/actuate/metrics/export/package-summary.html
Upvotes: 2