Spring Boot 2.2.X Actuator 用不了 HttpTrace 和 Tomcat Thread 解决方案

一、前言

spring boot 2.2.x release note 说明:

1.1 HttpTrace:

由于Spring Boot Actuator使用HttpTrace消耗资源并不支持集群,在Spring Boot 2.2 Release Notes开始已经默认禁用了,要启用HTTP跟踪,实现HttpTraceRepository或AuditEventRepository重新打开这些功能。

1.2 Tomcat Thread:

Spring Boot 2.2 Release Notes开始已经默认禁用了,从而节省了大约2MB的堆。

二、解决方案

2.1 HttpTrace:

a. 了解下 Spring Cloud Sleuth + Zipkin OR Skywalking
b. 要启用HTTP跟踪,实现HttpTraceRepository或AuditEventRepository重新打开这些功能。(PS:但是消耗资源并不支持集群)

import org.springframework.boot.actuate.autoconfigure.trace.http.HttpTraceAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.trace.http.HttpTraceProperties;
import org.springframework.boot.actuate.trace.http.HttpTrace;
import org.springframework.boot.actuate.trace.http.HttpTraceRepository;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

@Configuration
@ConditionalOnWebApplication
@ConditionalOnProperty(prefix = "management.trace.http", name = "enabled", matchIfMissing = true)
@EnableConfigurationProperties(HttpTraceProperties.class)
@AutoConfigureBefore(HttpTraceAutoConfiguration.class)
class TraceConfig {
    private List<HttpTrace> list = new CopyOnWriteArrayList<HttpTrace>();

    @Bean
    @ConditionalOnMissingBean(HttpTraceRepository.class)
    public HttpTraceRepository traceRepository() {
        return new HttpTraceRepository() {
            @Override
            public List<HttpTrace> findAll() {
                return list;
            }

            @Override
            public void add(HttpTrace trace) {
                if (list.size() > 99){
                    list.remove(0);
                }
                list.add(trace);
            }
        };
    }
}


2.2 Tomcat Thread :

server:
  tomcat:
    mbeanregistry:
      enabled: true
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值