Spring Boot 使用Metrics监控
- 导入pom依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
- 配置项中启用 metrics
management.endpoints.web.exposure.include=*
- 需要监控调用次数的Controller配置如下:
@GetMapping("/dic")
@Timed(value = "all.people", longTask = true)
public String list() throws JsonProcessingException {
return objectMapper.writeValueAsString(dictDao.list());
}
查看方式:
http://127.0.0.1:8080/actuator/metrics/all.people
Spring Boot官网配置
Spring Boot Metrics中查看版本等信息
- 配置项中启用:
management.endpoints.web.exposure.include=*
- 配置项中以info开头的配置,都会在info中显示
- info中显示git信息
- 在classpath中添加git.properties 配置文件
git.branch=master
git.commit.id=sdxe2jdd
git.commit.time=2018-03-25
- 查看info信息
http://127.0.0.1:8080/actuator/info
{
"version": "1.0.0",
"git": { "commit": { "time": "2018-03-25", "id": "sdxe2jd" }, "branch": "master" } }