SpringBoot学习笔记(14):使用SpringBootAdmin管理监控你的应用

SpringBoot学习笔记(14):使用SpringBootAdmin管理监控你的应用

Spring Boot Admin是一个管理和监控Spring Boot应用程序的应用程序。本文参考文档:

  • 官方文档:http://codecentric.github.io/spring-boot-admin/1.5.6
  • GITHUB仓库:https://github.com/codecentric/spring-boot-admin
  • 纯洁的微笑:http://www.ityouknow.com/springboot/2018/02/11/spring-boot-admin.html

SBA现在有三个版本,下面是是三个版本的参考文档,本文基于1.5.7

SpringBootAdmin是什么

  Spring Boot Admin是一个管理和监控Spring Boot应用程序的应用程序。应用程序向我们的Spring Boot Admin Client注册(通过HTTP)或使用Spring Cloud(例如Eureka)发现。它是基于AngularJs在前端显示Spring Boot Actuator数据的应用。

  

快速开始

新建一个SpringBoot应用作为服务端

  首先,您需要设置您的服务器。要做到这一点,只需设置一个简单的启动项目(例如使用start.spring.io)。

1.将Spring Boot Admin Server和UI添加到依赖项:

<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>

2.通过将@EnableAdminServer添加到您的配置来引入Spring Boot Admin Server配置:

@Configuration
@EnableAutoConfiguration
@EnableAdminServer
public class SpringBootAdminApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringBootAdminApplication.class, args);
    }
}

 我在这里将该应用的端口设置为8088,启动应用后,可看到其效果:

  

在客户端注册服务

1.添加客户端必要依赖

<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-client</artifactId>
    <version>1.5.6</version>
</dependency>

2.通过配置Spring Boot Admin Server的URL来启用SBA客户端:

1.spring.boot.admin.url: http://localhost:8080  
2.management.security.enabled: false   

说明:
1.要注册的Spring Boot Admin Server的URL。

2.从Spring Boot 1.5.x开始,默认情况下所有端点都是安全的。为简洁起见,我们暂时禁用了安全性。查看有关如何处理安全端点的安全性部分。 

扫描二维码关注公众号,回复: 4023209 查看本文章

配置完成之后,启动Client端服务,再次访问服务:http://localhost:8000可以看到客户端的相关信息。

  

邮件通知

使用 spring-boot-starter-mail 创建邮箱发送器

pom.xml
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-mail</artifactId>
</dependency>

application.properties

spring.mail.host=smtp.example.com
[email protected]  

其他的邮箱通知注册项

Property name Description Default value

spring.boot.admin.notify.mail.enabled

Enable mail notifications

true

spring.boot.admin.notify.mail.ignore-changes

Comma-delimited list of status changes to be ignored. Format: "<from-status>:<to-status>". Wildcards allowed.

"UNKNOWN:UP"

spring.boot.admin.notify.mail.to

Comma-delimited list of mail recipients

"root@localhost"

spring.boot.admin.notify.mail.cc

Comma-delimited list of carbon-copy recipients

 

spring.boot.admin.notify.mail.from

Mail sender

 

spring.boot.admin.notify.mail.subject

Mail subject. SpEL-expressions are supported

"#{application.name} (#{application.id}) is #{to.status}"

spring.boot.admin.notify.mail.text

Mail body. SpEL-expressions are supported

"#{application.name} (#{application.id})\nstatus changed from #{from.status} to #{to.status}\n\n#{application.healthUrl}"

配置完成后,重新启动项目spring-boot-admin-server,这样Admin Server就具备了邮件告警的功能。

猜你喜欢

转载自www.cnblogs.com/MrSaver/p/9941513.html