SpringBoot 监控神器——Actuator 保姆级教程

这篇具有很好参考价值的文章主要介绍了SpringBoot 监控神器——Actuator 保姆级教程。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

  • pom.xml

  • info

  • beans

  • conditions

  • heapdump

  • shutdown

  • mappings

  • threaddump

  • loggers 端点

  • metrics 端点

  • 自定义Endpoint

  • 自定义监控端点常用注解

  • 使用Filter对访问actuator做限制

  • Spring Boot Monitor做监控页面


SpringBoot自带监控功能Actuator,可以帮助实现对程序内部运行情况监控,比如监控状况、Bean加载情况、环境变量、日志信息、线程信息等

配置Actuator

pom.xml

<!-- web start-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- web end-->
<!-- actuator start-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- actuator end-->

浏览器打开链接http://localhost:8080/actuator/

可以看到所有支持的连接,默认只有

/actuator
/actuator/health
/actuator/health/{component}
/actuator/health/{component}/{instance}
/actuator/info

bean加载情况http://localhost:8080/actuator/beans

具体的使用方法:

  • 引入上述的依赖jar

通过下面的配置启用所有的监控端点,默认情况下,这些端点是禁用的;

management:
  endpoints:
    web:
      exposure:
        include: "*"

“*”号代表启用所有的监控端点,可以单独启用,例如,healthinfometrics

Actuator 的 REST 接口

Actuator 监控分成两类:原生端点和用户自定义端点;自定义端点主要是指扩展性,用户可以根据自己的实际应用,定义一些比较关心的指标,在运行期进行监控。

原生端点是在应用程序里提供众多 Web 接口,通过它们了解应用程序运行时的内部状况。原生端点又可以分成三类:

  • 应用配置类 :可以查看应用在运行期的静态信息:例如自动配置信息、加载的 springbean 信息、yml 文件配置信息、环境信息、请求映射信息;

  • 度量指标类 :主要是运行期的动态信息,例如堆栈、请求连、一些健康指标、metrics 信息等;

  • 操作控制类 :主要是指 shutdown,用户可以发送一个请求将应用的监控功能关闭。

Actuator 提供了 13 个接口,具体如下表所示。

GET /auditevents 显示应用暴露的审计事件 (比如认证进入、订单失败)
GET /beans 描述应用程序上下文里全部的 Bean,以及它们的关系
GET /conditions 就是 1.0 的 /autoconfig ,提供一份自动配置生效的条件情况,记录哪些自动配置条件通过了,哪些没通过
GET /configprops 描述配置属性(包含默认值)如何注入Bean
GET /env 获取全部环境属性
GET /env/{name} 根据名称获取特定的环境属性值
GET /flyway 提供一份 Flyway 数据库迁移信息
GET /liquidbase 显示Liquibase 数据库迁移的纤细信息
GET /health 报告应用程序的健康指标,这些值由 HealthIndicator 的实现类提供
GET /heapdump dump 一份应用的 JVM 堆信息
GET /httptrace 显示HTTP足迹,最近100个HTTP request/repsponse
GET /info 获取应用程序的定制信息,这些信息由info打头的属性提供
GET /logfile 返回log file中的内容(如果 logging.file 或者 logging.path 被设置)
GET /loggers 显示和修改配置的loggers
GET /metrics 报告各种应用程序度量信息,比如内存用量和HTTP请求计数
GET /metrics/{name} 报告指定名称的应用程序度量值
GET /scheduledtasks 展示应用中的定时任务信息
GET /sessions 如果我们使用了 Spring Session 展示应用中的 HTTP sessions 信息
POST /shutdown 关闭应用程序,要求endpoints.shutdown.enabled设置为true
GET /mappings 描述全部的 URI路径,以及它们和控制器(包含Actuator端点)的映射关系
GET /threaddump 获取线程活动的快照

命令详解

在 Spring Boot 2.x 中为了安全期间,Actuator 只开放了两个端点 /actuator/health 和 /actuator/info。可以在配置文件中设置打开。

可以打开所有的监控点

management:
  endpoints:
    web:
      exposure:
        include: "*"

也可以选择打开部分

management:
  endpoints:
    web:
      exposure:
        exclude: beans,trace

Actuator 默认所有的监控点路径都在/actuator/*,当然如果有需要这个路径也支持定制。

management:
  endpoints:
    web:
      base-path: /manage #记得要加上/

设置完重启后,再次访问地址就会变成/manage/*

Actuator 几乎监控了应用涉及的方方面面,我们重点讲述一些经常在项目中常用的命令。

  • health

health 主要用来检查应用的运行状态,这是我们使用最高频的一个监控点。通常使用此接口提醒我们应用实例的运行状态,以及应用不”健康“的原因,比如数据库连接、磁盘空间不够等。

默认情况下 health 的状态是开放的,添加依赖后启动项目,访问:http://localhost:8080/actuator/health即可看到应用的状态。

{
    "status" : "UP"
}

要想查看详细的应用健康信息需要配置management.endpoint.health.show-details 的值为always,配置之后我们再次访问http://localhost:8080/actuator/health,获取的信息如下:

{
    "status": "UP",
    "components": {
        "diskSpace": {
            "status": "UP",
            "details": {
                "total": 236510507008,
                "free": 223361744896,
                "threshold": 10485760
            }
        },
        "ping": {
            "status": "UP"
        }
    }
}

Spring boot的健康信息都是从ApplicationContext中的各种HealthIndicator Beans中收集到的,Spring boot框架中包含了大量的HealthIndicators的实现类,当然你也可以实现自己认为的健康状态。

默认情况下,最终的 Spring Boot 应用的状态是由 HealthAggregator 汇总而成的,汇总的算法是:

  1. 设置状态码顺序:setStatusOrder(Status.DOWN, Status.OUT_OF_SERVICE, Status.UP, Status.UNKNOWN);

  2. 过滤掉不能识别的状态码。

  3. 如果无任何状态码,整个 Spring Boot 应用的状态是 UNKNOWN

  4. 将所有收集到的状态码按照 1 中的顺序排序。

  5. 返回有序状态码序列中的第一个状态码,作为整个 Spring Boot 应用的状态。

health 通过合并几个健康指数检查应用的健康情况。Spring boot框架自带的 HealthIndicators 目前包括:

CassandraHealthIndicator Checks that a Cassandra database is up.
DiskSpaceHealthIndicator Checks for low disk space.
DataSourceHealthIndicator Checks that a connection to DataSource can be obtained.
ElasticsearchHealthIndicator Checks that an Elasticsearch cluster is up.
InfluxDbHealthIndicator Checks that an InfluxDB server is up.
JmsHealthIndicator Checks that a JMS broker is up.
MailHealthIndicator Checks that a mail server is up.
MongoHealthIndicator Checks that a Mongo database is up.
Neo4jHealthIndicator Checks that a Neo4j server is up.
RabbitHealthIndicator Checks that a Neo4j server is up.
RedisHealthIndicator Checks that a Redis server is up.
SolrHealthIndicator Checks that a Solr server is up.

举个例子,如果你的应用使用 Redis,RedisHealthindicator 将被当作检查的一部分;如果使用 MongoDB,那么MongoHealthIndicator 将被当作检查的一部分。

可以在配置文件中关闭特定的健康检查指标,比如关闭 redis 的健康检查:

management:
  health:
    redise:
      enabled: false

默认,所有的这些健康指标被当作健康检查的一部分。

  • 自定义 HealthIndicator 健康检查

有时候需要提供自定义的健康状态检查信息,你可以通过实现HealthIndicator的接口来实现,并将该实现类注册为spring bean。你需要实现其中的health()方法,并返回自定义的健康状态响应信息,该响应信息应该包括一个状态码和要展示详细信息。例如,下面就是一个接口HealthIndicator的实现类:

@Component
public class MyHealthIndicator implements HealthIndicator {

    @Override
    public Health health() {
        int errorCode = check(); // perform some specific health check
        if (errorCode != 0) {
            return Health.down().withDetail("Error Code", errorCode).build();
        }
        return Health.up().build();
    }

}

另外,除了Spring boot定义的几个状态类型,我们也可以自定义状态类型,用来表示一个新的系统状态。在这种情况下,你还需要实现接口 HealthAggregator ,或者通过配置 management.health.status.order 来继续使用HealthAggregator的默认实现。

例如,在你自定义的健康检查HealthIndicator的实现类中,使用了自定义的状态类型FATAL,为了配置该状态类型的严重程度,你需要在application的配置文件中添加如下配置:

management:
  health:
    status:
      order: FATAL, DOWN, OUT_OF_SERVICE, UNKNOWN, UP

在做健康检查时,响应中的HTTP状态码反应了整体的健康状态,(例如,UP 对应 200, 而 OUT_OF_SERVICE 和 DOWN 对应 503)。同样,你也需要为自定义的状态类型设置对应的HTTP状态码,例如,下面的配置可以将 FATAL 映射为 503(服务不可用):

management:
  health:
    status:
      http-mapping:
        FATAL: 503

下面是内置健康状态类型对应的HTTP状态码列表:

Status Mapping
OUT_OF_SERVICE SERVICE_UNAVAILABLE (503)
DOWN SERVICE_UNAVAILABLE (503)
UP No mapping by default, so http status is 200
UNKNOWN No mapping by default, so http status is 200

info

info 就是我们自己配置在配置文件中以 info 开头的配置信息,比如我们在示例项目中的配置是:

info:
  app:
    name:
      spring-boot-actuator
    version: 1.0.0
    test: test

启动示例项目,访问:http://localhost:8080/actuator/info返回部分信息如下:

{
  "app": {
    "name": "spring-boot-actuator",
    "version": "1.0.0",
    "test":"test"
  }
}

beans

根据示例就可以看出,展示了 bean 的别名、类型、是否单例、类的地址、依赖等信息。

启动示例项目,访问:http://localhost:8080/actuator/beans返回部分信息如下:

[
  {
    "context": "application:8080:management",
    "parent": "application:8080",
    "beans": [
      {
        "bean": "embeddedServletContainerFactory",
        "aliases": [
          
        ],
        "scope": "singleton",
        "type": "org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory",
        "resource": "null",
        "dependencies": [
          
        ]
      },
      {
        "bean": "endpointWebMvcChildContextConfiguration",
        "aliases": [
          
        ],
        "scope": "singleton",
        "type": "org.springframework.boot.actuate.autoconfigure.EndpointWebMvcChildContextConfiguration$$EnhancerBySpringCGLIB$$a4a10f9d",
        "resource": "null",
        "dependencies": [
          
        ]
      }
  }
]

conditions

Spring Boot 的自动配置功能非常便利,但有时候也意味着出问题比较难找出具体的原因。使用 conditions 可以在应用运行时查看代码了某个配置在什么条件下生效,或者某个自动配置为什么没有生效。

启动示例项目,访问:http://localhost:8080/actuator/conditions返回部分信息如下:

{
    "positiveMatches": {
     "DevToolsDataSourceAutoConfiguration": {
            "notMatched": [
                {
                    "condition": "DevToolsDataSourceAutoConfiguration.DevToolsDataSourceCondition", 
                    "message": "DevTools DataSource Condition did not find a single DataSource bean"
                }
            ], 
            "matched": [ ]
        }, 
        "RemoteDevToolsAutoConfiguration": {
            "notMatched": [
                {
                    "condition": "OnPropertyCondition", 
                    "message": "@ConditionalOnProperty (spring.devtools.remote.secret) did not find property 'secret'"
                }
            ], 
            "matched": [
                {
                    "condition": "OnClassCondition", 
                    "message": "@ConditionalOnClass found required classes 'javax.servlet.Filter', 'org.springframework.http.server.ServerHttpRequest'; @ConditionalOnMissingClass did not find unwanted class"
                }
            ]
        }
    }
}

heapdump

返回一个 GZip 压缩的 JVM 堆 dump

启动示例项目,访问:http://localhost:8080/actuator/heapdump会自动生成一个 Jvm 的堆文件 heapdump,我们可以使用 JDK 自带的 Jvm 监控工具 VisualVM 打开此文件查看内存快照。类似如下图:

SpringBoot 监控神器——Actuator 保姆级教程,spring boot,后端,java

图片

shutdown

开启接口优雅关闭 Spring Boot 应用,要使用这个功能首先需要在配置文件中开启:

management:
  endpoint:
    shutdown:
      enabled: true

配置完成之后,启动示例项目,使用 curl 模拟 post 请求访问 shutdown 接口。

shutdown 接口默认只支持 post 请求。

curl -X POST "http://localhost:8080/actuator/shutdown" 
{
    "message": "Shutting down, bye..."
}

此时你会发现应用已经被关闭。

mappings

描述全部的 URI 路径,以及它们和控制器的映射关系

启动示例项目,访问:http://localhost:8080/actuator/mappings返回部分信息如下:

{
  "/**/favicon.ico": {
    "bean": "faviconHandlerMapping"
  },
  "{[/hello]}": {
    "bean": "requestMappingHandlerMapping",
    "method": "public java.lang.String com.neo.controller.HelloController.index()"
  },
  "{[/error]}": {
    "bean": "requestMappingHandlerMapping",
    "method": "public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)"
  }
}

threaddump

/threaddump 接口会生成当前线程活动的快照。这个功能非常好,方便我们在日常定位问题的时候查看线程的情况。 主要展示了线程名、线程ID、线程的状态、是否等待锁资源等信息。

启动示例项目,访问:http://localhost:8080/actuator/threaddump返回部分信息如下:

[
  {
    "threadName": "http-nio-8088-exec-6",
    "threadId": 49,
    "blockedTime": -1,
    "blockedCount": 0,
    "waitedTime": -1,
    "waitedCount": 2,
    "lockName": "java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject@1630a501",
    "lockOwnerId": -1,
    "lockOwnerName": null,
    "inNative": false,
    "suspended": false,
    "threadState": "WAITING",
    "stackTrace": [
      {
        "methodName": "park",
        "fileName": "Unsafe.java",
        "lineNumber": -2,
        "className": "sun.misc.Unsafe",
        "nativeMethod": true
      },
      ...
      {
        "methodName": "run",
        "fileName": "TaskThread.java",
        "lineNumber": 61,
        "className": "org.apache.tomcat.util.threads.TaskThread$WrappingRunnable",
        "nativeMethod": false
      }
      ...
    ],
    "lockInfo": {
      "className": "java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject",
      "identityHashCode": 372286721
    }
  }
  ...
]

生产出现问题的时候,可以通过应用的线程快照来检测应用正在执行的任务。

loggers 端点

访问 http://localhost:8080/actuator/loggers 可以查看当前应用的日志级别等信息:

SpringBoot 监控神器——Actuator 保姆级教程,spring boot,后端,java

图片

这里面本身并不特别,但是有一个功能却非常有用,比如我们生产环境日志级别一般都是 info,但是现在有一个 bug 通过 info 级别无法排查,那么我们就可以临时修改 log 级别。

比如上图中的 ROOT 节点是 info 级别,那么我们可以通过 postman 等工具来发一个 post 请求修改日志级别。

SpringBoot 监控神器——Actuator 保姆级教程,spring boot,后端,java

图片

修改之后就会发现,日志由原来的 info 变成了 debug:

SpringBoot 监控神器——Actuator 保姆级教程,spring boot,后端,java

图片

metrics 端点

metrics 是一个非常重要的监控端点,其监控内容覆盖了 JVM 内存、堆、类加载、处理器和 tomcat 容器等一些重要指标:

SpringBoot 监控神器——Actuator 保姆级教程,spring boot,后端,java

图片

可以看到这里面包含了非常多的指标,任意访问一个指标就可以查看对应的指标信息:

SpringBoot 监控神器——Actuator 保姆级教程,spring boot,后端,java

图片

自定义Endpoint

自定义配置来控制是否开启过滤

actuator:
  filter:
    switch: false

自定义监控端点常用注解

自定义一个监控端点主要有如下常用注解:

  • @Endpoint :定义一个监控端点,同时支持 HTTP 和 JMX 两种方式。

  • @WebEndpoint :定义一个监控端点,只支持 HTTP 方式。

  • @JmxEndpoint :定义一个监控端点,只支持 JMX 方式。

以上三个注解作用在类上,表示当前类是一个监控端点,另外还有一些注解会用在方法和参数上:

  • @ReadOperation :作用在方法上,可用来返回端点展示的信息(通过 Get 方法请求)。

  • @WriteOperation :作用在方法上,可用来修改端点展示的信息(通过 Post 方法请求)。

  • @DeleteOperation :作用在方法上,可用来删除对应端点信息(通过 Delete 方法请求)。

  • @Selector :作用在参数上,用来定位一个端点的具体指标路由。

一般情况下,是没必要自定义Endpoint的,但是也不排除特殊情况,我这里自定义一个Endpoint,用来往request里放一个user对象,这个user是用来做测试的,用于下面突破filter用的(下面再说),这里先说怎么增查这个user。

过程如下:

  • 使用@Endpoint注解相应的类,作为Actuator的一个endpoint。注解要指定id,这个id作为访问路径,比如这里是/actuator/super

  • @ReadOperation来注解查询接口,如果要根据路径做查询,要用@Selector注解方法参数;注意这地方是@Selector String arg0,这个arg0不能改变,改成其他的,开放出去的接口还是/{arg0},这就导致你的方法无法正常获取参数值。

  • @WriteOperation 来注解修改接口,注意请求数据必须是json,而且参数不像controller中那么灵活,不能将实体作为参数,要把实体中相应的属性拿出来做参数。

  • 这里在增加用户时,往request里放一个user对象。

SuperEndPoint :

package com.cff.springbootwork.actuator.endpoint;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import javax.servlet.http.HttpServletRequest;

import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.annotation.Selector;
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

@Endpoint(id = "super")
public class SuperEndPoint {
    private Map<String, SuperUser> users = new ConcurrentHashMap<>();

    @ReadOperation
    public Set<String> users() {
        return users.keySet();
    }

    @ReadOperation
    public SuperUser usersIdentify(@Selector String arg0) {
        return users.get(arg0);
    }

    @WriteOperation
    public Set<String> set(String userName, String passwd) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
                .getRequest();
        if (request != null) {
            SuperUser superUser = new SuperUser();
            superUser.setUserName(userName);
            superUser.setPasswd(passwd);
            request.getSession().setAttribute("superUser", superUser);

            users.put(superUser.getUserName(), superUser);
        }

        return users.keySet();
    }

    public static class SuperUser {
        private String userName;
        private String passwd;

        public String getUserName() {
            return userName;
        }

        public void setUserName(String userName) {
            this.userName = userName;
        }

        public String getPasswd() {
            return passwd;
        }

        public void setPasswd(String passwd) {
            this.passwd = passwd;
        }
    }
}

还要将Endpoint注册为bean

MvcEndPointConfig:

package com.cff.springbootwork.actuator;

import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.cff.springbootwork.actuator.endpoint.SuperEndPoint;

@Configuration
@ServletComponentScan 
public class MvcEndPointConfig {

    @Bean
    @ConditionalOnEnabledEndpoint
    public SuperEndPoint superEndPoint() {
        return new SuperEndPoint();
    }
}

使用Filter对访问actuator做限制

上面已经说了,actuator的接口要做保护,我这里就用filter对接口做最简单的保护。

  • /actuator/*下所有路径做过滤,并用actuator.filter.switch属性对filter做开关;

  • 如果时/actuator/super路径的post操作,放行它,它将会往request中放一个对象;

  • 其他/actuator/*下路径要判断request中有没有user对象,没有就返回错误提示。

ActuatorPermissionFilter :

package com.cff.springbootwork.actuator.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;

import com.fasterxml.jackson.databind.ObjectMapper;

@WebFilter(urlPatterns = "/actuator/*", filterName = "actuatorPermissionFilter")
@Order(1) // 指定过滤器的执行顺序,值越大越靠后执行
public class ActuatorPermissionFilter implements Filter {
    private String excludePath = "actuator/super";
    @Value("${actuator.filter.switch}")
    Boolean actuatorSwitch;

    @Override
    public void init(FilterConfig filterConfig) {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
            throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        if (actuatorSwitch && !(request.getRequestURI().endsWith(excludePath)
                && request.getMethod().equals(HttpMethod.POST.toString()))) {
            Object user = request.getSession().getAttribute("superUser");
            if (user == null) {
                // 未登录,返回数据
                ObjectMapper mapper = new ObjectMapper();
                response.setStatus(HttpStatus.OK.value());
                response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
                mapper.writeValue(response.getWriter(), "您没有权限访问该接口,请使用自定义的登录接口设置superUser后使用!");
                return;
            }
        }
        filterChain.doFilter(servletRequest, servletResponse);

    }

    @Override
    public void destroy() {
    }

}

Spring Boot Monitor做监控页面

额外引入依赖

<dependency>
    <groupId>cn.pomit</groupId>
    <artifactId>spring-boot-monitor</artifactId>
    <version>0.0.1</version>
</dependency>

Spring Boot Monitor是一个对Spring boot admin监控工具做修改并适配单机的监控工具,完美继承了Spring boot admin的风格,直接使用actuator的指标进行显示。

  • Spring Boot Monitor官网:https://www.pomit.cn/SpringBootMonitor

前面maven依赖中,已经说明依赖spring-boot-monitor,这时,无需其他配置.

访问http://127.0.0.1:8080/monitor, 自动跳转到Spring Boot Monitor的监控页面。

SpringBoot 监控神器——Actuator 保姆级教程,spring boot,后端,java

图片

Spring Boot Monitor的监控页面和Spring boot admin的一模一样,前端的功能也一模一样。

SpringBoot 监控神器——Actuator 保姆级教程,spring boot,后端,java

图片

可以对Spring boot的各项指标一目了然,还可以进行简单的操作。

当然,如果Spring boot actuator的指标被限制了,它也拿不到相应的指标了,因为它是直接请求actuator接口的。

 
 
 

 文章来源地址https://www.toymoban.com/news/detail-603815.html

 

 

 

 

到了这里,关于SpringBoot 监控神器——Actuator 保姆级教程的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

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

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

相关文章

  • 【监控】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)
  • springboot 整合 actuator监控详情

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

    2024年01月20日
    浏览(30)
  • Spring Boot 单元测试,保姆级教程!

    概念: 单元测试(unit testing),是指对软件中的最小可测试单元进行检查和验证。在Java中单元测试的最小单元是类。 单元测试是开发者编写的一小段代码,用于检验被测代码的一个很小的、很明确的功能是否正确。执行单元测试,就是为了证明这段代码的行为和我们期望是

    2024年02月03日
    浏览(36)
  • Spring Boot Actuator详解

    Spring Boot Actuator 模块提供了生产级别的功能,比如 健康检查 , 审计 , 指标收集 , HTTP跟踪 等,帮助我们监控和管理Spring Boot应用。 这个模块是一个采集应用内部信息暴露给外部的模块,上述的功能都可以通过HTTP和JMX访问。 因为暴露内部信息的特性,Actuator也可以和一些外

    2024年02月07日
    浏览(29)
  • spring boot actuator 禁用后,/actuator仍可正常访问

    项目上线后,被测试出actuator没有关闭,关闭后,仍可正常访问/actuator端点,只是类似/actuator/env这样的无法访问,现在就想把/actuator端点也给禁用了。 spring boot 2.x关闭actuator配置,关闭后,仍可正常访问/actuator端点 说明spring boot 2.x无法通过配置的方式禁用/actuator端点 大部分

    2024年01月19日
    浏览(29)
  • SpringBoot应用监控Actuator使用的安全隐患

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

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

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

    2024年04月16日
    浏览(24)
  • 关于Spring Boot Actuator漏洞补救方案

    在浏览器中范围于http://192.168.0.119:81/dev-api/actuator(http://IP:端口/actuator),如下图 几个漏洞属于配置不当引起路由暴露。 1.读取用户的认证字段获取敏感信息 可以直接尝试访问网站目录下的/trace 路径,读取用户认证字段信息,比如在trace 路径下,会有用户的敏感信息,可能

    2024年02月04日
    浏览(30)
  • Spring Boot Actuator未授权访问漏洞

    Spring Boot Actuator 端点的未授权访问漏洞是一个安全性问题,可能会导致未经授权的用户访问敏感的应用程序信息。 可是并不用太过担心,Spring Boot Actuator 默认暴漏的信息有限,一般情况下并不会暴露敏感数据。 注册中心有些功能集成了actuator,如果同时使用eureka和actuator,可

    2024年02月13日
    浏览(30)
  • Spring Boot中的Actuator是什么?Spring Boot中的Starter依赖是什么?

    在Spring Boot中,Actuator是一种用于监控和管理应用程序的工具。它提供了一些额外的端点和功能,使开发人员能够更好地了解和控制他们的应用程序。 Actuator提供了以下功能: 指标收集:Actuator可以收集并显示有关应用程序的指标,例如内存使用情况、线程数、请求处理时间等

    2024年02月09日
    浏览(34)

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

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

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

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

二维码1

领取红包

二维码2

领红包