Bruceyan/issue monitor 20230624 (#1382)

pull/1383/head
yanrongzhen 1 year ago committed by GitHub
parent d3e76ff668
commit f773440783
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -83,6 +83,11 @@
<artifactId>hippo4j-threadpool-dynamic-mode-config</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-threadpool-kernel-monitor</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>

@ -28,6 +28,7 @@ import cn.hippo4j.agent.plugin.spring.common.support.SpringThreadPoolRegisterSup
import cn.hippo4j.common.extension.design.AbstractSubjectCenter;
import cn.hippo4j.threadpool.dynamic.api.ThreadPoolDynamicRefresh;
import cn.hippo4j.threadpool.dynamic.mode.config.refresher.event.DynamicThreadPoolRefreshListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ConfigurableApplicationContext;
import java.lang.reflect.Method;
@ -35,6 +36,7 @@ import java.lang.reflect.Method;
/**
* Event publishing started interceptor
*/
@Slf4j
public class EventPublishingStartedInterceptor implements InstanceMethodsAroundInterceptor {
private static final ILog LOGGER = LogManager.getLogger(EventPublishingStartedInterceptor.class);
@ -57,6 +59,7 @@ public class EventPublishingStartedInterceptor implements InstanceMethodsAroundI
dynamicRefresh.registerListener();
AbstractSubjectCenter.register(AbstractSubjectCenter.SubjectType.THREAD_POOL_DYNAMIC_REFRESH,
new DynamicThreadPoolRefreshListener());
return ret;
}

@ -52,6 +52,23 @@ public class SpringBootConfig {
public static List<String> NAMESPACE = Arrays.asList("application");
}
/**
* Monitor
*/
@SpringBootConfigNode(root = SpringBootConfig.class)
public static class Monitor {
public static Boolean enable = Boolean.TRUE;
public static String collectTypes = "micrometer";
public static String threadPoolTypes = "dynamic";
public static Long initialDelay = 10000L;
public static Long collectInterval = 5000L;
}
public static String CONFIG_FILE_TYPE;
}
}

@ -0,0 +1,73 @@
/*
* 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.agent.plugin.spring.common.define;
import cn.hippo4j.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import cn.hippo4j.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import cn.hippo4j.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import cn.hippo4j.agent.core.plugin.match.ClassMatch;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import static cn.hippo4j.agent.core.plugin.match.NameMatch.byName;
import static net.bytebuddy.matcher.ElementMatchers.named;
public class SpringApplicationInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String ENHANCE_CLASS = "org.springframework.boot.SpringApplication";
private static final String RUN_INTERCEPTOR = "cn.hippo4j.agent.plugin.spring.common.interceptor.SpringApplicationRunInterceptor";
@Override
protected ClassMatch enhanceClass() {
return byName(ENHANCE_CLASS);
}
@Override
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return new ConstructorInterceptPoint[0];
}
@Override
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
return new InstanceMethodsInterceptPoint[]{
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named("run");
}
@Override
public String getMethodsInterceptor() {
return RUN_INTERCEPTOR;
}
@Override
public boolean isOverrideArgs() {
return false;
}
}
};
}
@Override
protected String[] witnessClasses() {
return new String[]{"org.springframework.boot.SpringApplication"};
}
}

@ -21,6 +21,7 @@ import cn.hippo4j.agent.core.util.ReflectUtil;
import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry;
import cn.hippo4j.common.executor.support.BlockingQueueTypeEnum;
import cn.hippo4j.common.executor.support.RejectedPolicyTypeEnum;
import cn.hippo4j.common.handler.DynamicThreadPoolAdapterChoose;
import cn.hippo4j.common.model.executor.ExecutorProperties;
import cn.hippo4j.common.toolkit.BooleanUtil;
import org.slf4j.Logger;
@ -64,13 +65,12 @@ public class SpringThreadPoolRegisterSupport {
for (Map.Entry<String, Executor> entry : beansWithAnnotation.entrySet()) {
String beanName = entry.getKey();
Executor bean = entry.getValue();
ThreadPoolExecutor executor = (ThreadPoolExecutor) bean;
// TODO
// if (DynamicThreadPoolAdapterChoose.match(bean)) {
// executor = DynamicThreadPoolAdapterChoose.unwrap(bean);
// } else {
// executor = (ThreadPoolExecutor) bean;
// }
ThreadPoolExecutor executor;
if (DynamicThreadPoolAdapterChoose.match(bean)) {
executor = DynamicThreadPoolAdapterChoose.unwrap(bean);
} else {
executor = (ThreadPoolExecutor) bean;
}
if (executor == null) {
LOGGER.warn("[Hippo4j-Agent] Thread pool is null, ignore bean registration. beanName={}, beanClass={}", beanName, bean.getClass().getName());
} else {

@ -15,7 +15,7 @@
* limitations under the License.
*/
package cn.hippo4j.core.executor.support.adpter;
package cn.hippo4j.common.api;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

@ -0,0 +1,96 @@
/*
* 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.common.handler;
import cn.hippo4j.common.api.DynamicThreadPoolAdapter;
import cn.hippo4j.common.extension.spi.ServiceLoaderRegistry;
import cn.hippo4j.common.toolkit.CollectionUtil;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
/**
* Dynamic thread pool adapter choose.
*/
public class DynamicThreadPoolAdapterChoose {
private static final List<DynamicThreadPoolAdapter> DYNAMIC_THREAD_POOL_ADAPTERS = new ArrayList<>();
static {
DYNAMIC_THREAD_POOL_ADAPTERS.add(new TransmittableThreadLocalExecutorAdapter());
DYNAMIC_THREAD_POOL_ADAPTERS.add(new TransmittableThreadLocalExecutorServiceAdapter());
DYNAMIC_THREAD_POOL_ADAPTERS.add(new ZipkinExecutorAdapter());
loadCustomerAdapter();
}
/**
* Check if the object contains thread pool information.
*
* @param executor objects where there may be instances
* of dynamic thread pools
* @return matching results
*/
public static boolean match(Object executor) {
return DYNAMIC_THREAD_POOL_ADAPTERS.stream().anyMatch(each -> each.match(executor));
}
/**
* Get the dynamic thread pool reference in the object.
*
* @param executor objects where there may be instances
* of dynamic thread pools
* @return get the real dynamic thread pool instance
*/
public static ThreadPoolExecutor unwrap(Object executor) {
Optional<DynamicThreadPoolAdapter> dynamicThreadPoolAdapterOptional = DYNAMIC_THREAD_POOL_ADAPTERS.stream().filter(each -> each.match(executor)).findFirst();
return dynamicThreadPoolAdapterOptional.map(each -> each.unwrap(executor)).orElse(null);
}
/**
* If the {@link DynamicThreadPoolAdapter#match(Object)} conditions are met,
* the thread pool is replaced with a dynamic thread pool.
*
* @param executor objects where there may be instances
* of dynamic thread pools
* @param dynamicThreadPoolExecutor dynamic thread-pool executor
*/
public static void replace(Object executor, Executor dynamicThreadPoolExecutor) {
Optional<DynamicThreadPoolAdapter> dynamicThreadPoolAdapterOptional = DYNAMIC_THREAD_POOL_ADAPTERS.stream().filter(each -> each.match(executor)).findFirst();
dynamicThreadPoolAdapterOptional.ifPresent(dynamicThreadPoolAdapter -> dynamicThreadPoolAdapter.replace(executor, dynamicThreadPoolExecutor));
}
/**
* Load SPI customer adapter.
*/
private static void loadCustomerAdapter() {
ServiceLoaderRegistry.register(DynamicThreadPoolAdapter.class);
Collection<DynamicThreadPoolAdapter> instances = ServiceLoaderRegistry.getSingletonServiceInstances(DynamicThreadPoolAdapter.class);
if (CollectionUtil.isEmpty(instances)) {
return;
}
for (DynamicThreadPoolAdapter instance : instances) {
if (instance != null) {
DYNAMIC_THREAD_POOL_ADAPTERS.add(instance);
}
}
}
}

@ -15,7 +15,7 @@
* limitations under the License.
*/
package cn.hippo4j.core.executor.state;
package cn.hippo4j.common.handler;
import cn.hippo4j.common.toolkit.ReflectUtil;
import lombok.extern.slf4j.Slf4j;

@ -0,0 +1,50 @@
/*
* 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.common.handler;
import cn.hippo4j.common.api.DynamicThreadPoolAdapter;
import cn.hippo4j.common.toolkit.ReflectUtil;
import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
/**
* Transmittable thread local executor adapter.
*/
public class TransmittableThreadLocalExecutorAdapter implements DynamicThreadPoolAdapter {
private static final String MATCH_CLASS_NAME = "ExecutorTtlWrapper";
private static final String FIELD_NAME = "executor";
@Override
public boolean match(Object executor) {
return Objects.equals(MATCH_CLASS_NAME, executor.getClass().getSimpleName());
}
@Override
public ThreadPoolExecutor unwrap(Object executor) {
return (ThreadPoolExecutor) ReflectUtil.getFieldValue(executor, FIELD_NAME);
}
@Override
public void replace(Object executor, Executor dynamicThreadPoolExecutor) {
ReflectUtil.setFieldValue(executor, FIELD_NAME, dynamicThreadPoolExecutor);
}
}

@ -0,0 +1,50 @@
/*
* 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.common.handler;
import cn.hippo4j.common.api.DynamicThreadPoolAdapter;
import cn.hippo4j.common.toolkit.ReflectUtil;
import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
/**
* Transmittable thread local executor service adapter.
*/
public class TransmittableThreadLocalExecutorServiceAdapter implements DynamicThreadPoolAdapter {
private static final String MATCH_CLASS_NAME = "ExecutorServiceTtlWrapper";
private static final String FIELD_NAME = "executorService";
@Override
public boolean match(Object executor) {
return Objects.equals(MATCH_CLASS_NAME, executor.getClass().getSimpleName());
}
@Override
public ThreadPoolExecutor unwrap(Object executor) {
return (ThreadPoolExecutor) ReflectUtil.getFieldValue(executor, FIELD_NAME);
}
@Override
public void replace(Object executor, Executor dynamicThreadPoolExecutor) {
ReflectUtil.setFieldValue(executor, FIELD_NAME, dynamicThreadPoolExecutor);
}
}

@ -0,0 +1,76 @@
/*
* 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.common.handler;
import cn.hippo4j.common.api.DynamicThreadPoolAdapter;
import cn.hippo4j.common.toolkit.ReflectUtil;
import java.lang.reflect.Field;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
/**
* Zipkin thread local executor adapter.
*/
public class ZipkinExecutorAdapter implements DynamicThreadPoolAdapter {
private static final String MATCH_CLASS_NAME = "brave.internal.WrappingExecutorService";
private static final String FIELD_NAME = "delegate";
private static final String TYPE_NAME = "java.util.concurrent.ExecutorService";
@Override
public boolean match(Object executor) {
return matchSuper(executor);
}
public boolean matchSuper(Object executor) {
if (Objects.equals(MATCH_CLASS_NAME, Optional.ofNullable(executor).map(Object::getClass).map(Class::getName).orElse(null))) {
return true;
} else {
return Objects.equals(MATCH_CLASS_NAME, Optional.ofNullable(executor).map(Object::getClass).map(Class::getSuperclass).map(Class::getName).orElse(null));
}
}
@Override
public ThreadPoolExecutor unwrap(Object executor) {
Object unwrap = doUnwrap(executor);
if (unwrap == null) {
return null;
}
return (ThreadPoolExecutor) unwrap;
}
@Override
public void replace(Object executor, Executor dynamicThreadPoolExecutor) {
Field field = ReflectUtil.findField(executor, FIELD_NAME, TYPE_NAME);
ReflectUtil.setFieldValue(executor, field, dynamicThreadPoolExecutor);
}
private Object doUnwrap(Object executor) {
Object unwrap = ReflectUtil.getFieldValue(executor, FIELD_NAME);
if (unwrap == null) {
Field field = ReflectUtil.findField(executor, FIELD_NAME, TYPE_NAME);
if (field != null) {
return ReflectUtil.getFieldValue(executor, field);
}
}
return null;
}
}

@ -15,7 +15,7 @@
* limitations under the License.
*/
package cn.hippo4j.adapter.base;
package cn.hippo4j.common.model;
import lombok.Data;

@ -15,16 +15,17 @@
* limitations under the License.
*/
package cn.hippo4j.core.executor.state;
package cn.hippo4j.common.support;
import cn.hippo4j.common.executor.ThreadPoolExecutorHolder;
import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry;
import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
import cn.hippo4j.common.toolkit.CalculateUtil;
import cn.hippo4j.core.executor.DynamicThreadPoolExecutor;
import cn.hippo4j.common.toolkit.ReflectUtil;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Objects;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
@ -68,7 +69,13 @@ public abstract class AbstractThreadPoolRuntime {
int activeCount = actualExecutor.getActiveCount();
int largestPoolSize = actualExecutor.getLargestPoolSize();
BlockingQueue<Runnable> blockingQueue = actualExecutor.getQueue();
long rejectCount = actualExecutor instanceof DynamicThreadPoolExecutor ? ((DynamicThreadPoolExecutor) actualExecutor).getRejectCountNum() : NO_REJECT_COUNT_NUM;
long rejectCount = NO_REJECT_COUNT_NUM;
if (Objects.equals(actualExecutor.getClass().getName(), "cn.hippo4j.core.executor.DynamicThreadPoolExecutor")) {
Object actualRejectCountNum = ReflectUtil.invoke(actualExecutor, "getRejectCountNum");
if (actualRejectCountNum != null) {
rejectCount = (long) actualRejectCountNum;
}
}
ThreadPoolRunStateInfo stateInfo = ThreadPoolRunStateInfo.builder()
.tpId(threadPoolId)
.activeSize(activeCount)

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-kernel</artifactId>
<version>${revision}</version>
</parent>
<artifactId>hippo4j-threadpool-kernel-monitor</artifactId>
<dependencies>
<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-threadpool-infra-common</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

@ -15,7 +15,7 @@
* limitations under the License.
*/
package cn.hippo4j.monitor.base;
package cn.hippo4j.threadpool.monitor.api;
/**
* Adapter thread-pool monitor.

@ -15,7 +15,7 @@
* limitations under the License.
*/
package cn.hippo4j.monitor.base;
package cn.hippo4j.threadpool.monitor.api;
/**
* Dynamic thread-pool monitor.

@ -15,7 +15,7 @@
* limitations under the License.
*/
package cn.hippo4j.monitor.base;
package cn.hippo4j.threadpool.monitor.api;
/**
* Thread-pool runtime monitor.

@ -15,7 +15,9 @@
* limitations under the License.
*/
package cn.hippo4j.monitor.base;
package cn.hippo4j.threadpool.monitor.api;
import cn.hippo4j.threadpool.monitor.api.ThreadPoolMonitor;
/**
* Web thread-pool monitor.

@ -15,7 +15,7 @@
* limitations under the License.
*/
package cn.hippo4j.monitor.base;
package cn.hippo4j.threadpool.monitor.support;
/**
* Monitor thread-pool type enum.

@ -15,7 +15,7 @@
* limitations under the License.
*/
package cn.hippo4j.monitor.base;
package cn.hippo4j.threadpool.monitor.support;
/**
* Monitor type enum.

@ -16,5 +16,6 @@
<module>alarm</module>
<module>dynamic</module>
<module>message</module>
<module>monitor</module>
</modules>
</project>

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

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

@ -19,7 +19,7 @@ package cn.hippo4j.config.springboot1x.starter.web.tomcat;
import cn.hippo4j.adapter.web.tomcat.TomcatWebThreadPoolHandlerSupport;
import cn.hippo4j.config.springboot1x.starter.web.AbstractWebThreadPoolService1x;
import cn.hippo4j.core.executor.state.AbstractThreadPoolRuntime;
import cn.hippo4j.common.support.AbstractThreadPoolRuntime;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer;

@ -38,6 +38,7 @@ import org.springframework.context.annotation.Configuration;
* Config handler configuration.
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, value = "enable", matchIfMissing = true, havingValue = "true")
public class ConfigHandlerConfiguration {
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.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.refresher.event.AdapterExecutorsRefreshListener;
import cn.hippo4j.config.springboot.starter.refresher.event.DynamicThreadPoolRefreshListener;
@ -29,12 +28,9 @@ import cn.hippo4j.config.springboot.starter.support.DynamicThreadPoolAdapterRegi
import cn.hippo4j.config.springboot.starter.support.DynamicThreadPoolConfigService;
import cn.hippo4j.config.springboot.starter.support.DynamicThreadPoolPostProcessor;
import cn.hippo4j.core.config.ApplicationContextHolder;
import cn.hippo4j.core.config.UtilAutoConfiguration;
import cn.hippo4j.core.enable.MarkerConfiguration;
import cn.hippo4j.core.executor.handler.DynamicThreadPoolBannerHandler;
import cn.hippo4j.core.extension.initialize.Hippo4jDynamicThreadPoolInitializer;
import cn.hippo4j.message.config.MessageConfiguration;
import cn.hippo4j.springboot.starter.adapter.web.WebAdapterConfiguration;
import cn.hippo4j.threadpool.alarm.api.ThreadPoolCheckAlarm;
import cn.hippo4j.threadpool.alarm.handler.DefaultThreadPoolCheckAlarmHandler;
import cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties;
@ -46,7 +42,6 @@ import cn.hippo4j.threadpool.message.core.service.ThreadPoolSendMessageService;
import cn.hippo4j.threadpool.message.core.service.WebThreadPoolConfigChangeHandler;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@ -54,6 +49,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.boot.info.BuildProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Import;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
@ -70,10 +66,9 @@ import org.springframework.core.annotation.Order;
@Configuration
@AllArgsConstructor
@ConditionalOnBean(MarkerConfiguration.Marker.class)
@ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, value = "enable", matchIfMissing = true, havingValue = "true")
@EnableConfigurationProperties(SpringBootstrapConfigProperties.class)
@Import(ConfigHandlerConfiguration.class)
@ImportAutoConfiguration({WebAdapterConfiguration.class, UtilAutoConfiguration.class, MessageConfiguration.class})
@ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, value = "enable", matchIfMissing = true, havingValue = "true")
public class DynamicThreadPoolAutoConfiguration {
private final BootstrapConfigProperties bootstrapConfigProperties;
@ -114,15 +109,11 @@ public class DynamicThreadPoolAutoConfiguration {
}
@Bean
public DynamicThreadPoolPostProcessor dynamicThreadPoolPostProcessor(ApplicationContextHolder hippo4jApplicationContextHolder) {
@DependsOn("hippo4jApplicationContextHolder")
public DynamicThreadPoolPostProcessor dynamicThreadPoolPostProcessor() {
return new DynamicThreadPoolPostProcessor(bootstrapConfigProperties);
}
@Bean
public ThreadPoolMonitorExecutor hippo4jDynamicThreadPoolMonitorExecutor() {
return new ThreadPoolMonitorExecutor(bootstrapConfigProperties);
}
@Bean
@SuppressWarnings("all")
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);
}
}

@ -22,10 +22,10 @@ import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry;
import cn.hippo4j.common.extension.spi.ServiceLoaderRegistry;
import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.core.config.ApplicationContextHolder;
import cn.hippo4j.monitor.base.DynamicThreadPoolMonitor;
import cn.hippo4j.monitor.base.ThreadPoolMonitor;
import cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties;
import cn.hippo4j.threadpool.dynamic.mode.config.properties.MonitorProperties;
import cn.hippo4j.threadpool.monitor.api.DynamicThreadPoolMonitor;
import cn.hippo4j.threadpool.monitor.api.ThreadPoolMonitor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.DisposableBean;

@ -19,7 +19,7 @@ package cn.hippo4j.config.springboot.starter.refresher.event;
import cn.hippo4j.adapter.base.ThreadPoolAdapter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
import cn.hippo4j.common.model.ThreadPoolAdapterState;
import cn.hippo4j.core.config.ApplicationContextHolder;
import cn.hippo4j.common.toolkit.BeanUtil;
import cn.hippo4j.common.toolkit.CollectionUtil;

@ -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

@ -17,14 +17,13 @@
package cn.hippo4j.springboot.starter.monitor.elasticsearch;
import cn.hippo4j.common.constant.Constants;
import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler;
import cn.hippo4j.core.enable.MarkerConfiguration;
import cn.hippo4j.monitor.elasticsearch.AdapterThreadPoolElasticSearchMonitorHandler;
import cn.hippo4j.monitor.elasticsearch.DynamicThreadPoolElasticSearchMonitorHandler;
import cn.hippo4j.monitor.elasticsearch.WebThreadPoolElasticSearchMonitorHandler;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -34,24 +33,23 @@ import org.springframework.context.annotation.Configuration;
@Configuration
@ConditionalOnBean(MarkerConfiguration.Marker.class)
@ConditionalOnExpression("'${spring.dynamic.thread-pool.monitor.collect-types:}'.contains('elasticsearch')")
@ConditionalOnProperty(prefix = Constants.CONFIGURATION_PROPERTIES_PREFIX, value = "enable", matchIfMissing = true, havingValue = "true")
public class ElasticSearchMonitorAutoConfiguration {
@Bean
@ConditionalOnExpression("'${spring.dynamic.thread-pool.monitor.thread-pool-types:}'.contains('dynamic')")
public DynamicThreadPoolElasticSearchMonitorHandler dynamicThreadPoolElasticSearchMonitorHandler() {
return new DynamicThreadPoolElasticSearchMonitorHandler();
public DynamicThreadPoolElasticSearchMonitorHandler dynamicThreadPoolElasticSearchMonitorHandler(ThreadPoolRunStateHandler handler) {
return new DynamicThreadPoolElasticSearchMonitorHandler(handler);
}
@Bean
@ConditionalOnExpression("'${spring.dynamic.thread-pool.monitor.thread-pool-types:}'.contains('web')")
public WebThreadPoolElasticSearchMonitorHandler webThreadPoolElasticSearchMonitorHandler() {
return new WebThreadPoolElasticSearchMonitorHandler();
public WebThreadPoolElasticSearchMonitorHandler webThreadPoolElasticSearchMonitorHandler(ThreadPoolRunStateHandler handler) {
return new WebThreadPoolElasticSearchMonitorHandler(handler);
}
@Bean
@ConditionalOnExpression("'${spring.dynamic.thread-pool.monitor.thread-pool-types:}'.contains('adapter')")
public AdapterThreadPoolElasticSearchMonitorHandler adapterThreadPoolElasticSearchMonitorHandler() {
return new AdapterThreadPoolElasticSearchMonitorHandler();
public AdapterThreadPoolElasticSearchMonitorHandler adapterThreadPoolElasticSearchMonitorHandler(ThreadPoolRunStateHandler handler) {
return new AdapterThreadPoolElasticSearchMonitorHandler(handler);
}
}

@ -18,14 +18,13 @@
package cn.hippo4j.springboot.starter.monitor.local.log;
import cn.hippo4j.adapter.web.WebThreadPoolService;
import cn.hippo4j.common.constant.Constants;
import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler;
import cn.hippo4j.core.enable.MarkerConfiguration;
import cn.hippo4j.monitor.local.log.AdapterThreadPoolLocalLogMonitorHandler;
import cn.hippo4j.monitor.local.log.DynamicThreadPoolLocalLogMonitorHandler;
import cn.hippo4j.monitor.local.log.WebThreadPoolLocalLogMonitorHandler;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -35,13 +34,12 @@ import org.springframework.context.annotation.Configuration;
@Configuration
@ConditionalOnBean(MarkerConfiguration.Marker.class)
@ConditionalOnExpression("'${spring.dynamic.thread-pool.monitor.collect-types:}'.contains('log')")
@ConditionalOnProperty(prefix = Constants.CONFIGURATION_PROPERTIES_PREFIX, value = "enable", matchIfMissing = true, havingValue = "true")
public class LocalLogMonitorAutoConfiguration {
@Bean
@ConditionalOnExpression("'${spring.dynamic.thread-pool.monitor.thread-pool-types:}'.contains('dynamic')")
public DynamicThreadPoolLocalLogMonitorHandler dynamicThreadPoolLocalLogMonitorHandler() {
return new DynamicThreadPoolLocalLogMonitorHandler();
public DynamicThreadPoolLocalLogMonitorHandler dynamicThreadPoolLocalLogMonitorHandler(ThreadPoolRunStateHandler handler) {
return new DynamicThreadPoolLocalLogMonitorHandler(handler);
}
@Bean

@ -18,16 +18,16 @@
package cn.hippo4j.springboot.starter.monitor.micrometer;
import cn.hippo4j.adapter.web.WebThreadPoolService;
import cn.hippo4j.common.constant.Constants;
import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler;
import cn.hippo4j.core.enable.MarkerConfiguration;
import cn.hippo4j.monitor.micrometer.AdapterThreadPoolMicrometerMonitorHandler;
import cn.hippo4j.monitor.micrometer.DynamicThreadPoolMicrometerMonitorHandler;
import cn.hippo4j.monitor.micrometer.WebThreadPoolMicrometerMonitorHandler;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
/**
* Micrometer monitor auto configuration.
@ -35,14 +35,12 @@ import org.springframework.context.annotation.Configuration;
@Configuration
@ConditionalOnBean(MarkerConfiguration.Marker.class)
@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 {
@Bean
@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() {
return new DynamicThreadPoolMicrometerMonitorHandler();
public DynamicThreadPoolMicrometerMonitorHandler dynamicThreadPoolMicrometerMonitorHandler(ThreadPoolRunStateHandler handler) {
return new DynamicThreadPoolMicrometerMonitorHandler(handler);
}
@Bean

@ -138,6 +138,7 @@ public class DynamicThreadPoolAutoConfiguration {
}
@Bean
@ConditionalOnProperty(prefix = Constants.CONFIGURATION_PROPERTIES_PREFIX, value = "enable", matchIfMissing = true, havingValue = "true")
@SuppressWarnings("all")
public DynamicThreadPoolPostProcessor threadPoolBeanPostProcessor(HttpAgent httpAgent,
ApplicationContextHolder hippo4jApplicationContextHolder,

@ -17,8 +17,8 @@
package cn.hippo4j.springboot.starter.config;
import cn.hippo4j.monitor.base.MonitorThreadPoolTypeEnum;
import cn.hippo4j.monitor.base.MonitorTypeEnum;
import cn.hippo4j.threadpool.monitor.support.MonitorThreadPoolTypeEnum;
import cn.hippo4j.threadpool.monitor.support.MonitorTypeEnum;
import lombok.Data;
/**

@ -19,7 +19,7 @@ package cn.hippo4j.springboot.starter.controller;
import cn.hippo4j.adapter.base.ThreadPoolAdapter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
import cn.hippo4j.common.model.ThreadPoolAdapterState;
import cn.hippo4j.common.model.Result;
import cn.hippo4j.core.api.ClientNetworkService;
import cn.hippo4j.common.extension.spi.ServiceLoaderRegistry;

@ -20,7 +20,7 @@ package cn.hippo4j.springboot.starter.core;
import cn.hippo4j.adapter.base.ThreadPoolAdapter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterCacheConfig;
import cn.hippo4j.adapter.base.ThreadPoolAdapterRegisterAction;
import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
import cn.hippo4j.common.model.ThreadPoolAdapterState;
import cn.hippo4j.common.model.Result;
import cn.hippo4j.core.config.ApplicationContextHolder;
import cn.hippo4j.common.toolkit.CollectionUtil;

@ -25,13 +25,13 @@ import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.common.toolkit.ThreadUtil;
import cn.hippo4j.core.config.ApplicationContextHolder;
import cn.hippo4j.monitor.base.MonitorTypeEnum;
import cn.hippo4j.monitor.base.ThreadPoolMonitor;
import cn.hippo4j.threadpool.monitor.support.MonitorTypeEnum;
import cn.hippo4j.springboot.starter.config.BootstrapProperties;
import cn.hippo4j.springboot.starter.config.MonitorProperties;
import cn.hippo4j.springboot.starter.monitor.collect.Collector;
import cn.hippo4j.springboot.starter.monitor.send.MessageSender;
import cn.hippo4j.springboot.starter.remote.ServerHealthCheck;
import cn.hippo4j.threadpool.monitor.api.ThreadPoolMonitor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;

@ -24,7 +24,7 @@ import cn.hippo4j.common.monitor.Message;
import cn.hippo4j.common.monitor.MessageTypeEnum;
import cn.hippo4j.common.monitor.RuntimeMessage;
import cn.hippo4j.common.toolkit.BeanUtil;
import cn.hippo4j.core.executor.state.AbstractThreadPoolRuntime;
import cn.hippo4j.common.support.AbstractThreadPoolRuntime;
import cn.hippo4j.springboot.starter.config.BootstrapProperties;
import lombok.AllArgsConstructor;

@ -20,7 +20,7 @@ package cn.hippo4j.springboot.starter.support;
import cn.hippo4j.common.executor.ThreadPoolExecutorHolder;
import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry;
import cn.hippo4j.core.executor.DynamicThreadPoolExecutor;
import cn.hippo4j.core.executor.support.adpter.DynamicThreadPoolAdapter;
import cn.hippo4j.common.api.DynamicThreadPoolAdapter;
import cn.hippo4j.core.executor.support.adpter.DynamicThreadPoolAdapterChoose;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@ -19,7 +19,7 @@ package cn.hippo4j.adapter.alibaba.dubbo;
import cn.hippo4j.adapter.base.ThreadPoolAdapter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
import cn.hippo4j.common.model.ThreadPoolAdapterState;
import cn.hippo4j.common.toolkit.ThreadPoolExecutorUtil;
import com.alibaba.dubbo.common.extension.ExtensionLoader;
import com.alibaba.dubbo.common.store.DataStore;

@ -17,6 +17,8 @@
package cn.hippo4j.adapter.base;
import cn.hippo4j.common.model.ThreadPoolAdapterState;
import java.util.List;
/**

@ -17,6 +17,7 @@
package cn.hippo4j.adapter.base;
import cn.hippo4j.common.model.ThreadPoolAdapterState;
import lombok.Data;
import java.util.List;

@ -19,7 +19,7 @@ package cn.hippo4j.adapter.dubbo;
import cn.hippo4j.adapter.base.ThreadPoolAdapter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
import cn.hippo4j.common.model.ThreadPoolAdapterState;
import cn.hippo4j.common.toolkit.ReflectUtil;
import cn.hippo4j.common.toolkit.ThreadPoolExecutorUtil;
import lombok.extern.slf4j.Slf4j;

@ -19,7 +19,7 @@ package cn.hippo4j.adapter.hystrix;
import cn.hippo4j.adapter.base.ThreadPoolAdapter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
import cn.hippo4j.common.model.ThreadPoolAdapterState;
import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.common.toolkit.ThreadPoolExecutorUtil;
import com.netflix.hystrix.HystrixThreadPool;

@ -20,7 +20,7 @@ package cn.hippo4j.adapter.hystrix;
import cn.hippo4j.adapter.base.ThreadPoolAdapter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterCacheConfig;
import cn.hippo4j.adapter.base.ThreadPoolAdapterRegisterAction;
import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
import cn.hippo4j.common.model.ThreadPoolAdapterState;
import cn.hippo4j.core.config.ApplicationContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.event.ApplicationStartedEvent;

@ -19,7 +19,7 @@ package cn.hippo4j.adapter.kafka;
import cn.hippo4j.adapter.base.ThreadPoolAdapter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
import cn.hippo4j.common.model.ThreadPoolAdapterState;
import cn.hippo4j.common.toolkit.ReflectUtil;
import cn.hippo4j.core.config.ApplicationContextHolder;
import lombok.SneakyThrows;

@ -19,7 +19,7 @@ package cn.hippo4j.adapter.rabbitmq;
import cn.hippo4j.adapter.base.ThreadPoolAdapter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
import cn.hippo4j.common.model.ThreadPoolAdapterState;
import cn.hippo4j.common.toolkit.ReflectUtil;
import cn.hippo4j.common.toolkit.ThreadPoolExecutorUtil;
import lombok.RequiredArgsConstructor;

@ -19,7 +19,7 @@ package cn.hippo4j.adapter.rocketmq;
import cn.hippo4j.adapter.base.ThreadPoolAdapter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
import cn.hippo4j.common.model.ThreadPoolAdapterState;
import cn.hippo4j.common.toolkit.ReflectUtil;
import cn.hippo4j.common.toolkit.ThreadPoolExecutorUtil;
import cn.hippo4j.core.config.ApplicationContextHolder;

@ -19,7 +19,7 @@ package cn.hippo4j.adapter.springcloud.stream.rabbitmq;
import cn.hippo4j.adapter.base.ThreadPoolAdapter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
import cn.hippo4j.common.model.ThreadPoolAdapterState;
import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.common.toolkit.ReflectUtil;
import cn.hippo4j.core.config.ApplicationContextHolder;

@ -19,7 +19,7 @@ package cn.hippo4j.adapter.springcloud.stream.rocketmq;
import cn.hippo4j.adapter.base.ThreadPoolAdapter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
import cn.hippo4j.common.model.ThreadPoolAdapterState;
import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.common.toolkit.ReflectUtil;
import cn.hippo4j.common.toolkit.ThreadPoolExecutorUtil;

@ -21,7 +21,7 @@ import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
import cn.hippo4j.common.toolkit.ByteConvertUtil;
import cn.hippo4j.common.toolkit.MemoryUtil;
import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.core.executor.state.AbstractThreadPoolRuntime;
import cn.hippo4j.common.support.AbstractThreadPoolRuntime;
import lombok.extern.slf4j.Slf4j;
/**

@ -18,7 +18,7 @@
package cn.hippo4j.adapter.web.tomcat;
import cn.hippo4j.adapter.web.DefaultAbstractWebThreadPoolService;
import cn.hippo4j.core.executor.state.AbstractThreadPoolRuntime;
import cn.hippo4j.common.support.AbstractThreadPoolRuntime;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.embedded.tomcat.TomcatWebServer;
import org.springframework.boot.web.server.WebServer;

@ -25,7 +25,7 @@ import cn.hippo4j.common.model.ThreadPoolParameter;
import cn.hippo4j.common.model.ThreadPoolParameterInfo;
import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
import cn.hippo4j.common.toolkit.CalculateUtil;
import cn.hippo4j.core.executor.state.AbstractThreadPoolRuntime;
import cn.hippo4j.common.support.AbstractThreadPoolRuntime;
import lombok.extern.slf4j.Slf4j;
import java.time.LocalDateTime;

@ -29,6 +29,11 @@
<artifactId>hippo4j-threadpool-kernel-alarm</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-threadpool-kernel-monitor</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

@ -19,8 +19,10 @@ package cn.hippo4j.core.executor.state;
import cn.hippo4j.common.executor.ThreadPoolExecutorHolder;
import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry;
import cn.hippo4j.common.handler.ThreadPoolStatusHandler;
import cn.hippo4j.common.model.ManyThreadPoolRunStateInfo;
import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
import cn.hippo4j.common.support.AbstractThreadPoolRuntime;
import cn.hippo4j.common.toolkit.BeanUtil;
import cn.hippo4j.common.toolkit.ByteConvertUtil;
import cn.hippo4j.common.toolkit.MemoryUtil;
@ -66,7 +68,8 @@ public class ThreadPoolRunStateHandler extends AbstractThreadPoolRuntime {
String rejectedName;
rejectedName = pool.getRejectedExecutionHandler().getClass().getSimpleName();
poolRunStateInfo.setRejectedName(rejectedName);
ManyThreadPoolRunStateInfo manyThreadPoolRunStateInfo = BeanUtil.convert(poolRunStateInfo, ManyThreadPoolRunStateInfo.class);
ManyThreadPoolRunStateInfo manyThreadPoolRunStateInfo = convert(poolRunStateInfo);
manyThreadPoolRunStateInfo.setIdentify(CLIENT_IDENTIFICATION_VALUE);
String active = environment.getProperty("spring.profiles.active", "UNKNOWN");
manyThreadPoolRunStateInfo.setActive(active.toUpperCase());
@ -74,4 +77,31 @@ public class ThreadPoolRunStateHandler extends AbstractThreadPoolRuntime {
manyThreadPoolRunStateInfo.setState(threadPoolState);
return manyThreadPoolRunStateInfo;
}
private ManyThreadPoolRunStateInfo convert(ThreadPoolRunStateInfo poolRunStateInfo) {
ManyThreadPoolRunStateInfo manyThreadPoolRunStateInfo = new ManyThreadPoolRunStateInfo();
manyThreadPoolRunStateInfo.setCurrentLoad(poolRunStateInfo.getCurrentLoad());
manyThreadPoolRunStateInfo.setPeakLoad(poolRunStateInfo.getPeakLoad());
manyThreadPoolRunStateInfo.setTpId(poolRunStateInfo.getTpId());
manyThreadPoolRunStateInfo.setActiveCount(poolRunStateInfo.getActiveCount());
manyThreadPoolRunStateInfo.setPoolSize(poolRunStateInfo.getPoolSize());
manyThreadPoolRunStateInfo.setActiveSize(poolRunStateInfo.getActiveSize());
manyThreadPoolRunStateInfo.setLargestPoolSize(poolRunStateInfo.getLargestPoolSize());
manyThreadPoolRunStateInfo.setQueueSize(poolRunStateInfo.getQueueSize());
manyThreadPoolRunStateInfo.setQueueRemainingCapacity(poolRunStateInfo.getQueueRemainingCapacity());
manyThreadPoolRunStateInfo.setCompletedTaskCount(poolRunStateInfo.getCompletedTaskCount());
manyThreadPoolRunStateInfo.setRejectCount(poolRunStateInfo.getRejectCount());
manyThreadPoolRunStateInfo.setHost(poolRunStateInfo.getHost());
manyThreadPoolRunStateInfo.setMemoryProportion(poolRunStateInfo.getMemoryProportion());
manyThreadPoolRunStateInfo.setFreeMemory(poolRunStateInfo.getFreeMemory());
manyThreadPoolRunStateInfo.setClientLastRefreshTime(poolRunStateInfo.getClientLastRefreshTime());
manyThreadPoolRunStateInfo.setTimestamp(poolRunStateInfo.getTimestamp());
manyThreadPoolRunStateInfo.setCoreSize(poolRunStateInfo.getCoreSize());
manyThreadPoolRunStateInfo.setMaximumSize(poolRunStateInfo.getMaximumSize());
manyThreadPoolRunStateInfo.setQueueType(poolRunStateInfo.getQueueType());
manyThreadPoolRunStateInfo.setQueueCapacity(poolRunStateInfo.getQueueCapacity());
manyThreadPoolRunStateInfo.setRejectedName(poolRunStateInfo.getRejectedName());
manyThreadPoolRunStateInfo.setKeepAliveTime(poolRunStateInfo.getKeepAliveTime());
return manyThreadPoolRunStateInfo;
}
}

@ -17,6 +17,7 @@
package cn.hippo4j.core.executor.support.adpter;
import cn.hippo4j.common.api.DynamicThreadPoolAdapter;
import cn.hippo4j.common.extension.spi.ServiceLoaderRegistry;
import cn.hippo4j.common.toolkit.CollectionUtil;

@ -17,6 +17,7 @@
package cn.hippo4j.core.executor.support.adpter;
import cn.hippo4j.common.api.DynamicThreadPoolAdapter;
import cn.hippo4j.common.toolkit.ReflectUtil;
import cn.hippo4j.core.executor.DynamicThreadPoolExecutor;
import cn.hippo4j.core.executor.support.ThreadPoolBuilder;

@ -17,6 +17,7 @@
package cn.hippo4j.core.executor.support.adpter;
import cn.hippo4j.common.api.DynamicThreadPoolAdapter;
import cn.hippo4j.common.toolkit.ReflectUtil;
import cn.hippo4j.core.executor.DynamicThreadPoolExecutor;

@ -17,6 +17,7 @@
package cn.hippo4j.core.executor.support.adpter;
import cn.hippo4j.common.api.DynamicThreadPoolAdapter;
import cn.hippo4j.common.toolkit.ReflectUtil;
import cn.hippo4j.core.executor.DynamicThreadPoolExecutor;

@ -17,6 +17,7 @@
package cn.hippo4j.core.executor.support.adpter;
import cn.hippo4j.common.api.DynamicThreadPoolAdapter;
import cn.hippo4j.common.toolkit.ReflectUtil;
import cn.hippo4j.core.executor.DynamicThreadPoolExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@ -19,6 +19,7 @@ package cn.hippo4j.core.executor.state;
import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry;
import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
import cn.hippo4j.common.support.AbstractThreadPoolRuntime;
import cn.hippo4j.core.executor.DynamicThreadPoolExecutor;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;

@ -19,6 +19,7 @@ package cn.hippo4j.core.executor.state;
import cn.hippo4j.common.executor.ThreadPoolExecutorHolder;
import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry;
import cn.hippo4j.common.handler.ThreadPoolStatusHandler;
import cn.hippo4j.common.model.ManyThreadPoolRunStateInfo;
import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
import cn.hippo4j.common.toolkit.BeanUtil;

@ -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.SendMessageHandler;
import cn.hippo4j.threadpool.message.core.service.ThreadPoolBaseSendMessageService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
/**
* Message configuration.
*/
@ConditionalOnProperty(prefix = "spring.dynamic.thread-pool", value = "enable", matchIfMissing = true, havingValue = "true")
public class MessageConfiguration {
@Bean

@ -18,8 +18,9 @@
package cn.hippo4j.monitor.base;
import cn.hippo4j.adapter.base.ThreadPoolAdapter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
import cn.hippo4j.common.model.ThreadPoolAdapterState;
import cn.hippo4j.core.config.ApplicationContextHolder;
import cn.hippo4j.threadpool.monitor.api.AdapterThreadPoolMonitor;
import java.util.Map;

@ -20,6 +20,7 @@ package cn.hippo4j.monitor.base;
import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry;
import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler;
import cn.hippo4j.threadpool.monitor.api.DynamicThreadPoolMonitor;
import javax.annotation.Resource;
import java.util.List;
@ -29,9 +30,12 @@ import java.util.List;
*/
public abstract class AbstractDynamicThreadPoolMonitor implements DynamicThreadPoolMonitor {
@Resource
private ThreadPoolRunStateHandler threadPoolRunStateHandler;
public AbstractDynamicThreadPoolMonitor(ThreadPoolRunStateHandler handler) {
this.threadPoolRunStateHandler = handler;
}
/**
* Execute collection thread pool running data.
*

@ -19,6 +19,7 @@ package cn.hippo4j.monitor.base;
import cn.hippo4j.adapter.web.WebThreadPoolService;
import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
import cn.hippo4j.threadpool.monitor.api.WebThreadPoolMonitor;
import javax.annotation.Resource;

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

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

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

@ -17,10 +17,10 @@
package cn.hippo4j.monitor.local.log;
import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
import cn.hippo4j.common.model.ThreadPoolAdapterState;
import cn.hippo4j.common.toolkit.JSONUtil;
import cn.hippo4j.monitor.base.AbstractAdapterThreadPoolMonitor;
import cn.hippo4j.monitor.base.MonitorTypeEnum;
import cn.hippo4j.threadpool.monitor.support.MonitorTypeEnum;
import lombok.extern.slf4j.Slf4j;
/**

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

@ -20,7 +20,7 @@ package cn.hippo4j.monitor.local.log;
import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
import cn.hippo4j.common.toolkit.JSONUtil;
import cn.hippo4j.monitor.base.AbstractWebThreadPoolMonitor;
import cn.hippo4j.monitor.base.MonitorTypeEnum;
import cn.hippo4j.threadpool.monitor.support.MonitorTypeEnum;
import lombok.extern.slf4j.Slf4j;
/**

@ -17,12 +17,12 @@
package cn.hippo4j.monitor.micrometer;
import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
import cn.hippo4j.common.model.ThreadPoolAdapterState;
import cn.hippo4j.core.config.ApplicationContextHolder;
import cn.hippo4j.common.toolkit.BeanUtil;
import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.monitor.base.AbstractAdapterThreadPoolMonitor;
import cn.hippo4j.monitor.base.MonitorTypeEnum;
import cn.hippo4j.threadpool.monitor.support.MonitorTypeEnum;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Tag;
import org.springframework.core.env.Environment;

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

@ -22,7 +22,7 @@ import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
import cn.hippo4j.common.toolkit.BeanUtil;
import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.monitor.base.AbstractWebThreadPoolMonitor;
import cn.hippo4j.monitor.base.MonitorTypeEnum;
import cn.hippo4j.threadpool.monitor.support.MonitorTypeEnum;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Tag;
import org.springframework.core.env.Environment;

@ -18,7 +18,7 @@
package cn.hippo4j.config.service;
import cn.hippo4j.adapter.base.ThreadPoolAdapterCacheConfig;
import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
import cn.hippo4j.common.model.ThreadPoolAdapterState;
import cn.hippo4j.common.extension.design.AbstractSubjectCenter;
import cn.hippo4j.common.extension.design.Observer;
import cn.hippo4j.common.extension.design.ObserverMessage;

Loading…
Cancel
Save