在spring boot 的监控插件 spring-boot-starter-actuator 中存在/metrics 端口能够提供应用的运行状态的报告,
在报告中,其中又一个功能就是现实端口的被调用次数。
例如:
"counter.status.200.env":1
我们可以借用这以功能自定义一个端口访问次数统计,我们就能在/metrics 端口中看到我们自动以的借口访问统计
@RestController
public class HelloController {
@Autowired
private CounterService counterService;
@RequestMapping("/hello")
public String test(){
counterService.increment("my.hello.count");
return "";
}
}
本文介绍如何利用SpringBoot的监控插件spring-boot-starter-actuator中的/metrics端口,实现应用程序运行状态的监控及端口访问次数的自定义统计。通过示例代码展示如何创建自定义监控指标并将其集成到/metrics报告中。
443

被折叠的 条评论
为什么被折叠?



