Spring Boot Metrics使用

Spring Boot 使用Metrics监控

  1. 导入pom依赖
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
  1. 配置项中启用 metrics
management.endpoints.web.exposure.include=*
  1. 需要监控调用次数的Controller配置如下:
    @GetMapping("/dic")
    @Timed(value = "all.people", longTask = true)
    public String list() throws JsonProcessingException {
        return objectMapper.writeValueAsString(dictDao.list());
    }
  1. 查看方式:
    http://127.0.0.1:8080/actuator/metrics/all.people

  2. Spring Boot官网配置

Spring Boot Metrics中查看版本等信息

  1. 配置项中启用
management.endpoints.web.exposure.include=*
  1. 配置项中以info开头的配置,都会在info中显示
  2. info中显示git信息
    • 在classpath中添加git.properties 配置文件
git.branch=master
git.commit.id=sdxe2jdd
git.commit.time=2018-03-25
  1. 查看info信息
    http://127.0.0.1:8080/actuator/info
{
  "version": "1.0.0",
  "git": { "commit": { "time": "2018-03-25", "id": "sdxe2jd" }, "branch": "master" } }
    原文作者:Spring Boot
    原文地址: https://blog.csdn.net/afgasdg/article/details/79758645
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞