spring boot监控之actuator--持续更新

 

一、环境配置

1、pom文件配置

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.0.RELEASE</version>
    <relativePath/>
</parent>
<!-- 运行状态监控actuator -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

2、yml文件配置

spring boot 2.0配置方法已更新,具体配置可查看spring boot官网Endpoints配置,如下为开启所有监控端点的写法:

management:
  server:
    port: 9002
  endpoints:
    web:
      exposure:
        include: '*'

启动spring boot应用,看到如下信息,表示actuator启动并配置成功,具体某个端点的作用可在Endpoints配置中查看:

spring boot监控之actuator--持续更新

在spring boot 2.0中,默认情况下,访问http://localhost:9002/stag/actuator/health端点只会提供简单的状态信息:

{"status":"UP"}

如需查看更多的详细信息,需要在yml中添加额外配置:

#----------actuator--------
management:
  server:
    port: 9002
  endpoints:
    web:
      exposure:
        include: '*'
  endpoint:
    health:
      show-details: always

修改配置后访问http://localhost:9002/stag/actuator/health显示如下信息,更多讲解可查看spring boot 2.0 actuator 健康检查: 

{
	"status": "UP",
	"details": {
		"diskSpace": {
			"status": "UP",
			"details": {
				"total": 1000201674752,
				"free": 647068315648,
				"threshold": 10485760
			}
		},
		"db": {
			"status": "UP",
			"details": {
				"dataSource": {
					"status": "UP",
					"details": {
						"database": "MySQL",
						"hello": 1
					}
				},
				"dev-dataSource": {
					"status": "UP",
					"details": {
						"database": "MySQL",
						"hello": 1
					}
				}
			}
		},
		"redis": {
			"status": "UP",
			"details": {
				"version": "3.2.100"
			}
		}
	}
}