SpringBoot+actuator和admin-UI实现监控中心

news/2024/5/12 20:00:28/文章来源:https://blog.csdn.net/myyhtw/article/details/131724515

使用SpringBoot很久了,但是很少使用到SpringBoot的查看和监控,将来八成也不会用到,万一有机会用到呢?所以记录一下以前学习SpringBoot+actuator和adminUI实现监控中心的方式

Springboot的版本2.0.x

<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.0.5.RELEASE</version><relativePath/> <!-- lookup parent from repository -->
</parent>

导入对应的包

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId><version>2.0.5.RELEASE</version>
</dependency><!-- security 一旦导入就会生效 -->
<!--
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId>
</dependency><dependency><groupId>org.springframework.security</groupId><artifactId>spring-security-test</artifactId><scope>test</scope>
</dependency>-->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
</dependency>

application.properties

server.port=7080# 配置用户名和密码
#spring.security.user.name=admin
#spring.security.user.password=123456# 端点信息配置
management.server.port=8081
management.server.servlet.context-path=/sys
# 默认 never always可以显示硬盘使用情况和线程情况
management.endpoint.health.show-details=always
# 端点暴露的内容,默认["health","info"],设置"*"代表暴露所有可访问的端点
management.endpoints.web.exposure.include=*# actuator 信息
info.actuator.name=test

启动之后

myw
访问

http://localhost:8081/sys/actuator

myw
在这里使用的Actuator是spring boot的一个附加功能,可帮助你在应用程序生产环境时监视和管理应用程序。可以使用HTTP的各种请求来监管,审计,收集应用的运行情况.特别对于微服务管理十分有意义.缺点:没有可视化界面。
使用场景,针对微服务的服务状态监控,服务器的内存变化(堆内存,线程,日志管理等),检测服务配置连接地址是否可用(模拟访问,懒加载),统计现在有多少个bean(Spring容器中的bean) 统计接口数量, 应用场景:生产环境

/actuator/beans 显示应用程序中所有Spring bean的完整列表
/actuator/configprops 显示所有配置信息
/actuator/env 陈列所有的环境变量
/actuator/mappings 显示所有@RequestMapping的url整理列表
/actuator/health 显示应用程序运行状况信息 up表示成功 down失败,对于懒加载没报错的可以看到控制台报错了
/actuator/info 查看自定义应用信息

懒加载有个缺点,例如mysql的配置,启动的时候不会发现错误,只有运行的时候才报错

当访问

http://localhost:8081/sys/actuator/health

myw
使用adminUI的方式 client客户端导包和配置
pom.xml

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId><version>2.0.5.RELEASE</version>
</dependency>
<dependency><groupId>de.codecentric</groupId><artifactId>spring-boot-admin-starter-client</artifactId><version>2.0.5</version>
</dependency>

application.properties

server.port=8071spring.application.name=boot-example-admin-clientspring.boot.admin.client.url=http://127.0.0.1:8050/myw-admin
spring.boot.admin.client.username=admin
spring.boot.admin.client.password=123456
spring.boot.admin.client.instance.service-url=http://127.0.0.1:8071#management.server.port=8081
#management.server.servlet.context-path=/sys
# 默认 never always可以显示硬盘使用情况和线程情况
management.endpoint.health.show-details=always
# 端点暴露的内容,默认["health","info"],设置"*"代表暴露所有可访问的端点
management.endpoints.web.exposure.include=*

使用admin-ui的方式 server服务端导包和配置
pom.xml

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency><groupId>de.codecentric</groupId><artifactId>spring-boot-admin-starter-server</artifactId><version>2.0.5</version>
</dependency>

application.properties

server.port=8050
server.servlet.context-path=/myw-admin
spring.application.name=boot-example-admin-serverspring.security.user.name=admin
spring.security.user.password=123456

WebSecurityConfig.java

package boot.example.admin.server;import de.codecentric.boot.admin.server.config.AdminServerProperties;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;/*** SpringBootAdmin 登录鉴权使用**/
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {private final String contextPath;public WebSecurityConfig(AdminServerProperties adminServerProperties) {this.contextPath = adminServerProperties.getContextPath();}@Overrideprotected void configure(HttpSecurity http) throws Exception {// 跨域设置,SpringBootAdmin客户端通过instances注册,见InstancesControllerhttp.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()).ignoringAntMatchers(contextPath + "/instances");http.authorizeRequests().antMatchers(contextPath + "/assets/**").permitAll(); // 静态资源http.authorizeRequests().antMatchers(contextPath + "/actuator/**").permitAll(); // 自身监控http.authorizeRequests().anyRequest().authenticated(); // 所有请求必须通过认证// 整合spring-boot-admin-server-uihttp.formLogin().loginPage("/login").permitAll();http.logout().logoutUrl("/logout").logoutSuccessUrl("/login");// 启用basic认证,SpringBootAdmin客户端使用的是basic认证http.httpBasic();}
}

启动客户端和服务端的监控中心

http://localhost:8050/myw-admin/login#/applications

myw
myw
myw
记录一下在SpringBoot2.6.6版本使用

<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.6.6</version><relativePath/> <!-- lookup parent from repository -->
</parent>

client的pom.xml

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId><version>2.6.6</version>
</dependency>
<dependency><groupId>de.codecentric</groupId><artifactId>spring-boot-admin-starter-client</artifactId><version>2.5.6</version>
</dependency>

application.properties 1

server.port=8071spring.application.name=boot-example-admin-client1spring.boot.admin.client.url=http://localhost:8050
spring.boot.admin.client.username=admin
spring.boot.admin.client.password=123456management.endpoint.health.show-details=always
management.endpoints.web.exposure.include=*

application.properties 2

server.port=8072spring.application.name=boot-example-admin-client2spring.boot.admin.client.url=http://localhost:8050
spring.boot.admin.client.username=admin
spring.boot.admin.client.password=123456management.server.port=8082
management.server.base-path = /sys
management.endpoint.health.show-details=always
management.endpoints.web.exposure.include=*

application.properties 3

server.port=8073spring.application.name=boot-example-admin-client3spring.boot.admin.client.url=http://localhost:8050
spring.boot.admin.client.username=admin
spring.boot.admin.client.password=123456#spring.security.user.name=admin
#spring.security.user.password=123456management.server.port=8083
management.server.base-path = /sys
management.endpoint.health.show-details=always
management.endpoints.web.exposure.include=*

服务端的配置

pom.xml

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
</dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId>
</dependency><dependency><groupId>de.codecentric</groupId><artifactId>spring-boot-admin-starter-server</artifactId><version>2.5.6</version>
</dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

application.properties

server.port=8050spring.application.name=boot-example-admin-serverspring.security.user.name=admin
spring.security.user.password=123456

备注记录到这里 将来会不会用到再说了。

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

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

相关文章

keepalived安装配置详解

文章目录 高可用介绍keepalived安装、使用vip漂移抓包脑裂脑裂有没有危害&#xff1f;如果有危害对业务有什么影响&#xff1f; keepalived架构双vip架构 Healthcheck实现 notifyVRRP选举格式 高可用 介绍 高可用性&#xff08;High Availability&#xff09;是指系统或服务能…

Word2Vec实现文本识别分类

深度学习训练营之使用Word2Vec实现文本识别分类 原文链接环境介绍前言前置工作设置GPU数据查看构建数据迭代器 Word2Vec的调用生成数据批次和迭代器模型训练初始化拆分数据集并进行训练 预测 原文链接 &#x1f368; 本文为&#x1f517;365天深度学习训练营 中的学习记录博客&…

pycharm新建分支并提送至GitHub

文章目录 前言pycharm创建本地分支Push至远程分支 前言 当我们写的项目代码越来越多时&#xff0c;一个master分支无法满足需求了&#xff0c;这个时候就需要创建分支来管理代码。 创建分支可以快速的回滚到某个节点的版本&#xff0c;也可以多个开发者同时开发一个项目&#…

剑指oferr68-II.二叉树的最近公共祖先

为什么这道题的难度是easy&#xff0c;我感觉挺难的啊&#xff0c;我想了挺久没有一点思路就直接看题解了。题解有两种解法&#xff0c;先看第一种存储父节点 class Solution {Map<Integer,TreeNode> parent new HashMap<Integer,TreeNode>();Set<Integer>…

windows nodejs 版本切换

一、按健winR弹出窗口&#xff0c;键盘输入cmd,然后敲回车。然后进入命令控制行窗口&#xff0c;并输入where node查看之前本地安装的node的路径。 二、找到上面找到的路径&#xff0c;将node.exe所在的父目录里面的所有东西都删除。 三、从官网下载安装包 https://github.com/…

Raft算法之日志复制

Raft算法之日志复制 一、日志复制大致流程 在Leader选举过程中&#xff0c;集群最终会选举出一个Leader节点&#xff0c;而集群中剩余的其他节点将会成为Follower节点。Leader节点除了向Follower节点发送心跳消息&#xff0c;还会处理客户端的请求&#xff0c;并将客户端的更…

AP5193 DC-DC宽电压LED降压恒流驱动器 LED电源驱动IC

产品 AP5193是一款PWM工作模式、外围简单、内置功率MOS管&#xff0c;适用于4.5-100V输入的高精度降压LED恒流驱动芯片。电流2.5A。AP5193可实现线性调光和PWM调光&#xff0c;线性调光脚有效电压范围0.55-2.6V.AP5193 工作频率可以通过RT 外部电阻编程来设定&#xff0c;同时…

linux下一个iic驱动(按键+点灯)-互斥

一、前提&#xff1a; 硬件部分&#xff1a; 1. rk3399开发板&#xff0c;其中的某一路iic&#xff0c;这个作为总线的主控制器 2. gd32单片机&#xff0c;其中的某一路iic&#xff0c;从设备。主要是按键上报和灯的亮灭控制。&#xff08;按键大约30个&#xff0c;灯在键的…

day34-servlet 分页

0目录 servlet 1.分页 分页逻辑1&#xff1a;数据库中20条记录&#xff0c;要求每页5条数据&#xff0c;则一共有4页 分页逻辑2&#xff1a;数据库中21条记录&#xff0c;要求每页5条数据&#xff0c;则一共有5页 分页逻辑3&#xff1a;数据库中19条记录&#xff0c;要求每页…

数字 IC 设计职位经典笔/面试题(二)

共100道经典笔试、面试题目&#xff08;文末可全领&#xff09; FPGA 中可以综合实现为 RAM/ROM/CAM 的三种资源及其注意事项&#xff1f; 三种资源&#xff1a;BLOCK RAM&#xff0c;触发器&#xff08;FF&#xff09;&#xff0c;查找表&#xff08;LUT&#xff09;&#xf…

【算法基础】2.1栈和队列(单调栈和单调队列)

文章目录 例题3302. 表达式求值&#xff08;栈的应用&#xff09;&#x1f62d;&#x1f62d;&#x1f62d;&#x1f62d;&#x1f62d;830. 单调栈知识点解法 154. 滑动窗口 &#xff08;单调队列&#xff09;知识点解法 相关链接 & 相关题目 例题 3302. 表达式求值&…

基于weka手工实现多层感知机(BPNet)

一、BP网络 1.1 单层感知机 单层感知机&#xff0c;就是只有一层神经元&#xff0c;它的模型结构如下1&#xff1a; 对于权重 w w w的更新&#xff0c;我们采用如下公式&#xff1a; w i w i Δ w i Δ w i η ( y − y ^ ) x i (1) w_iw_i\Delta w_i \\ \Delta w_i\eta(y…

RabbitMQ 同样的操作一次成功一次失败

RabbitMQ 是一个功能强大的消息队列系统&#xff0c;广泛应用于分布式系统中。然而&#xff0c;我遇到这样的情况&#xff1a;执行同样的操作&#xff0c;一次成功&#xff0c;一次失败。在本篇博文中&#xff0c;我将探讨这个问题的原因&#xff0c;并提供解决方法。 我是在表…

创作一周年纪念日【道阻且长,行则将至】

✨个人主页&#xff1a; 北 海 &#x1f389;所属专栏&#xff1a; 技术之外的往事 &#x1f383;所处时段&#xff1a; 大学生涯[1/2] 文章目录 一、起点一切皆有定数 二、成果尽心、尽力 三、相遇孤举者难起&#xff0c;众行者易趋 四、未来长风破浪会有时&#xff0c;直挂云…

markdown2html 转化流程

定义一个extensions function markedMention() {return {extensions: [{name: mention,level: inline,start(src) {// console.log("markedMention start....", src);return src.indexOf(#)},tokenizer(src, tokens) {const rule /^(#[a-zA-Z0-9])\s?/const match…

JMeter websocket接口测试

前言 在一个网站中&#xff0c;很多数据需要即时更新&#xff0c;比如期货交易类的用户资产。在以前&#xff0c;这种功能的实现一般使用http轮询&#xff0c;即客户端用定时任务每隔一段时间向服务器发送查询请求来获取最新值。这种方式的弊端显而易见&#xff1a; 有可能造…

解决Gson解析json字符串,Integer变为Double类型的问题

直接上代码记录下。我代码里没有Gson包&#xff0c;用的是nacos对Gson的封装&#xff0c;只是包不同&#xff0c;方法都一样 import com.alibaba.nacos.shaded.com.google.common.reflect.TypeToken; import com.alibaba.nacos.shaded.com.google.gson.*;import java.util.Map;…

idea-控制台输出乱码问题

idea-控制台输出乱码问题 现象描述&#xff1a; 今天在进行IDEA开发WEB工程调式的时候控制台日志输出了乱码&#xff0c;如下截图 其实开发者大多都知道乱码是 编码不一致导致的&#xff0c;但是有时候就是不知到哪些地方不一致&#xff0c;今天我碰到的情况可能和你的不相同…

前端框架Layui实现动态表格效果用户管理实例(对表格进行CRUD操作-附源码)

目录 一、前言 1.什么是表格 2.表格的使用范围 二、案例实现 1.案例分析 ①根据需求找到文档源码 ②查询结果在实体中没有该属性 2.dao层编写 ①BaseDao工具类 ②UserDao编写 3.Servlet编写 ①R工具类的介绍 ②Useraction编写 4.jsp页面搭建 ①userManage.jsp ②…

Docker基础——初识Docker

Docker架构 Docker 使用客户端-服务器 (C/S) 架构模式&#xff0c;使用远程API来管理和创建Docker容器。 Docker 客户端(Client) : Docker 客户端通过命令行或者其他工具使用 Docker SDK (https://docs.docker.com/develop/sdk/) 与 Docker 的守护进程通信。Docker 主机(Host…