SpringBoot Admin健康检查功能的实现
监控检查,检查的是什么了。检查的是应用实例状态,说白了就是被查服务提供信息给检查服务端。在spring cloud 中可以有两种方式进行健康检查,一种是应用主动上报到admin服务端,第二种就是的admin项目eureka服务端拉取信息。admin主要就是告诉运维人员,服务出现异常,然后进行通知(微信、邮件、短信、钉钉等)可以非常快速通知到运维人员,相当报警功能。应用中如果没有监控服务状态功能,又需要及时通知运维人员服务状态,就可以使用这个admin服务。
实现admin功能创建客户端创建新的模块服务依赖引入
<!-- Admin 服务 --><dependency><groupId>de.codecentric</groupId><artifactId>spring-boot-admin-starter-server</artifactId></dependency><!-- Admin 界面 --><dependency><groupId>de.codecentric</groupId><artifactId>spring-boot-admin-server-ui</artifactId></dependency><!--如果使用eureka拉取方式就需要引入依赖--><dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency>
启动添加注解
@SpringBootApplication@EnableAdminServerpublic class AdminApplication {}
添加配置信息
#设置服务注册中心的URL,用于client和server端交流eureka.client.service-url.defaultZone=http://eureka1.com:7100/eureka/,http://eureka2.com:7200/eureka/server.port=8081spring.application.name=admin主动上报的服务端
如果服务已经添加注册中就不需要进行这步。依赖引入
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId></dependency><dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-client</artifactId></dependency>
添加配置
management.endpoints.web.exposure.include=*management.endpoint.health.show-details=alwaysspring.boot.admin.client.url=http://localhost:8081实现效果
所有应用信息在线状态
查看单个服务信息
所有配置信息,包括默认值都是显示出来,这样就旁边查看配置信息。
环境信息,这个包含本地环境信息,运行环境信息。
依赖加载
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId></dependency>
添加配置
# qq邮箱设置spring.mail.host=smtp.qq.comspring.mail.username=79811111spring.mail.password=ssssdfffdddfffspring.mail.properties.mail.smpt=truespring.mail.properties.mail.starttls.enable=truespring.mail.properties.mail.starttls.required=true#收件邮箱spring.boot.admin.notify.mail.to=243333355@qq.com# 发件邮箱spring.boot.admin.notify.mail.from=79811111@qq.com
qq邮箱怎么获取授权码当服务异常就会收到邮件
自定义通知类型类继承AbstractStatusChangeNotifier类重写doNotify(InstanceEvent event, Instance instance)方法,加载bean初始就可以了。
代码地址https://gitee.com/zhang798/spring-cloud/tree/admin分支:admin
git clone https://gitee.com/zhang798/spring-cloud.git -b admin
以上就是SpringBoot Admin健康检查的详细内容,更多关于SpringBoot 健康检查的资料请关注好吧啦网其它相关文章!
相关文章:
1. React中的合成事件是什么原理2. Vue Element UI 表单自定义校验规则及使用3. 用css截取字符的几种方法详解(css排版隐藏溢出文本)4. CSS3实例分享之多重背景的实现(Multiple backgrounds)5. 在 XSL/XSLT 中实现随机排序6. ie6,ie7,ie8完美支持position:fixed的终极解决方案7. CSS Hack大全-教你如何区分出IE6-IE10、FireFox、Chrome、Opera8. CSS可以做的几个令你叹为观止的实例分享9. 《CSS3实战》笔记--渐变设计(一)10. chatGPT教我写compose函数的详细过程
