天天看點

Spring Boot Metrics使用

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"

  }

}

繼續閱讀