- 应用端点
- Health端点
- info端点
- 监控信息可视化
- 邮件报警
- 应用端点--实时监控
- 创建项目,添加web依赖,添加Ops下的Spring Boot Actuator依赖
- 在application.properties中配置
- management.endpoint.shutdown.enabled=true //开启端点,默认情况没有开启
- 访问方式:http://localhsot:8080/autuator/health http://localhsot:8080/autuator/info
- Health端点
- management.endpoing.health.show-details=when_authorized //当应用获取信息认证请求后,详情就展示出来
- Info端点
- 应用信息
- 自定信息
- 项目构建信息
info.app.encoding=@project.build.sourceEncoding@
info.app.java.source=@java.version@
info.app.java.target=@java.version@
info.author.name=zenghao
info.author.address=www.baidu.com
http://hocalhost:8080/author/info
也可以用Java代码实现
@Component
public class zenghaoInfo implements InfoContributor {
@Override
public void contribute(Info.Builder builder) {
Map<String,Object> info = new HashMap<>();
info.put("email","1290410202@qq.com");
builder.withDetail("author",info);
}
}
在pom中配置
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
- 监控信息可视化
- 采集Spring Boot中的信息通过图表展示出来
- 创建项目 Admin 添加web依赖,添加Ops下的 SpringBoot Admin(Server)依赖
- 在Spring BootApplication启动类中加入注解 @EnabledAdminServer
- 访问:localhost:8080/index.html即可
- 创建另一个项目,Client,添加web依赖,添加OPs下的Spring Boot Actuator依赖和Spring Boot Admin(Client)依赖
- 在application.properties中配置 management.endpoints.webexposure.include=* //把所有的端口暴露出来
- server.port=8081
- spring.boot.admin.client.url=http://localhsot:8080 //连接第一个项目
- 再访问:http://localhost:8080/index.html
- 邮件报警
- 打开上面Admin工程,添加邮件依赖
<dependency> <grouoId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId> </dependency>
在application.properties中配置
spring.mail.host=smtp.qq.com spring.mail.port=587 //或者465 spring.mial.username=1290410202@qq.com spring.mail.password=agawybjhdmbkhhhih //授权码 spring.mail.default-encoding=UTF-8 spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory spring.mail.properties.mail.debug=true spring.boot.admin.notify.mail.to=251568707@qq.com //发送给谁 spring.boot.admin.notify.mail.from=1290410202@qq.com //从哪儿来的 spring.boot.admin.notify.mail.ignore-changes= //发生仍和变化都发邮件
即可!!!