赞
踩
Actuator是spring boot的一个附加功能,可帮助你在应用程序生产环境时监视和管理应用程序。可以使用HTTP的各种请求来监管,审计,收集应用的运行情况.特别对于微服务管理十分有意义.缺点:没有可视化界面。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
###通过下面的配置启用所有的监控端点,默认情况下,这些端点是禁用的;
management:
endpoints:
web:
exposure:
include: "*"
###接口 相当在配置文件中,配置相关info开头的配置信息
info:
hszsd: 合石招商贷
name: 何金荣
通过actuator/+端点名就可以获取相应的信息。
路径 | 作用 |
---|---|
/actuator/beans | 显示应用程序中所有Spring bean的完整列表。 |
/actuator/configprops | 显示所有配置信息。 |
/actuator/env | 陈列所有的环境变量。 |
/actuator/mappings | 显示所有@RequestMapping的url整理列表。 |
/actuator/health | 显示应用程序运行状况信息 up表示成功 down失败 |
/actuator/info | 查看自定义应用信息 |
http://localhost:8080/actuator/info
可以访问到自己定义的字段属性。
Admin-UI基于actuator实现能够返回界面展示监控信息
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.3.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <java.version>1.8</java.version> <spring-boot-admin.version>2.1.3</spring-boot-admin.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-server</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency>
server:
port: 8800
spring:
application:
name: admin-ui-server
@Configuration
@EnableAutoConfiguration
@EnableAdminServer
public class Springboot2008AdminUiServerApplication {
public static void main(String[] args) {
SpringApplication.run(Springboot2008AdminUiServerApplication.class, args);
}
}
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.3.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <java.version>1.8</java.version> <spring-boot-admin.version>2.1.3</spring-boot-admin.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-client</artifactId> </dependency> <dependency> <groupId>org.jolokia</groupId> <artifactId>jolokia-core</artifactId> </dependency> <dependency> <groupId>com.googlecode.json-simple</groupId> <artifactId>json-simple</artifactId> <version>1.1</version> </dependency>
spring: ##配置client 注册到admin ui 平台 boot: admin: client: url: http://localhost:8800 application: name: admin-ui-client server: port: 8801 ### 开放所有的监控接口监控权限 management: endpoints: web: exposure: include: "*" endpoint: health: show-details: always
@SpringBootApplication
public class Springboot2008AdminUiClientApplication {
public static void main(String[] args) {
SpringApplication.run(Springboot2008AdminUiClientApplication.class, args);
}
}
https://gitee.com/hejr.cn.com/SpringBoot2.0_2019/tree/master/springboot2_008_admin_ui_client
https://gitee.com/hejr.cn.com/SpringBoot2.0_2019/tree/master/springboot2_008_admin_ui_server
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。