membersound
membersound

Reputation: 86627

How to read and reset spring actuator metrics?

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

Answers (3)

user2204107
user2204107

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

membersound
membersound

Reputation: 86627

@Autowired
private BufferMetricReader metrics;

int count = metrics.findOne("my.metrics.key").getValue().intValue();

Upvotes: 5

Related Questions