SpringBootAdmin微服务应用监控如何改写为长尾词?
- 内容介绍
- 文章标签
- 相关推荐
本文共计1261个文字,预计阅读时间需要6分钟。
SpringBootAdmin简介:使用SpringBootAdmin实现微服务应用监控,希望读完本文后,大家都能有所收获,下面让我们一起去探讨吧!
自由互联小编给大家分享一下SpringBootAdmin微服务应用监控怎么实现,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!SpringBootAdmin简介Sp自由互联小编给大家分享一下SpringBootAdmin微服务应用监控怎么实现,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!
Spring Boot Admin 简介
SpringBoot应用可以通过Actuator来暴露应用运行过程中的各项指标,Spring Boot Admin通过这些指标来监控SpringBoot应用,然后通过图形化界面呈现出来。Spring Boot Admin不仅可以监控单体应用,还可以和Spring Cloud的注册中心相结合来监控微服务应用。
Spring Boot Admin 可以提供应用的以下监控信息:
监控应用运行过程中的概览信息; 度量指标信息,比如JVM、Tomcat及进程信息; 环境变量信息,比如系统属性、系统环境变量以及应用配置信息; 查看所有创建的Bean信息; 查看应用中的所有配置信息; 查看应用运行日志信息; 查看JVM信息; 查看可以访问的Web端点; 查看HTTP跟踪信息。
这里我们创建一个admin-server模块来作为监控中心演示其功能。
在pom.xml中添加相关依赖:
org.springframework.boot spring-boot-starter-web de.codecentric spring-boot-admin-starter-server
在application.yml中进行配置:
spring: application: name: admin-serverserver: port: 9301
在启动类上添加@EnableAdminServer来启用admin-server功能:
@EnableAdminServer@SpringBootApplicationpublic class AdminServerApplication { public static void main(String[] args) { SpringApplication.run(AdminServerApplication.class, args); }}
创建admin-client模块
这里我们创建一个admin-client模块作为客户端注册到admin-server。
在pom.xml中添加相关依赖:
org.springframework.boot spring-boot-starter-web de.codecentric spring-boot-admin-starter-client
在application.yml中进行配置:
spring: application: name: admin-client boot: admin: client: url: localhost:9301 #配置admin-server地址server: port: 9305management: endpoints: web: exposure: include: * endpoint: health: show-details: alwayslogging: file: admin-client.log #添加开启admin的日志监控
启动admin-server和admin-client服务。
监控信息演示
访问如下地址打开Spring Boot Admin的主页: localhost:9301
点击wallboard按钮,选择admin-client查看监控信息;
监控信息概览;
度量指标信息,比如JVM、Tomcat及进程信息;
环境变量信息,比如系统属性、系统环境变量以及应用配置信息;
查看所有创建的Bean信息;
查看应用中的所有配置信息;
查看日志信息,需要添加以下配置才能开启;
logging: file: admin-client.log #添加开启admin的日志监控
查看JVM信息;
查看可以访问的Web端点;
查看HTTP跟踪信息;
结合注册中心使用
Spring Boot Admin结合Spring Cloud 注册中心使用,只需将admin-server和注册中心整合即可,admin-server 会自动从注册中心获取服务列表,然后挨个获取监控信息。这里以Eureka注册中心为例来介绍下该功能。
修改admin-server 在pom.xml中添加相关依赖:
org.springframework.cloud spring-cloud-starter-netflix-eureka-client
在application-eureka.yml中进行配置,只需添加注册中心配置即可:
spring: application: name: admin-serverserver: port: 9301eureka: client: register-with-eureka: true fetch-registry: true service-url: defaultZone: localhost:8001/eureka/
在启动类上添加@EnableDiscoveryClient来启用服务注册功能:
@EnableDiscoveryClient@EnableAdminServer@SpringBootApplicationpublic class AdminServerApplication { public static void main(String[] args) { SpringApplication.run(AdminServerApplication.class, args); }}
修改admin-client
在pom.xml中添加相关依赖:
org.springframework.cloud spring-cloud-starter-netflix-eureka-client
在application-eureka.yml中进行配置,删除原来的admin-server地址配置,添加注册中心配置即可:
spring: application: name: admin-clientserver: port: 9305management: endpoints: web: exposure: include: * endpoint: health: show-details: alwayslogging: file: admin-client.log #添加开启admin的日志监控eureka: client: register-with-eureka: true fetch-registry: true service-url: defaultZone: localhost:8001/eureka/
在启动类上添加@EnableDiscoveryClient来启用服务注册功能:
@EnableDiscoveryClient@SpringBootApplicationpublic class AdminClientApplication { public static void main(String[] args) { SpringApplication.run(AdminClientApplication.class, args); }}
功能演示
启动eureka-server,使用application-eureka.yml配置启动admin-server,admin-client;
查看注册中心发现服务均已注册: localhost:8001/
查看Spring Boot Admin 主页发现可以看到服务信息: localhost:9301
添加登录认证
我们可以通过给admin-server添加Spring Security支持来获得登录认证功能。
创建admin-security-server模块
在pom.xml中添加相关依赖:
org.springframework.cloud spring-cloud-starter-netflix-eureka-client de.codecentric spring-boot-admin-starter-server 2.1.5 org.springframework.boot spring-boot-starter-security org.springframework.boot spring-boot-starter-web
在application.yml中进行配置,配置登录用户名和密码,忽略admin-security-server的监控信息:
spring: application: name: admin-security-server security: # 配置登录用户名和密码 user: name: macro password: 123456 boot: # 不显示admin-security-server的监控信息 admin: discovery: ignored-services: ${spring.application.name}server: port: 9301eureka: client: register-with-eureka: true fetch-registry: true service-url: defaultZone: localhost:8001/eureka/
对SpringSecurity进行配置,以便admin-client可以注册:
/** * Created by macro on 2019/9/30. */@Configurationpublic class SecuritySecureConfig extends WebSecurityConfigurerAdapter { private final String adminContextPath; public SecuritySecureConfig(AdminServerProperties adminServerProperties) { this.adminCOntextPath= adminServerProperties.getContextPath(); } @Override protected void configure(HttpSecurity localhost:9301
使用到的模块
springcloud-learning├── eureka-server -- eureka注册中心├── admin-server -- admin监控中心服务├── admin-client -- admin监控中心监控的应用服务└── admin-security-server -- 带登录认证的admin监控中心服务
看完了这篇文章,相信你对“SpringBootAdmin微服务应用监控怎么实现”有了一定的了解,如果想了解更多相关知识,欢迎关注编程笔记行业资讯频道,感谢各位的阅读!
本文共计1261个文字,预计阅读时间需要6分钟。
SpringBootAdmin简介:使用SpringBootAdmin实现微服务应用监控,希望读完本文后,大家都能有所收获,下面让我们一起去探讨吧!
自由互联小编给大家分享一下SpringBootAdmin微服务应用监控怎么实现,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!SpringBootAdmin简介Sp自由互联小编给大家分享一下SpringBootAdmin微服务应用监控怎么实现,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!
Spring Boot Admin 简介
SpringBoot应用可以通过Actuator来暴露应用运行过程中的各项指标,Spring Boot Admin通过这些指标来监控SpringBoot应用,然后通过图形化界面呈现出来。Spring Boot Admin不仅可以监控单体应用,还可以和Spring Cloud的注册中心相结合来监控微服务应用。
Spring Boot Admin 可以提供应用的以下监控信息:
监控应用运行过程中的概览信息; 度量指标信息,比如JVM、Tomcat及进程信息; 环境变量信息,比如系统属性、系统环境变量以及应用配置信息; 查看所有创建的Bean信息; 查看应用中的所有配置信息; 查看应用运行日志信息; 查看JVM信息; 查看可以访问的Web端点; 查看HTTP跟踪信息。
这里我们创建一个admin-server模块来作为监控中心演示其功能。
在pom.xml中添加相关依赖:
org.springframework.boot spring-boot-starter-web de.codecentric spring-boot-admin-starter-server
在application.yml中进行配置:
spring: application: name: admin-serverserver: port: 9301
在启动类上添加@EnableAdminServer来启用admin-server功能:
@EnableAdminServer@SpringBootApplicationpublic class AdminServerApplication { public static void main(String[] args) { SpringApplication.run(AdminServerApplication.class, args); }}
创建admin-client模块
这里我们创建一个admin-client模块作为客户端注册到admin-server。
在pom.xml中添加相关依赖:
org.springframework.boot spring-boot-starter-web de.codecentric spring-boot-admin-starter-client
在application.yml中进行配置:
spring: application: name: admin-client boot: admin: client: url: localhost:9301 #配置admin-server地址server: port: 9305management: endpoints: web: exposure: include: * endpoint: health: show-details: alwayslogging: file: admin-client.log #添加开启admin的日志监控
启动admin-server和admin-client服务。
监控信息演示
访问如下地址打开Spring Boot Admin的主页: localhost:9301
点击wallboard按钮,选择admin-client查看监控信息;
监控信息概览;
度量指标信息,比如JVM、Tomcat及进程信息;
环境变量信息,比如系统属性、系统环境变量以及应用配置信息;
查看所有创建的Bean信息;
查看应用中的所有配置信息;
查看日志信息,需要添加以下配置才能开启;
logging: file: admin-client.log #添加开启admin的日志监控
查看JVM信息;
查看可以访问的Web端点;
查看HTTP跟踪信息;
结合注册中心使用
Spring Boot Admin结合Spring Cloud 注册中心使用,只需将admin-server和注册中心整合即可,admin-server 会自动从注册中心获取服务列表,然后挨个获取监控信息。这里以Eureka注册中心为例来介绍下该功能。
修改admin-server 在pom.xml中添加相关依赖:
org.springframework.cloud spring-cloud-starter-netflix-eureka-client
在application-eureka.yml中进行配置,只需添加注册中心配置即可:
spring: application: name: admin-serverserver: port: 9301eureka: client: register-with-eureka: true fetch-registry: true service-url: defaultZone: localhost:8001/eureka/
在启动类上添加@EnableDiscoveryClient来启用服务注册功能:
@EnableDiscoveryClient@EnableAdminServer@SpringBootApplicationpublic class AdminServerApplication { public static void main(String[] args) { SpringApplication.run(AdminServerApplication.class, args); }}
修改admin-client
在pom.xml中添加相关依赖:
org.springframework.cloud spring-cloud-starter-netflix-eureka-client
在application-eureka.yml中进行配置,删除原来的admin-server地址配置,添加注册中心配置即可:
spring: application: name: admin-clientserver: port: 9305management: endpoints: web: exposure: include: * endpoint: health: show-details: alwayslogging: file: admin-client.log #添加开启admin的日志监控eureka: client: register-with-eureka: true fetch-registry: true service-url: defaultZone: localhost:8001/eureka/
在启动类上添加@EnableDiscoveryClient来启用服务注册功能:
@EnableDiscoveryClient@SpringBootApplicationpublic class AdminClientApplication { public static void main(String[] args) { SpringApplication.run(AdminClientApplication.class, args); }}
功能演示
启动eureka-server,使用application-eureka.yml配置启动admin-server,admin-client;
查看注册中心发现服务均已注册: localhost:8001/
查看Spring Boot Admin 主页发现可以看到服务信息: localhost:9301
添加登录认证
我们可以通过给admin-server添加Spring Security支持来获得登录认证功能。
创建admin-security-server模块
在pom.xml中添加相关依赖:
org.springframework.cloud spring-cloud-starter-netflix-eureka-client de.codecentric spring-boot-admin-starter-server 2.1.5 org.springframework.boot spring-boot-starter-security org.springframework.boot spring-boot-starter-web
在application.yml中进行配置,配置登录用户名和密码,忽略admin-security-server的监控信息:
spring: application: name: admin-security-server security: # 配置登录用户名和密码 user: name: macro password: 123456 boot: # 不显示admin-security-server的监控信息 admin: discovery: ignored-services: ${spring.application.name}server: port: 9301eureka: client: register-with-eureka: true fetch-registry: true service-url: defaultZone: localhost:8001/eureka/
对SpringSecurity进行配置,以便admin-client可以注册:
/** * Created by macro on 2019/9/30. */@Configurationpublic class SecuritySecureConfig extends WebSecurityConfigurerAdapter { private final String adminContextPath; public SecuritySecureConfig(AdminServerProperties adminServerProperties) { this.adminCOntextPath= adminServerProperties.getContextPath(); } @Override protected void configure(HttpSecurity localhost:9301
使用到的模块
springcloud-learning├── eureka-server -- eureka注册中心├── admin-server -- admin监控中心服务├── admin-client -- admin监控中心监控的应用服务└── admin-security-server -- 带登录认证的admin监控中心服务
看完了这篇文章,相信你对“SpringBootAdmin微服务应用监控怎么实现”有了一定的了解,如果想了解更多相关知识,欢迎关注编程笔记行业资讯频道,感谢各位的阅读!

