微服务之服务监控篇 ActuatorAdmin
微服务之服务监控篇 Actuator
服务监控
- 什么是服务监控?
- 主要是查看当前系统的运行状态,例如内存、线程、堆栈、日志等等,通过服务监控可以快速准确的发现问题,以减少或避免对用户的影响.
- 为什么使用服务监控
- 随着功能的拆分. 微服务越来越多,相互调用出错的概率也越来越大,如果不能及时发现问题会引起灾难性后果.
Spring Boot Actuator &Admin
- actuator是监控系统健康情况的工具,admin是一个针对spring-boot的actuator接口进行UI美化封装的监控工具
入门小demo
创建SpringBoot项目版本2.3.5.RELEASE
引入依赖
<!-- SpringBoot Web --> <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId> </dependency><!-- SpringBoot Actuator --> <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId><version>2.3.5.RELEASE</version> </dependency>
application.yml配置
management:endpoints:web:exposure:include: '*' # 暴露所有的监控点
启动项目并访问:
http://localhost:8080/actuator
服务端返回
好丑啊,看不下去.
添加依赖并在启动类添加@EnableAdminServer注解
<!-- SpringBoot Admin --> <dependency><groupId>de.codecentric</groupId><artifactId>spring-boot-admin-starter-server</artifactId><version>2.3.1</version> </dependency>
测试访问:
http://192.168.83.1:8080/wallboard
服务监控更多细节
客户端配置整合nacos
添加依赖
<!-- springcloud alibaba nacos discovery --> <dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency>
application.yml
spring:application:name: project-test # \u670D\u52A1\u540D\u79F0cloud:nacos:discovery:server-addr: 192.168.88.166:8848 # nacos\u5730\u5740
访问结果
登录认证
添加依赖
<!-- spring security --> <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId><version>2.4.0</version> </dependency>
配置类只要登录即可
@Component public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {private final String adminContextPath;public WebSecurityConfigurer(AdminServerProperties adminServerProperties) {this.adminContextPath = adminServerProperties.getContextPath();}@Overrideprotected void configure(HttpSecurity http) throws Exception {SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();successHandler.setTargetUrlParameter("redirectTo");successHandler.setDefaultTargetUrl(adminContextPath + "/");http.headers().frameOptions().disable().and().authorizeRequests().antMatchers(adminContextPath + "/assets/**", adminContextPath + "/login", adminContextPath + "/actuator/**", adminContextPath + "/instances/**").permitAll().anyRequest().authenticated().and().formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and().logout().logoutUrl(adminContextPath + "/logout").and().httpBasic().and().csrf().disable();} }
application.yml配置用户名和密码
spring:security:user:name: testpassword: 123456
访问时出现如下界面
自定义通知
@Component public class StatusDangerNotifier extends AbstractStatusChangeNotifier {public StatusDangerNotifier(InstanceRepository repository) {super(repository);}@Overrideprotected Mono<Void> doNotify(InstanceEvent event,de.codecentric.boot.admin.server.domain.entities.Instance instance) {return Mono.fromRunnable(() -> {if (event instanceof InstanceStatusChangedEvent) {String status = ((InstanceStatusChangedEvent) event).getStatusInfo().getStatus();switch (status) {// 健康检查没通过case "DOWN":System.out.println("发送 健康检查没通过 的通知!");break;// 服务离线case "OFFLINE":System.out.println("发送 服务离线 的通知!");break;// 服务上线case "UP":System.out.println("发送 服务上线 的通知!");break;// 服务未知异常case "UNKNOWN":System.out.println("发送 服务未知异常 的通知!");break;default:break;}}});} }
总结
- 阅读微服务相关的姊妹篇可以更好的理解本文哦
- 文章列表
- 微服务之网关篇 Spring Cloud Gateway
- 微服务之注册中心篇 Nacos
- 微服务之配置中心篇 Naocs
- 微服务之远程调用篇 OpenFeign
- 微服务之链路追踪篇 Skywalking
- 微服务之分布式日志 ELK
- 微服务之分布式事务篇 Seata
- 微服务思想介绍
- 微服务之熔断与降级篇 Sentinel
微服务之服务监控篇 ActuatorAdmin相关推荐
- 服务治理(系统监控篇): 开源一站式运维管家ChengYing(承影)
文章目录 简介 一.特性 1.自动化部署 2.界面化集群运维 3.仪表盘集群监控 4.实时告警 5.强拓展性 6.安全稳定 二.操作界面 三.未来 四.总结 其他 简介 继ChunJun(纯钧).Ta ...
- 主流微服务全链路监控系统之战
点击上方蓝色"方志朋",选择"设为星标"回复"666"获取独家整理的学习资料!问题背景随着微服务架构的流行,服务按照不同的维度进行拆分,一次 ...
- springboot springcloud区别_SpringCloud微服务全家桶-第一篇!为什么要用微服务
从今天开始,学习SpringCloud微服务全家桶. 一.引导 1.什么是微服务? 2.微服务之间是如何独立通讯的 3.springCloud和Dubbo有哪些区别? 4.什么是服务熔断?什么是服务降 ...
- 黑马程序员---微服务笔记【实用篇】
微服务技术栈导学 微服务实现流程: 所有要学的技术: 分层次教学: 具体分层: 实用篇---第一天 一.认识微服务 单体架构 将业务所有功能集中在一个项目中开发,打成一个包部署 优点:架构简单.部署成 ...
- SpringCloud(第 003 篇)服务发现服务端EurekaServer微服务
SpringCloud(第 003 篇)服务发现服务端EurekaServer微服务 - 一.大致介绍 1.众所周知,在现在互联网开发中,访问地址的IP和端口号是动态的,一个服务停掉再重新启用后IP和 ...
- 想要设计自己的微服务?看这篇文章就对了
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由我就静静地看 发表于云+社区专栏 本文通过使用Spring Boot,Spring Cloud和Docker构建的概念验证应用程序的示 ...
- 想要设计自己的微服务?看这篇文章就对了 1
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由我就静静地看 发表于云+社区专栏 本文通过使用Spring Boot,Spring Cloud和Docker构建的概念验证应用程序的示 ...
- java微服务开发(基础环境篇)
java微服务开发(基础环境篇) 我们的目标是~~_浩瀚的宇宙 _~~全栈开发 俗话说的好 _工欲善其事 必先利其器 _对于一个开发者来说 一个好的开发环境可以带来的收益是巨大的 本篇的重点主要是li ...
- 【云原生微服务>SCG网关篇十二】Spring Cloud Gateway集成Sentinel API实现多种限流方式
文章目录 一.前言 二.Gateway集成Sentinel API 0.集成Sentinel的核心概念 1)GatewayFlowRule 和 ApiDefinition 2)GatewayFlowR ...
最新文章
- C 语言编程 — 大小端区分
- 【已解答】Linux ./configure --prefix 命令是什么意思?
- 12.Linux之输入子系统分析(详解)
- 自然语言处理中的Attention Model:是什么以及为什么[二]
- Java统计做题正确率_ResNet:训练期间的准确率为100%,但使用相同数据的预测准确率为33%...
- qt布局调用自定义函数_QT 自定义函数 自定义信号和槽
- ios 图片裁剪框架_iOS 图片裁剪与修改
- JS中异常处理的理解
- 生活情景英语:英语国家生存英语精选
- C++ string类成员函数
- 全国地图钻取(openlayers6+高德地图api行政区划)
- CentOS 6.2 + CUPS + AirPrint for iOS
- java 可达性算法实现,垃圾标记阶段算法之可达性分析算法
- 云原生 Kuma 简单部署与使用
- Java接口测试工具rap_接口文档管理工具-Postman、Swagger、RAP(转载)
- 报考建行考计算机专业知识资料,建设银行信息技术类考试都考什么,有没有以前......
- ios11修改微信步数_你会时常去看他的微信步数吗?
- 推荐国内外常见的一些学术文献数据库网站
- python括号是中文还是英文_Python括号约定
- 1.8 信息系统服务管理
热门文章
- android 上午零点格式,Android零点一度的区别——Matrix
- Python SyntaxError: Non-ASCII character '\xe5' in file
- twisted中的延迟(deferred)(一)
- Dev-C++如何单步调试程序--8min学会自己找程序错误
- CSU2020期中测试模拟题1 问题E:小帅的字符串
- Oracle导入dmp数据
- 并发编程之深入理解十三:CompletionService CompletableFuture
- python怎么把一个文件夹内的文件复制到另外一个文件夹(进阶重命名复制)
- 梦幻默认服务器文件夹修改器,【梦幻仙境V3.96服务端】梦幻最新完美开心版带存档与修改器时代梦幻最新5.2版本...
- 开发者不可错过的 10 个人工智能开源项目