springboot监控
springboot版本
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.8.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent>
监控类型
1.以json串的格式返回监控信息(spring-boot-starter-actuator)
2.以图形化界面的方式返回监控内容(spring-boot-admin-starter-server、spring-boot-admin-starter-client)
监控内容
spring-boot-starter-actuator(支持自定义)
如果使用springMVC还可以监控以下内容
spring-boot-admin
spring-boot-starter-actuator配置
pom.xml
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
<!-- 安全方面,可选配置 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>
application.yml
management:
# 是否启用认证
security:
enabled: false
# 监控端口
port: 8088
# 监控上下文路径
context-path: /monitor
# 启用shutdown,实现springboot项目优雅停机,要考虑安全问题,默认不启用
endpoints:
shutdown:
enabled: true
# 认证账号、密码,需要spring-boot-starter-security支持,可选配置
#security:
# user:
# name: wly
# password: wly
# role=SUPERUSER
# spring boot信息,可选配置
info:
app:
name: spring-boot-actuator-wly
version: 1.0.0
访问监控URL
http://localhost:8088/monitor/env
效果
spring-boot-admin配置
spring-boot-admin-starter-server配置,需要单独建立一个监控的项目
pom.xml
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server</artifactId> <version>1.5.6</version> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server-ui</artifactId> <version>1.5.6</version> </dependency>
application.yml
server.port=8085
启动类(添加@EnableAdminServer注解)
package com.example.springbootadmin; import de.codecentric.boot.admin.config.EnableAdminServer; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication @EnableAdminServer public class SpringbootadminApplication { public static void main(String[] args) { SpringApplication.run(SpringbootadminApplication.class, args); } }
配置完成启动项目即可~
spring-boot-admin-starter-client配置
pom.xml
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-client</artifactId> <version>1.5.6</version> </dependency>
application.yml
# 配置spring-boot-admin-starter-server的监控地址
spring:
boot:
admin:
url: http://localhost:8085
server:
port: 8080
management:
# 是否启用认证
security:
enabled: false
配置完成启动服务即可~
效果
访问spring-boot-admin-starter-server地址(localhost:8085)