- Spring 5.0 Microservices(Second Edition)
- Rajesh R V
- 66字
- 2025-04-04 18:53:35
Building custom metrics
Just like health, customization of the metrics is also possible. The following example shows how to add a counter service and gauge service, just for demonstration purpose:
@Autowired
CounterService counterService;
@Autowired
GaugeService gaugeService;
And add the following methods to the greet method:
this.counterService.increment("greet.txnCount");
this.gaugeService.submit("greet.customgauge", 1.0);
Restart the server, and go to /application/metrics to see the new gauge and counter added already reflected there.