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

这篇具有很好参考价值的文章主要介绍了SpringBoot+actuator和admin-UI实现监控中心。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

使用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

启动之后

SpringBoot+actuator和admin-UI实现监控中心,SpringBoot+Demo,spring boot,后端,actuator,admin-ui
访问

http://localhost:8081/sys/actuator

SpringBoot+actuator和admin-UI实现监控中心,SpringBoot+Demo,spring boot,后端,actuator,admin-ui
在这里使用的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

SpringBoot+actuator和admin-UI实现监控中心,SpringBoot+Demo,spring boot,后端,actuator,admin-ui
使用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=8071

spring.application.name=boot-example-admin-client

spring.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-server

spring.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();
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // 跨域设置,SpringBootAdmin客户端通过instances注册,见InstancesController
        http.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-ui
        http.formLogin().loginPage("/login").permitAll();
        http.logout().logoutUrl("/logout").logoutSuccessUrl("/login");

        // 启用basic认证,SpringBootAdmin客户端使用的是basic认证
        http.httpBasic();
    }
}

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

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

SpringBoot+actuator和admin-UI实现监控中心,SpringBoot+Demo,spring boot,后端,actuator,admin-ui
SpringBoot+actuator和admin-UI实现监控中心,SpringBoot+Demo,spring boot,后端,actuator,admin-ui
SpringBoot+actuator和admin-UI实现监控中心,SpringBoot+Demo,spring boot,后端,actuator,admin-ui
记录一下在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=8071

spring.application.name=boot-example-admin-client1

spring.boot.admin.client.url=http://localhost:8050
spring.boot.admin.client.username=admin
spring.boot.admin.client.password=123456

management.endpoint.health.show-details=always
management.endpoints.web.exposure.include=*


application.properties 2



server.port=8072

spring.application.name=boot-example-admin-client2

spring.boot.admin.client.url=http://localhost:8050
spring.boot.admin.client.username=admin
spring.boot.admin.client.password=123456

management.server.port=8082
management.server.base-path = /sys
management.endpoint.health.show-details=always
management.endpoints.web.exposure.include=*

application.properties 3



server.port=8073

spring.application.name=boot-example-admin-client3

spring.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=123456

management.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=8050

spring.application.name=boot-example-admin-server

spring.security.user.name=admin
spring.security.user.password=123456


备注记录到这里 将来会不会用到再说了。文章来源地址https://www.toymoban.com/news/detail-630290.html

到了这里,关于SpringBoot+actuator和admin-UI实现监控中心的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Springboot Actuator监控

    官网连接: Spring Boot Reference Documentation Spring Boot包括许多附加功能,帮助您在将应用程序推向生产时监视和管理应用程序。您可以选择使用HTTP端点或JMX来管理和监视应用程序。 审计,健康和指标收集 也可以自动应用于应用程序。 spring-boot-actuator 模块提供所有Spring Boot的生产

    2024年02月02日
    浏览(31)
  • springboot 整合 actuator监控详情

    SpringBoot自带监控功能Actuator,可以帮助实现对程序内部运行情况监控,比如监控状况、Bean加载情况、环境变量、日志信息、线程信息等 pom文件中添加 yaml文件 监控端口必须单独配置,否则请求不到 启动项目,请求接口:http:/localhost:8092/actuator 返回的是可以查看的所有接口

    2024年01月20日
    浏览(30)
  • SpringBoot 监控神器——Actuator 保姆级教程

    pom.xml info beans conditions heapdump shutdown mappings threaddump loggers 端点 metrics 端点 自定义Endpoint 自定义监控端点常用注解 使用Filter对访问actuator做限制 Spring Boot Monitor做监控页面 SpringBoot自带监控功能Actuator,可以帮助实现对程序内部运行情况监控,比如监控状况、Bean加载情况、环境

    2024年02月16日
    浏览(35)
  • SpringBoot应用监控Actuator使用的安全隐患

    Actuator 是 springboot 提供的用来对应用系统进行自省和监控的功能模块,借助于 Actuator 开发者可以很方便地对应用系统某些监控指标进行查看、统计等。在 Actuator 启用的情况下,如果没有做好相关权限控制,非法用户可通过访问默认的执行器端点(endpoints)来获取应用系统中

    2024年02月05日
    浏览(33)
  • 【SpringBoot系列】- 四大核心之actuator(程序监控器)

    应用系统在开发完成以后,就投入实际生产中运营。在软件运行时,整个软件一个黑盒,如何在整个生命周期中准确的知道应用程序运行的健康状况,服务使用状态?我们需要对应用程序进行监控,从而了解应用的运行状态,并根据情况决定是否需要对其运行状态进行调整。

    2024年02月15日
    浏览(32)
  • dubbo监控中心dubbo-admin老版本(dubbo-ops)使用

    1、dubbo分组 在dubbo中,可以指定group,如下: 使用properties如下: group分组的作用: 在服务器资源紧缺的情况下,group可以用来隔离开发环境和测试环境:同一个服务不同的版本可以在相同的注册中心中注册,根据group来隔离不同版本之间的影响 如: 项目开发环境: dubbo.reg

    2024年02月12日
    浏览(34)
  • 服务监控平台:SpringBoot Admin入门应用

    在日常工作中,我们需要有一款监控平台来帮助我们管理服务,监控服务是否宕机、服务运行指标(内存、虚拟机、线程、请求等)、监控日志、管理服务(服务下线)等,SpringBoot Admin作为一款开源的监控平台,开发对接方便,只需要配置好服务和监控信息,定时拉取即可。

    2024年02月12日
    浏览(30)
  • spring boot admin搭建,监控springboot程序运行状况

    新建一个spring boot web项目,添加以下依赖 spring boot的监控端点依赖必须的。 关于版本,springboot的版本前两位是什么,上面依赖的版本就对应什么版本,比如现在spring boot parent的版本是2.3.5,这里的依赖可以选择2.3开头的版本。下面是开启相关的端点功能 添加以上依赖之后,

    2024年04月16日
    浏览(24)
  • PromQL实现Actuator获取的JVM指标的Full GC次数监控

    Spring Boot 版本需要2.0.0或更高版本。 添加Micrometer Prometheus registry依赖: 在application.properties中开启prometheus端点: 做完上述配置后,Actuator就可以通过Micrometer获取到JVM的GC指标,其中包括: jvm_gc_memory_promoted_bytes_total:记录New Generation晋升到Old Generation的内存大小总和。反映对象存活率。

    2024年02月13日
    浏览(62)
  • 【监控】spring actuator源码速读

    目录 1.前言 2.先搂一眼EndPoint 3.EndPoint如何被注入 4.EndPoint如何被暴露 4.1.如何通过http暴露 4.2.如何通过jmx暴露 5.EndPoint是怎么实现监控能力的 6.知道这些的意义是什么 版本:spring-boot-starter-actuator  2.6.3 阅读源码一定要带着疑问去阅读,这个疑问就是你阅读的主线,不然在浩如

    2024年02月19日
    浏览(28)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包