refactor the monitor logic.

pull/1382/head
yanrongzhen 2 years ago
parent 4e06e1ab63
commit 1e003aa074

@ -23,28 +23,15 @@ import cn.hippo4j.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import cn.hippo4j.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; import cn.hippo4j.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
import cn.hippo4j.agent.core.plugin.interceptor.enhance.MethodInterceptResult; import cn.hippo4j.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
import cn.hippo4j.agent.plugin.spring.boot.v2.DynamicThreadPoolChangeHandlerSpring2x; import cn.hippo4j.agent.plugin.spring.boot.v2.DynamicThreadPoolChangeHandlerSpring2x;
import cn.hippo4j.agent.plugin.spring.common.conf.SpringBootConfig;
import cn.hippo4j.agent.plugin.spring.common.support.SpringPropertiesLoader; import cn.hippo4j.agent.plugin.spring.common.support.SpringPropertiesLoader;
import cn.hippo4j.agent.plugin.spring.common.support.SpringThreadPoolRegisterSupport; import cn.hippo4j.agent.plugin.spring.common.support.SpringThreadPoolRegisterSupport;
import cn.hippo4j.common.executor.ThreadFactoryBuilder;
import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry;
import cn.hippo4j.common.extension.design.AbstractSubjectCenter; import cn.hippo4j.common.extension.design.AbstractSubjectCenter;
import cn.hippo4j.common.extension.spi.ServiceLoaderRegistry;
import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.threadpool.dynamic.api.ThreadPoolDynamicRefresh; import cn.hippo4j.threadpool.dynamic.api.ThreadPoolDynamicRefresh;
import cn.hippo4j.threadpool.dynamic.mode.config.refresher.event.DynamicThreadPoolRefreshListener; import cn.hippo4j.threadpool.dynamic.mode.config.refresher.event.DynamicThreadPoolRefreshListener;
import cn.hippo4j.threadpool.monitor.api.DynamicThreadPoolMonitor;
import cn.hippo4j.threadpool.monitor.api.ThreadPoolMonitor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/** /**
* Event publishing started interceptor * Event publishing started interceptor
@ -65,7 +52,6 @@ public class EventPublishingStartedInterceptor implements InstanceMethodsAroundI
if (context.getParent() != null) { if (context.getParent() != null) {
// After the child container is started, the thread pool registration will be carried out // After the child container is started, the thread pool registration will be carried out
SpringThreadPoolRegisterSupport.registerThreadPoolInstances(context); SpringThreadPoolRegisterSupport.registerThreadPoolInstances(context);
// registerMonitor(context);
return ret; return ret;
} }
SpringPropertiesLoader.loadSpringProperties(context.getEnvironment()); SpringPropertiesLoader.loadSpringProperties(context.getEnvironment());
@ -81,42 +67,4 @@ public class EventPublishingStartedInterceptor implements InstanceMethodsAroundI
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t) { public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t) {
} }
private void registerMonitor(ConfigurableApplicationContext context) {
if (!SpringBootConfig.Spring.Dynamic.Thread_Pool.Monitor.enable
|| StringUtil.isBlank(SpringBootConfig.Spring.Dynamic.Thread_Pool.Monitor.threadPoolTypes)
|| StringUtil.isBlank(SpringBootConfig.Spring.Dynamic.Thread_Pool.Monitor.collectTypes)) {
return;
}
log.info("Start monitoring the running status of dynamic thread pool.");
List<ThreadPoolMonitor> threadPoolMonitors = new ArrayList<>();
ScheduledThreadPoolExecutor collectScheduledExecutor = new ScheduledThreadPoolExecutor(
1,
ThreadFactoryBuilder.builder().daemon(true).prefix("client.scheduled.collect.data").build());
// Get dynamic thread pool monitoring component.
List<String> collectTypes = Arrays.asList(SpringBootConfig.Spring.Dynamic.Thread_Pool.Monitor.collectTypes.split(","));
context.getBeansOfType(ThreadPoolMonitor.class).forEach((beanName, bean) -> threadPoolMonitors.add(bean));
Collection<DynamicThreadPoolMonitor> dynamicThreadPoolMonitors =
ServiceLoaderRegistry.getSingletonServiceInstances(DynamicThreadPoolMonitor.class);
dynamicThreadPoolMonitors.stream().filter(each -> collectTypes.contains(each.getType())).forEach(each -> threadPoolMonitors.add(each));
// Execute dynamic thread pool monitoring component.
collectScheduledExecutor.scheduleWithFixedDelay(
() -> scheduleRunnable(threadPoolMonitors),
SpringBootConfig.Spring.Dynamic.Thread_Pool.Monitor.initialDelay,
SpringBootConfig.Spring.Dynamic.Thread_Pool.Monitor.collectInterval,
TimeUnit.MILLISECONDS);
if (ThreadPoolExecutorRegistry.getThreadPoolExecutorSize() > 0) {
log.info("Dynamic thread pool: [{}]. The dynamic thread pool starts data collection and reporting.", ThreadPoolExecutorRegistry.getThreadPoolExecutorSize());
}
}
public void scheduleRunnable(List<ThreadPoolMonitor> threadPoolMonitors) {
for (ThreadPoolMonitor each : threadPoolMonitors) {
try {
each.collect();
} catch (Exception ex) {
log.error("Error monitoring the running status of dynamic thread pool. Type: {}", each.getType(), ex);
}
}
}
} }

@ -20,13 +20,19 @@ package cn.hippo4j.springboot.starter.adapter.web;
import cn.hippo4j.adapter.web.WebThreadPoolHandlerChoose; import cn.hippo4j.adapter.web.WebThreadPoolHandlerChoose;
import cn.hippo4j.adapter.web.WebThreadPoolRunStateHandler; import cn.hippo4j.adapter.web.WebThreadPoolRunStateHandler;
import cn.hippo4j.core.config.ApplicationContextHolder; import cn.hippo4j.core.config.ApplicationContextHolder;
import cn.hippo4j.core.config.UtilAutoConfiguration;
import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler; import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler;
import cn.hippo4j.core.toolkit.inet.InetUtils; import cn.hippo4j.core.toolkit.inet.InetUtils;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.ConfigurableEnvironment;
/** /**
@ -37,6 +43,7 @@ import org.springframework.core.env.ConfigurableEnvironment;
WebThreadPoolHandlerConfiguration.EmbeddedJetty.class, WebThreadPoolHandlerConfiguration.EmbeddedJetty.class,
WebThreadPoolHandlerConfiguration.EmbeddedUndertow.class}) WebThreadPoolHandlerConfiguration.EmbeddedUndertow.class})
@RequiredArgsConstructor @RequiredArgsConstructor
@AutoConfigureAfter(UtilAutoConfiguration.class)
public class WebAdapterConfiguration { public class WebAdapterConfiguration {
private final ConfigurableEnvironment environment; private final ConfigurableEnvironment environment;

@ -0,0 +1 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.hippo4j.springboot.starter.adapter.web.WebAdapterConfiguration

@ -38,6 +38,7 @@ import org.springframework.context.annotation.Configuration;
* Config handler configuration. * Config handler configuration.
*/ */
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, value = "enable", matchIfMissing = true, havingValue = "true")
public class ConfigHandlerConfiguration { public class ConfigHandlerConfiguration {
private static final String NACOS_CONFIG_MANAGER_KEY = "com.alibaba.cloud.nacos.NacosConfigManager"; private static final String NACOS_CONFIG_MANAGER_KEY = "com.alibaba.cloud.nacos.NacosConfigManager";

@ -19,7 +19,6 @@ package cn.hippo4j.config.springboot.starter.config;
import cn.hippo4j.adapter.web.WebThreadPoolService; import cn.hippo4j.adapter.web.WebThreadPoolService;
import cn.hippo4j.common.toolkit.StringUtil; import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.config.springboot.starter.monitor.ThreadPoolMonitorExecutor;
import cn.hippo4j.config.springboot.starter.notify.ConfigModeNotifyConfigBuilder; import cn.hippo4j.config.springboot.starter.notify.ConfigModeNotifyConfigBuilder;
import cn.hippo4j.config.springboot.starter.refresher.event.AdapterExecutorsRefreshListener; import cn.hippo4j.config.springboot.starter.refresher.event.AdapterExecutorsRefreshListener;
import cn.hippo4j.config.springboot.starter.refresher.event.DynamicThreadPoolRefreshListener; import cn.hippo4j.config.springboot.starter.refresher.event.DynamicThreadPoolRefreshListener;
@ -70,10 +69,9 @@ import org.springframework.core.annotation.Order;
@Configuration @Configuration
@AllArgsConstructor @AllArgsConstructor
@ConditionalOnBean(MarkerConfiguration.Marker.class) @ConditionalOnBean(MarkerConfiguration.Marker.class)
@ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, value = "enable", matchIfMissing = true, havingValue = "true")
@EnableConfigurationProperties(SpringBootstrapConfigProperties.class) @EnableConfigurationProperties(SpringBootstrapConfigProperties.class)
@Import(ConfigHandlerConfiguration.class) @Import(ConfigHandlerConfiguration.class)
@ImportAutoConfiguration({WebAdapterConfiguration.class, UtilAutoConfiguration.class, MessageConfiguration.class}) @ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, value = "enable", matchIfMissing = true, havingValue = "true")
public class DynamicThreadPoolAutoConfiguration { public class DynamicThreadPoolAutoConfiguration {
private final BootstrapConfigProperties bootstrapConfigProperties; private final BootstrapConfigProperties bootstrapConfigProperties;
@ -114,15 +112,10 @@ public class DynamicThreadPoolAutoConfiguration {
} }
@Bean @Bean
public DynamicThreadPoolPostProcessor dynamicThreadPoolPostProcessor(ApplicationContextHolder hippo4jApplicationContextHolder) { public DynamicThreadPoolPostProcessor dynamicThreadPoolPostProcessor() {
return new DynamicThreadPoolPostProcessor(bootstrapConfigProperties); return new DynamicThreadPoolPostProcessor(bootstrapConfigProperties);
} }
@Bean
public ThreadPoolMonitorExecutor hippo4jDynamicThreadPoolMonitorExecutor() {
return new ThreadPoolMonitorExecutor(bootstrapConfigProperties);
}
@Bean @Bean
@SuppressWarnings("all") @SuppressWarnings("all")
public DynamicThreadPoolRefreshListener hippo4jExecutorsListener(DefaultThreadPoolConfigChangeHandler threadPoolConfigChange, public DynamicThreadPoolRefreshListener hippo4jExecutorsListener(DefaultThreadPoolConfigChangeHandler threadPoolConfigChange,

@ -0,0 +1,41 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.hippo4j.config.springboot.starter.config;
import cn.hippo4j.config.springboot.starter.monitor.ThreadPoolMonitorExecutor;
import cn.hippo4j.core.enable.MarkerConfiguration;
import cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@AllArgsConstructor
@EnableConfigurationProperties(SpringBootstrapConfigProperties.class)
public class MonitorConfiguration {
private final BootstrapConfigProperties bootstrapConfigProperties;
@Bean
public ThreadPoolMonitorExecutor hippo4jDynamicThreadPoolMonitorExecutor() {
return new ThreadPoolMonitorExecutor(bootstrapConfigProperties);
}
}

@ -1 +1,5 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.hippo4j.config.springboot.starter.config.DynamicThreadPoolAutoConfiguration org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.hippo4j.config.springboot.starter.config.DynamicThreadPoolAutoConfiguration,\
cn.hippo4j.core.config.UtilAutoConfiguration,\
cn.hippo4j.message.config.MessageConfiguration,\
cn.hippo4j.springboot.starter.adapter.web.WebAdapterConfiguration,\
cn.hippo4j.config.springboot.starter.config.MonitorConfiguration

@ -18,6 +18,7 @@
package cn.hippo4j.springboot.starter.monitor.elasticsearch; package cn.hippo4j.springboot.starter.monitor.elasticsearch;
import cn.hippo4j.common.constant.Constants; import cn.hippo4j.common.constant.Constants;
import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler;
import cn.hippo4j.monitor.elasticsearch.AdapterThreadPoolElasticSearchMonitorHandler; import cn.hippo4j.monitor.elasticsearch.AdapterThreadPoolElasticSearchMonitorHandler;
import cn.hippo4j.monitor.elasticsearch.DynamicThreadPoolElasticSearchMonitorHandler; import cn.hippo4j.monitor.elasticsearch.DynamicThreadPoolElasticSearchMonitorHandler;
import cn.hippo4j.monitor.elasticsearch.WebThreadPoolElasticSearchMonitorHandler; import cn.hippo4j.monitor.elasticsearch.WebThreadPoolElasticSearchMonitorHandler;
@ -36,19 +37,19 @@ public class ElasticSearchMonitorAutoConfiguration {
@Bean @Bean
@ConditionalOnExpression("'${spring.dynamic.thread-pool.monitor.thread-pool-types:}'.contains('dynamic')") @ConditionalOnExpression("'${spring.dynamic.thread-pool.monitor.thread-pool-types:}'.contains('dynamic')")
public DynamicThreadPoolElasticSearchMonitorHandler dynamicThreadPoolElasticSearchMonitorHandler() { public DynamicThreadPoolElasticSearchMonitorHandler dynamicThreadPoolElasticSearchMonitorHandler(ThreadPoolRunStateHandler handler) {
return new DynamicThreadPoolElasticSearchMonitorHandler(); return new DynamicThreadPoolElasticSearchMonitorHandler(handler);
} }
@Bean @Bean
@ConditionalOnExpression("'${spring.dynamic.thread-pool.monitor.thread-pool-types:}'.contains('web')") @ConditionalOnExpression("'${spring.dynamic.thread-pool.monitor.thread-pool-types:}'.contains('web')")
public WebThreadPoolElasticSearchMonitorHandler webThreadPoolElasticSearchMonitorHandler() { public WebThreadPoolElasticSearchMonitorHandler webThreadPoolElasticSearchMonitorHandler(ThreadPoolRunStateHandler handler) {
return new WebThreadPoolElasticSearchMonitorHandler(); return new WebThreadPoolElasticSearchMonitorHandler(handler);
} }
@Bean @Bean
@ConditionalOnExpression("'${spring.dynamic.thread-pool.monitor.thread-pool-types:}'.contains('adapter')") @ConditionalOnExpression("'${spring.dynamic.thread-pool.monitor.thread-pool-types:}'.contains('adapter')")
public AdapterThreadPoolElasticSearchMonitorHandler adapterThreadPoolElasticSearchMonitorHandler() { public AdapterThreadPoolElasticSearchMonitorHandler adapterThreadPoolElasticSearchMonitorHandler(ThreadPoolRunStateHandler handler) {
return new AdapterThreadPoolElasticSearchMonitorHandler(); return new AdapterThreadPoolElasticSearchMonitorHandler(handler);
} }
} }

@ -19,6 +19,7 @@ package cn.hippo4j.springboot.starter.monitor.local.log;
import cn.hippo4j.adapter.web.WebThreadPoolService; import cn.hippo4j.adapter.web.WebThreadPoolService;
import cn.hippo4j.common.constant.Constants; import cn.hippo4j.common.constant.Constants;
import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler;
import cn.hippo4j.monitor.local.log.AdapterThreadPoolLocalLogMonitorHandler; import cn.hippo4j.monitor.local.log.AdapterThreadPoolLocalLogMonitorHandler;
import cn.hippo4j.monitor.local.log.DynamicThreadPoolLocalLogMonitorHandler; import cn.hippo4j.monitor.local.log.DynamicThreadPoolLocalLogMonitorHandler;
import cn.hippo4j.monitor.local.log.WebThreadPoolLocalLogMonitorHandler; import cn.hippo4j.monitor.local.log.WebThreadPoolLocalLogMonitorHandler;
@ -38,8 +39,8 @@ public class LocalLogMonitorAutoConfiguration {
@Bean @Bean
@ConditionalOnExpression("'${spring.dynamic.thread-pool.monitor.thread-pool-types:}'.contains('dynamic')") @ConditionalOnExpression("'${spring.dynamic.thread-pool.monitor.thread-pool-types:}'.contains('dynamic')")
public DynamicThreadPoolLocalLogMonitorHandler dynamicThreadPoolLocalLogMonitorHandler() { public DynamicThreadPoolLocalLogMonitorHandler dynamicThreadPoolLocalLogMonitorHandler(ThreadPoolRunStateHandler handler) {
return new DynamicThreadPoolLocalLogMonitorHandler(); return new DynamicThreadPoolLocalLogMonitorHandler(handler);
} }
@Bean @Bean

@ -19,28 +19,31 @@ package cn.hippo4j.springboot.starter.monitor.micrometer;
import cn.hippo4j.adapter.web.WebThreadPoolService; import cn.hippo4j.adapter.web.WebThreadPoolService;
import cn.hippo4j.common.constant.Constants; import cn.hippo4j.common.constant.Constants;
import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler;
import cn.hippo4j.monitor.micrometer.AdapterThreadPoolMicrometerMonitorHandler; import cn.hippo4j.monitor.micrometer.AdapterThreadPoolMicrometerMonitorHandler;
import cn.hippo4j.monitor.micrometer.DynamicThreadPoolMicrometerMonitorHandler; import cn.hippo4j.monitor.micrometer.DynamicThreadPoolMicrometerMonitorHandler;
import cn.hippo4j.monitor.micrometer.WebThreadPoolMicrometerMonitorHandler; import cn.hippo4j.monitor.micrometer.WebThreadPoolMicrometerMonitorHandler;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
/** /**
* Micrometer monitor auto configuration. * Micrometer monitor auto configuration.
*/ */
@Configuration @Configuration
@AutoConfigureBefore
@ConditionalOnExpression("'${spring.dynamic.thread-pool.monitor.collect-types:}'.contains('micrometer')") @ConditionalOnExpression("'${spring.dynamic.thread-pool.monitor.collect-types:}'.contains('micrometer')")
//@ConditionalOnProperty(prefix = Constants.CONFIGURATION_PROPERTIES_PREFIX, value = "enable", matchIfMissing = true, havingValue = "true")
public class MicrometerMonitorAutoConfiguration { public class MicrometerMonitorAutoConfiguration {
@Bean @Bean
@ConditionalOnExpression("'${spring.dynamic.thread-pool.monitor.thread-pool-types:}'.contains('dynamic')") @ConditionalOnExpression("'${spring.dynamic.thread-pool.monitor.thread-pool-types:}'.contains('dynamic')")
// @ConditionalOnProperty(prefix = Constants.CONFIGURATION_PROPERTIES_PREFIX, value = "enable", matchIfMissing = true, havingValue = "true") public DynamicThreadPoolMicrometerMonitorHandler dynamicThreadPoolMicrometerMonitorHandler(ThreadPoolRunStateHandler handler) {
public DynamicThreadPoolMicrometerMonitorHandler dynamicThreadPoolMicrometerMonitorHandler() { return new DynamicThreadPoolMicrometerMonitorHandler(handler);
return new DynamicThreadPoolMicrometerMonitorHandler();
} }
@Bean @Bean

@ -92,7 +92,7 @@ import org.springframework.core.env.ConfigurableEnvironment;
@AllArgsConstructor @AllArgsConstructor
@ConditionalOnBean(MarkerConfiguration.Marker.class) @ConditionalOnBean(MarkerConfiguration.Marker.class)
@EnableConfigurationProperties(BootstrapProperties.class) @EnableConfigurationProperties(BootstrapProperties.class)
@ConditionalOnProperty(prefix = Constants.CONFIGURATION_PROPERTIES_PREFIX, value = "enable", matchIfMissing = true, havingValue = "true") // @ConditionalOnProperty(prefix = Constants.CONFIGURATION_PROPERTIES_PREFIX, value = "enable", matchIfMissing = true, havingValue = "true")
@ImportAutoConfiguration({WebAdapterConfiguration.class, NettyClientConfiguration.class, DiscoveryConfiguration.class, MessageConfiguration.class, UtilAutoConfiguration.class}) @ImportAutoConfiguration({WebAdapterConfiguration.class, NettyClientConfiguration.class, DiscoveryConfiguration.class, MessageConfiguration.class, UtilAutoConfiguration.class})
public class DynamicThreadPoolAutoConfiguration { public class DynamicThreadPoolAutoConfiguration {
@ -138,6 +138,7 @@ public class DynamicThreadPoolAutoConfiguration {
} }
@Bean @Bean
@ConditionalOnProperty(prefix = Constants.CONFIGURATION_PROPERTIES_PREFIX, value = "enable", matchIfMissing = true, havingValue = "true")
@SuppressWarnings("all") @SuppressWarnings("all")
public DynamicThreadPoolPostProcessor threadPoolBeanPostProcessor(HttpAgent httpAgent, public DynamicThreadPoolPostProcessor threadPoolBeanPostProcessor(HttpAgent httpAgent,
ApplicationContextHolder hippo4jApplicationContextHolder, ApplicationContextHolder hippo4jApplicationContextHolder,

@ -24,11 +24,13 @@ import cn.hippo4j.threadpool.message.core.platform.WeChatSendMessageHandler;
import cn.hippo4j.threadpool.message.core.service.AlarmControlHandler; import cn.hippo4j.threadpool.message.core.service.AlarmControlHandler;
import cn.hippo4j.threadpool.message.core.service.SendMessageHandler; import cn.hippo4j.threadpool.message.core.service.SendMessageHandler;
import cn.hippo4j.threadpool.message.core.service.ThreadPoolBaseSendMessageService; import cn.hippo4j.threadpool.message.core.service.ThreadPoolBaseSendMessageService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
/** /**
* Message configuration. * Message configuration.
*/ */
@ConditionalOnProperty(prefix = "spring.dynamic.thread-pool", value = "enable", matchIfMissing = true, havingValue = "true")
public class MessageConfiguration { public class MessageConfiguration {
@Bean @Bean

@ -30,9 +30,12 @@ import java.util.List;
*/ */
public abstract class AbstractDynamicThreadPoolMonitor implements DynamicThreadPoolMonitor { public abstract class AbstractDynamicThreadPoolMonitor implements DynamicThreadPoolMonitor {
@Resource
private ThreadPoolRunStateHandler threadPoolRunStateHandler; private ThreadPoolRunStateHandler threadPoolRunStateHandler;
public AbstractDynamicThreadPoolMonitor(ThreadPoolRunStateHandler handler) {
this.threadPoolRunStateHandler = handler;
}
/** /**
* Execute collection thread pool running data. * Execute collection thread pool running data.
* *

@ -18,6 +18,7 @@
package cn.hippo4j.monitor.elasticsearch; package cn.hippo4j.monitor.elasticsearch;
import cn.hippo4j.common.model.ThreadPoolRunStateInfo; import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler;
import cn.hippo4j.monitor.base.AbstractDynamicThreadPoolMonitor; import cn.hippo4j.monitor.base.AbstractDynamicThreadPoolMonitor;
import cn.hippo4j.threadpool.monitor.support.MonitorTypeEnum; import cn.hippo4j.threadpool.monitor.support.MonitorTypeEnum;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -28,6 +29,10 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
public class AdapterThreadPoolElasticSearchMonitorHandler extends AbstractDynamicThreadPoolMonitor { public class AdapterThreadPoolElasticSearchMonitorHandler extends AbstractDynamicThreadPoolMonitor {
public AdapterThreadPoolElasticSearchMonitorHandler(ThreadPoolRunStateHandler handler) {
super(handler);
}
@Override @Override
protected void execute(ThreadPoolRunStateInfo poolRunStateInfo) { protected void execute(ThreadPoolRunStateInfo poolRunStateInfo) {
// TODO // TODO

@ -21,6 +21,7 @@ import cn.hippo4j.core.config.ApplicationContextHolder;
import cn.hippo4j.common.model.ThreadPoolRunStateInfo; import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
import cn.hippo4j.common.toolkit.BeanUtil; import cn.hippo4j.common.toolkit.BeanUtil;
import cn.hippo4j.common.toolkit.JSONUtil; import cn.hippo4j.common.toolkit.JSONUtil;
import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler;
import cn.hippo4j.core.toolkit.FileUtil; import cn.hippo4j.core.toolkit.FileUtil;
import cn.hippo4j.monitor.base.AbstractDynamicThreadPoolMonitor; import cn.hippo4j.monitor.base.AbstractDynamicThreadPoolMonitor;
import cn.hippo4j.threadpool.monitor.support.MonitorTypeEnum; import cn.hippo4j.threadpool.monitor.support.MonitorTypeEnum;
@ -55,6 +56,10 @@ public class DynamicThreadPoolElasticSearchMonitorHandler extends AbstractDynami
private AtomicBoolean isIndexExist = null; private AtomicBoolean isIndexExist = null;
public DynamicThreadPoolElasticSearchMonitorHandler(ThreadPoolRunStateHandler handler) {
super(handler);
}
@Override @Override
protected void execute(ThreadPoolRunStateInfo poolRunStateInfo) { protected void execute(ThreadPoolRunStateInfo poolRunStateInfo) {
ElasticSearchThreadPoolRunStateInfo esThreadPoolRunStateInfo = BeanUtil.convert(poolRunStateInfo, ElasticSearchThreadPoolRunStateInfo.class); ElasticSearchThreadPoolRunStateInfo esThreadPoolRunStateInfo = BeanUtil.convert(poolRunStateInfo, ElasticSearchThreadPoolRunStateInfo.class);

@ -18,6 +18,7 @@
package cn.hippo4j.monitor.elasticsearch; package cn.hippo4j.monitor.elasticsearch;
import cn.hippo4j.common.model.ThreadPoolRunStateInfo; import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler;
import cn.hippo4j.monitor.base.AbstractDynamicThreadPoolMonitor; import cn.hippo4j.monitor.base.AbstractDynamicThreadPoolMonitor;
import cn.hippo4j.threadpool.monitor.support.MonitorTypeEnum; import cn.hippo4j.threadpool.monitor.support.MonitorTypeEnum;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -28,6 +29,10 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
public class WebThreadPoolElasticSearchMonitorHandler extends AbstractDynamicThreadPoolMonitor { public class WebThreadPoolElasticSearchMonitorHandler extends AbstractDynamicThreadPoolMonitor {
public WebThreadPoolElasticSearchMonitorHandler(ThreadPoolRunStateHandler handler) {
super(handler);
}
@Override @Override
protected void execute(ThreadPoolRunStateInfo poolRunStateInfo) { protected void execute(ThreadPoolRunStateInfo poolRunStateInfo) {
// TODO // TODO

@ -19,6 +19,7 @@ package cn.hippo4j.monitor.local.log;
import cn.hippo4j.common.model.ThreadPoolRunStateInfo; import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
import cn.hippo4j.common.toolkit.JSONUtil; import cn.hippo4j.common.toolkit.JSONUtil;
import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler;
import cn.hippo4j.monitor.base.AbstractDynamicThreadPoolMonitor; import cn.hippo4j.monitor.base.AbstractDynamicThreadPoolMonitor;
import cn.hippo4j.threadpool.monitor.support.MonitorTypeEnum; import cn.hippo4j.threadpool.monitor.support.MonitorTypeEnum;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -29,6 +30,10 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
public class DynamicThreadPoolLocalLogMonitorHandler extends AbstractDynamicThreadPoolMonitor { public class DynamicThreadPoolLocalLogMonitorHandler extends AbstractDynamicThreadPoolMonitor {
public DynamicThreadPoolLocalLogMonitorHandler(ThreadPoolRunStateHandler handler) {
super(handler);
}
@Override @Override
protected void execute(ThreadPoolRunStateInfo poolRunStateInfo) { protected void execute(ThreadPoolRunStateInfo poolRunStateInfo) {
log.info("{}", JSONUtil.toJSONString(poolRunStateInfo)); log.info("{}", JSONUtil.toJSONString(poolRunStateInfo));

@ -21,6 +21,7 @@ import cn.hippo4j.core.config.ApplicationContextHolder;
import cn.hippo4j.common.model.ThreadPoolRunStateInfo; import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
import cn.hippo4j.common.toolkit.BeanUtil; import cn.hippo4j.common.toolkit.BeanUtil;
import cn.hippo4j.common.toolkit.CollectionUtil; import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler;
import cn.hippo4j.monitor.base.AbstractDynamicThreadPoolMonitor; import cn.hippo4j.monitor.base.AbstractDynamicThreadPoolMonitor;
import cn.hippo4j.threadpool.monitor.support.MonitorTypeEnum; import cn.hippo4j.threadpool.monitor.support.MonitorTypeEnum;
import io.micrometer.core.instrument.Metrics; import io.micrometer.core.instrument.Metrics;
@ -43,6 +44,10 @@ public class DynamicThreadPoolMicrometerMonitorHandler extends AbstractDynamicTh
private final Map<String, ThreadPoolRunStateInfo> runStateCache = new ConcurrentHashMap<>(); private final Map<String, ThreadPoolRunStateInfo> runStateCache = new ConcurrentHashMap<>();
public DynamicThreadPoolMicrometerMonitorHandler(ThreadPoolRunStateHandler handler) {
super(handler);
}
@Override @Override
protected void execute(ThreadPoolRunStateInfo poolRunStateInfo) { protected void execute(ThreadPoolRunStateInfo poolRunStateInfo) {
ThreadPoolRunStateInfo stateInfo = runStateCache.get(poolRunStateInfo.getTpId()); ThreadPoolRunStateInfo stateInfo = runStateCache.get(poolRunStateInfo.getTpId());

Loading…
Cancel
Save