Spring Boot Admin服务监控

目录

  • 概述
  • 实践
    • server端
      • pom.xml
      • 类配置
      • 结果
      • client
      • pom.xml
      • 配置
  • 结束

概述

Spring Boot Admin 集权限、日志、异常通知。

实践

server端

pom.xml

<!-- SpringBoot Admin -->
<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-server</artifactId>
    <version>${spring-boot-admin.version}</version>
</dependency>

<!-- SpringCloud Alibaba Nacos -->
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>

<!-- SpringCloud Alibaba Nacos Config -->
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>

<!-- SpringCloud Alibaba Sentinel -->
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>

<!-- SpringBoot Web -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- Spring Security -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>

类配置

@EnableWebSecurity
public class WebSecurityConfigurer
{
    private final String adminContextPath;

    public WebSecurityConfigurer(AdminServerProperties adminServerProperties)
    {
        this.adminContextPath = adminServerProperties.getContextPath();
    }

    @Bean
    public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception
    {
        SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
        successHandler.setTargetUrlParameter("redirectTo");
        successHandler.setDefaultTargetUrl(adminContextPath + "/");

        return httpSecurity
                .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()
                .build();
    }
}
import de.codecentric.boot.admin.server.domain.entities.InstanceRepository;
import de.codecentric.boot.admin.server.domain.events.InstanceEvent;
import de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent;
import de.codecentric.boot.admin.server.notify.AbstractStatusChangeNotifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

/**
 * 通知发送配置测试用例
 */
@Component
public class StatusChangeNotifier extends AbstractStatusChangeNotifier {

    private static final Logger LOGGER = LoggerFactory.getLogger(RuoYiStatusChangeNotifier.class);

    public RuoYiStatusChangeNotifier(@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") InstanceRepository repository) {
        super(repository);
        LOGGER.info("通知发送配置测试用例初始化...");
    }

    @Override
    protected Mono<Void> doNotify(InstanceEvent event,
                                  de.codecentric.boot.admin.server.domain.entities.Instance instance) {
        return Mono.fromRunnable(() -> {
            if (event instanceof InstanceStatusChangedEvent) {
                String instanceName = instance.getRegistration().getName();
                String serviceUrl = instance.getRegistration().getServiceUrl();
                String status = ((InstanceStatusChangedEvent) event).getStatusInfo().getStatus();
                switch (status) {
                    // 健康检查没通过
                    case "DOWN":
                        LOGGER.info("实例名称:{},url:{},发送 健康检查没通过 的通知!", instanceName, serviceUrl);
                        break;
                    // 服务离线
                    case "OFFLINE":
                        LOGGER.info("实例名称:{},url:{},发送 服务离线 的通知!", instanceName, serviceUrl);
                        break;
                    // 服务上线
                    case "UP":
                        LOGGER.info("实例名称:{},url:{},发送 服务上线 的通知!", instanceName, serviceUrl);
                        break;
                    // 服务未知异常
                    case "UNKNOWN":
                        LOGGER.info("实例名称:{},url:{},发送 服务未知异常 的通知!", instanceName, serviceUrl);
                        break;
                    default:
                        LOGGER.info("实例名称:{},url:{},其它情况!", instanceName, serviceUrl);
                        break;
                }
            }
        });
    }
}

结果

在这里插入图片描述

client

pom.xml

添加依赖

<!-- SpringBoot Admin Client -->
<dependency>
	<groupId>de.codecentric</groupId>
	<artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>

<!-- SpringBoot Actuator -->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

配置

spring:
  autoconfigure:
    exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher
  boot:
    admin:
      client:
        url: http://xx.3xx.xx.131:9100
logging:
  file:
    name: logs/${spring.application.name}/info.log

Spring Boot Admin提供了基于Web页面的方式实时查看服务输出的本地日志,前提是服务中配置了logging.file.name

在这里插入图片描述

结束

Spring Boot Admin服务监控 至此结束。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/452544.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【算法面试题】-07

小明找位置 题目描述 小朋友出操&#xff0c;按学号从小到大排成一列;小明来迟了&#xff0c;请你给小明出个主意&#xff0c;让他尽快找到他应该排的位置。 算法复杂度要求不高于nLog(n);学号为整数类型&#xff0c;队列规模<10000; 输入描述 1、第一行:输入已排成队列的…

STM32外设分类--学习笔记

简介: 本文在于根据自己的理解&#xff0c;将stm32f103外设按照功能分个类别&#xff0c;便于记忆。下面的几张图一定要熟悉&#xff0c;后期编写代码时能够快速找到想要的功能和对应的引脚。 我使用的工具链是&#xff1a;使用CubeMX完成keil5工程搭建和引脚初始化功能,然后用…

使用Maven打包时出现Please refer to D:路径 for the individual怎么解决?

遇到这种情况不要着急&#xff0c;直接按照下面步骤即可&#xff1a; 解决方法1 可能是你的测试用例里出现了bug&#xff0c;根据下面提示的路径可以找到bug&#xff0c;打开 txt 文件&#xff08;可以每个都打开&#xff0c;不一定是哪个出bug了&#xff09; 去项目中修改完…

LeetCode(力扣)算法题_1261_在受污染的二叉树中查找元素

今天是2024年3月12日&#xff0c;可能是因为今天是植树节的原因&#xff0c;今天的每日一题是二叉树&#x1f64f;&#x1f3fb; 在受污染的二叉树中查找元素 题目描述 给出一个满足下述规则的二叉树&#xff1a; root.val 0 如果 treeNode.val x 且 treeNode.left ! n…

基于pci多功能采集卡——pci9640

一、追逐潮流&#xff0c;应运而生 信息社会的高速发展&#xff0c;在很大程度上取决于信息与信号处理的先进性。数字信号处理技术的出现改变了信号与信号处理技术的整个面貌&#xff0c;而数据采集作为数字信号处理的必不可少的前期工作在整个数字系统中起到关键性乃至决定性的…

C# RAM Stable Diffusion 提示词反推 Onnx Demo

目录 介绍 效果 模型信息 项目 代码 下载 C# RAM Stable Diffusion 提示词反推 Onnx Demo 介绍 github地址&#xff1a;GitHub - xinyu1205/recognize-anything: Open-source and strong foundation image recognition models. Open-source and strong foundation ima…

【Android】源码中的建造者模式

本文是基于 Android 14 的源码解析 在 Android 源码中&#xff0c;最常用到的建造者模式就是 AlertDialog.Builder&#xff0c;使用该建造者来构建复杂的 AlertDialog 对象。在开发过程中&#xff0c;我们经常用到 AlertDialog&#xff0c;具体示例如下&#xff1a; private f…

SA3D:基于 NeRF 的三维场景分割方法

Paper: Cen J, Zhou Z, Fang J, et al. Segment anything in 3d with nerfs[J]. Advances in Neural Information Processing Systems, 2024, 36. Introduction: https://jumpat.github.io/SA3D/ Code: https://github.com/Jumpat/SegmentAnythingin3D SA3D 是一种用于 NeRF 表…

RabbitMQ 面试题及答案整理,最新面试题

RabbitMQ的核心组件有哪些&#xff1f; RabbitMQ的核心组件包括&#xff1a; 1、生产者&#xff08;Producer&#xff09;&#xff1a; 生产者是发送消息到RabbitMQ的应用程序。 2、消费者&#xff08;Consumer&#xff09;&#xff1a; 消费者是接收RabbitMQ消息的应用程序…

阿里云领盲盒活动

阿里云每次的活动都很给力&#xff0c;实打实地发东西。 这次是体验 通义灵码 的活动&#xff0c;这个是体验的推广链接 「通义灵码 体验 AI 编码&#xff0c;开 AI 盲盒」 我是在vscode安装的&#xff0c;体验还行&#xff0c;抽奖抽到了马克杯 这个是抽奖的具体步骤 https:…

mysql对索引的选择简述

概述 在业务中经常会优化一些mysql的慢查询&#xff0c;通常都是使用explain去查看分析&#xff0c;检查扫描行数和索引的命中情况&#xff1b; 但是在具体索引的选择上&#xff0c;explain结果中并没有直接展示出来&#xff1b; 此时可以开启mysql的追踪优化器Trace功能&…

【Greenhills】MULTI IDE网络版license统计授权使用情况

【更多软件使用问题请点击亿道电子官方网站查询】 1、 文档目标 用于购买了GHS网络版的客户&#xff0c;对于license的调用情况进行统计和管理 2、 问题场景 对于购买了GHS网络版license的客户&#xff0c;想要对于授权的使用情况进行分析和管理&#xff0c;但是&#xff0c;…

c++ 常用函数 集锦 整理中

c 常用函数集锦 目录 1、string和wstring之间转换 1、string和wstring之间转换 std::string convertWStringToString(std::wstring wstr) {std::string str;if (!wstr.empty()){std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;str converter.to_b…

【论文阅读】ACM MM 2023 PatchBackdoor:不修改模型的深度神经网络后门攻击

文章目录 一.论文信息二.论文内容1.摘要2.引言3.作者贡献4.主要图表5.结论 一.论文信息 论文题目&#xff1a; PatchBackdoor: Backdoor Attack against Deep Neural Networks without Model Modification&#xff08;PatchBackdoor:不修改模型的深度神经网络后门攻击&#xf…

西井科技参与IATA全球货运大会 以AI绿动能引领智慧空港新未来

3月12日至14日&#xff0c;由国际航空运输协会IATA主办的全球货运大会&#xff08;World Cargo Symposium&#xff09;在中国香港成功举办&#xff0c;这是全球航空货运领域最大规模与影响力的年度盛会。作为大物流领域全球领先的“智能化与新能源化”综合解决方案提供商&#…

参加大广赛是否有价值?让我们来看答案!

大广赛全称是全国大学生广告艺术大赛&#xff0c;是中国最大的高校广告创意竞赛活动。它由教育部高等教育司指导&#xff0c;中国传媒大学、大广赛文化传播&#xff08;北京&#xff09;有限公司共同举办。 命题素材在线预览https://js.design/f/Jspbti?sourcesh&planbtt…

互联网操作系统Puter

什么是 Puter &#xff1f; Puter 是一个先进的开源桌面环境&#xff0c;运行在浏览器中&#xff0c;旨在具备丰富的功能、异常快速和高度可扩展性。它可以用于构建远程桌面环境&#xff0c;也可以作为云存储服务、远程服务器、Web 托管平台等的界面。Puter 是一个隐私至上的个…

垃圾清理软件大全免费 磁盘空间不足?注册表不敢乱动怎么办?ccleaner官方下载

在日常的工作中&#xff0c;面对重要文件时往往都会备份一份&#xff1b;在下载文件时&#xff0c;有时也会不小心把一份文件下载好多次。这些情况会导致电脑中出现重复的文件&#xff0c;删除这些重复文件&#xff0c;可以节省电脑空间&#xff0c;帮助提高电脑运行速度。那么…

websocket 使用示例

websocket 使用示例 前言html中使用vue3中使用1、安装websocket依赖2、代码 vue2中使用1、安装websocket依赖2、代码 前言 即时通讯webSocket 的使用 html中使用 以下是一个简单的 HTML 页面示例&#xff0c;它连接到 WebSocket 服务器并包含一个文本框、一个发送按钮以及 …

大语言模型RAG-技术概览 (一)

大语言模型RAG-技术概览 (一) 一 RAG概览 检索增强生成&#xff08;Retrieval-AugmentedGeneration, RAG&#xff09;。即大模型在回答问题或生成问题时会先从大量的文档中检索相关的信息&#xff0c;然后基于这些信息进行回答。RAG很好的弥补了传统搜索方法和大模型两类技术…
最新文章