From 96747a0b3dbadcaed929b9cc19aaa190baf7bf2a Mon Sep 17 00:00:00 2001 From: "chen.ma" Date: Mon, 1 Aug 2022 20:56:37 +0800 Subject: [PATCH] Dynamic thread pool monitoring module refactoring (#361) (#386) --- .../src/main/resources/bootstrap.properties | 2 +- hippo4j-monitor/hippo4j-monitor-base/pom.xml | 58 +++++++++++++++++ .../AbstractDynamicThreadPoolMonitor.java | 7 +- .../base}/DynamicThreadPoolMonitor.java | 5 +- .../example/monitor/base/MonitorTypeEnum.java | 26 ++++++++ .../monitor/base}/ThreadPoolMonitor.java | 5 +- hippo4j-monitor/hippo4j-monitor-log/pom.xml | 59 +++++++++++++++++ .../monitor/log}/LogMonitorHandler.java | 8 +-- .../hippo4j-monitor-prometheus/pom.xml | 65 +++++++++++++++++++ .../prometheus/PrometheusMonitorHandler.java | 16 ++--- hippo4j-monitor/pom.xml | 58 +++++++++++++++++ .../hippo4j-core-spring-boot-starter/pom.xml | 17 +++-- .../config/BootstrapCoreProperties.java | 4 +- ...ynamicThreadPoolCoreAutoConfiguration.java | 21 +----- .../config/MonitorHandlerConfiguration.java | 52 +++++++++++++++ .../config/condition/LogMonitorCondition.java | 37 +++++++++++ .../condition/PrometheusMonitorCondition.java | 37 +++++++++++ .../DynamicThreadPoolMonitorExecutor.java | 9 +-- .../hippo4j-spring-boot-starter/pom.xml | 6 ++ .../starter/config/BootstrapProperties.java | 8 +++ .../DynamicThreadPoolAutoConfiguration.java | 2 + .../config/MonitorHandlerConfiguration.java | 41 ++++++++++++ .../condition/PrometheusMonitorCondition.java | 37 +++++++++++ .../monitor/ReportingEventExecutor.java | 55 ++++++++++++---- pom.xml | 1 + 25 files changed, 561 insertions(+), 75 deletions(-) create mode 100644 hippo4j-monitor/hippo4j-monitor-base/pom.xml rename {hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/monitor => hippo4j-monitor/hippo4j-monitor-base/src/main/java/com/example/monitor/base}/AbstractDynamicThreadPoolMonitor.java (93%) rename {hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/monitor => hippo4j-monitor/hippo4j-monitor-base/src/main/java/com/example/monitor/base}/DynamicThreadPoolMonitor.java (90%) create mode 100644 hippo4j-monitor/hippo4j-monitor-base/src/main/java/com/example/monitor/base/MonitorTypeEnum.java rename {hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/monitor => hippo4j-monitor/hippo4j-monitor-base/src/main/java/com/example/monitor/base}/ThreadPoolMonitor.java (91%) create mode 100644 hippo4j-monitor/hippo4j-monitor-log/pom.xml rename {hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/monitor => hippo4j-monitor/hippo4j-monitor-log/src/main/java/cn/hippo4j/monitor/log}/LogMonitorHandler.java (92%) create mode 100644 hippo4j-monitor/hippo4j-monitor-prometheus/pom.xml rename hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/monitor/MetricMonitorHandler.java => hippo4j-monitor/hippo4j-monitor-prometheus/src/main/java/cn/hippo4j/monitor/prometheus/PrometheusMonitorHandler.java (92%) create mode 100644 hippo4j-monitor/pom.xml create mode 100644 hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/MonitorHandlerConfiguration.java create mode 100644 hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/condition/LogMonitorCondition.java create mode 100644 hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/condition/PrometheusMonitorCondition.java create mode 100644 hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/MonitorHandlerConfiguration.java create mode 100644 hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/condition/PrometheusMonitorCondition.java diff --git a/hippo4j-example/hippo4j-core-nacos-spring-boot-starter-example/src/main/resources/bootstrap.properties b/hippo4j-example/hippo4j-core-nacos-spring-boot-starter-example/src/main/resources/bootstrap.properties index 085bd572..c6c6be70 100644 --- a/hippo4j-example/hippo4j-core-nacos-spring-boot-starter-example/src/main/resources/bootstrap.properties +++ b/hippo4j-example/hippo4j-core-nacos-spring-boot-starter-example/src/main/resources/bootstrap.properties @@ -18,7 +18,7 @@ spring.cloud.nacos.config.extension-configs[0].refresh=true spring.dynamic.thread-pool.enable=true spring.dynamic.thread-pool.banner=true spring.dynamic.thread-pool.collect=true -spring.dynamic.thread-pool.collect-type=metric +spring.dynamic.thread-pool.collect-type=log,prometheus spring.dynamic.thread-pool.check-state-interval=5 spring.dynamic.thread-pool.notify-platforms[0].platform=WECHAT diff --git a/hippo4j-monitor/hippo4j-monitor-base/pom.xml b/hippo4j-monitor/hippo4j-monitor-base/pom.xml new file mode 100644 index 00000000..9aec021a --- /dev/null +++ b/hippo4j-monitor/hippo4j-monitor-base/pom.xml @@ -0,0 +1,58 @@ + + + 4.0.0 + + cn.hippo4j + hippo4j-monitor + ${revision} + + hippo4j-monitor-base + + + + cn.hippo4j + hippo4j-core + + + + + + + src/main/resources + + **/*.txt + **/*.json + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + ${project.artifactId} + ${project.version} + ${maven.build.timestamp} + chen.ma + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.3 + + + + jar + + + + + + + diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/monitor/AbstractDynamicThreadPoolMonitor.java b/hippo4j-monitor/hippo4j-monitor-base/src/main/java/com/example/monitor/base/AbstractDynamicThreadPoolMonitor.java similarity index 93% rename from hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/monitor/AbstractDynamicThreadPoolMonitor.java rename to hippo4j-monitor/hippo4j-monitor-base/src/main/java/com/example/monitor/base/AbstractDynamicThreadPoolMonitor.java index c93c73fc..ec36de7e 100644 --- a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/monitor/AbstractDynamicThreadPoolMonitor.java +++ b/hippo4j-monitor/hippo4j-monitor-base/src/main/java/com/example/monitor/base/AbstractDynamicThreadPoolMonitor.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package cn.hippo4j.core.springboot.starter.monitor; +package com.example.monitor.base; import cn.hippo4j.common.model.ThreadPoolRunStateInfo; import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; @@ -26,9 +26,6 @@ import java.util.List; /** * Abstract dynamic thread-pool monitor. - * - * @author chen.ma - * @date 2022/3/25 12:07 */ @RequiredArgsConstructor public abstract class AbstractDynamicThreadPoolMonitor implements DynamicThreadPoolMonitor { @@ -36,7 +33,7 @@ public abstract class AbstractDynamicThreadPoolMonitor implements DynamicThreadP private final ThreadPoolRunStateHandler threadPoolRunStateHandler; /** - * Execute. + * Execute collection thread pool running data. * * @param poolRunStateInfo */ diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/monitor/DynamicThreadPoolMonitor.java b/hippo4j-monitor/hippo4j-monitor-base/src/main/java/com/example/monitor/base/DynamicThreadPoolMonitor.java similarity index 90% rename from hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/monitor/DynamicThreadPoolMonitor.java rename to hippo4j-monitor/hippo4j-monitor-base/src/main/java/com/example/monitor/base/DynamicThreadPoolMonitor.java index eeaa2a65..171df74e 100644 --- a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/monitor/DynamicThreadPoolMonitor.java +++ b/hippo4j-monitor/hippo4j-monitor-base/src/main/java/com/example/monitor/base/DynamicThreadPoolMonitor.java @@ -15,13 +15,10 @@ * limitations under the License. */ -package cn.hippo4j.core.springboot.starter.monitor; +package com.example.monitor.base; /** * Dynamic thread-pool monitor. - * - * @author chen.ma - * @date 2022/3/25 19:03 */ public interface DynamicThreadPoolMonitor extends ThreadPoolMonitor { diff --git a/hippo4j-monitor/hippo4j-monitor-base/src/main/java/com/example/monitor/base/MonitorTypeEnum.java b/hippo4j-monitor/hippo4j-monitor-base/src/main/java/com/example/monitor/base/MonitorTypeEnum.java new file mode 100644 index 00000000..4907c8cc --- /dev/null +++ b/hippo4j-monitor/hippo4j-monitor-base/src/main/java/com/example/monitor/base/MonitorTypeEnum.java @@ -0,0 +1,26 @@ +/* + * 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 com.example.monitor.base; + +/** + * Monitor type enum. + */ +public enum MonitorTypeEnum { + + LOG, PROMETHEUS, SERVER +} diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/monitor/ThreadPoolMonitor.java b/hippo4j-monitor/hippo4j-monitor-base/src/main/java/com/example/monitor/base/ThreadPoolMonitor.java similarity index 91% rename from hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/monitor/ThreadPoolMonitor.java rename to hippo4j-monitor/hippo4j-monitor-base/src/main/java/com/example/monitor/base/ThreadPoolMonitor.java index 66cb6972..dc3d0c26 100644 --- a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/monitor/ThreadPoolMonitor.java +++ b/hippo4j-monitor/hippo4j-monitor-base/src/main/java/com/example/monitor/base/ThreadPoolMonitor.java @@ -15,13 +15,10 @@ * limitations under the License. */ -package cn.hippo4j.core.springboot.starter.monitor; +package com.example.monitor.base; /** * Thread-pool monitor. - * - * @author chen.ma - * @date 2022/3/25 19:03 */ public interface ThreadPoolMonitor { diff --git a/hippo4j-monitor/hippo4j-monitor-log/pom.xml b/hippo4j-monitor/hippo4j-monitor-log/pom.xml new file mode 100644 index 00000000..b2d454d7 --- /dev/null +++ b/hippo4j-monitor/hippo4j-monitor-log/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + + cn.hippo4j + hippo4j-monitor + ${revision} + + hippo4j-monitor-log + + + + cn.hippo4j + hippo4j-monitor-base + ${revision} + + + + + + + src/main/resources + + **/*.txt + **/*.json + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + ${project.artifactId} + ${project.version} + ${maven.build.timestamp} + chen.ma + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.3 + + + + jar + + + + + + + diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/monitor/LogMonitorHandler.java b/hippo4j-monitor/hippo4j-monitor-log/src/main/java/cn/hippo4j/monitor/log/LogMonitorHandler.java similarity index 92% rename from hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/monitor/LogMonitorHandler.java rename to hippo4j-monitor/hippo4j-monitor-log/src/main/java/cn/hippo4j/monitor/log/LogMonitorHandler.java index f6d0aee7..36c6a010 100644 --- a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/monitor/LogMonitorHandler.java +++ b/hippo4j-monitor/hippo4j-monitor-log/src/main/java/cn/hippo4j/monitor/log/LogMonitorHandler.java @@ -15,18 +15,16 @@ * limitations under the License. */ -package cn.hippo4j.core.springboot.starter.monitor; +package cn.hippo4j.monitor.log; import cn.hippo4j.common.model.ThreadPoolRunStateInfo; import cn.hippo4j.common.toolkit.JSONUtil; import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler; +import com.example.monitor.base.AbstractDynamicThreadPoolMonitor; import lombok.extern.slf4j.Slf4j; /** - * Log monitor handler. - * - * @author chen.ma - * @date 2022/3/25 19:22 + * Log monitor handler */ @Slf4j public class LogMonitorHandler extends AbstractDynamicThreadPoolMonitor { diff --git a/hippo4j-monitor/hippo4j-monitor-prometheus/pom.xml b/hippo4j-monitor/hippo4j-monitor-prometheus/pom.xml new file mode 100644 index 00000000..67acbaf0 --- /dev/null +++ b/hippo4j-monitor/hippo4j-monitor-prometheus/pom.xml @@ -0,0 +1,65 @@ + + + 4.0.0 + + cn.hippo4j + hippo4j-monitor + ${revision} + + hippo4j-monitor-prometheus + + + + cn.hippo4j + hippo4j-monitor-base + ${revision} + + + + io.micrometer + micrometer-core + ${micrometer-core.version} + + + + + + + src/main/resources + + **/*.txt + **/*.json + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + ${project.artifactId} + ${project.version} + ${maven.build.timestamp} + chen.ma + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.3 + + + + jar + + + + + + + diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/monitor/MetricMonitorHandler.java b/hippo4j-monitor/hippo4j-monitor-prometheus/src/main/java/cn/hippo4j/monitor/prometheus/PrometheusMonitorHandler.java similarity index 92% rename from hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/monitor/MetricMonitorHandler.java rename to hippo4j-monitor/hippo4j-monitor-prometheus/src/main/java/cn/hippo4j/monitor/prometheus/PrometheusMonitorHandler.java index 25b8cdbe..95ccc803 100644 --- a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/monitor/MetricMonitorHandler.java +++ b/hippo4j-monitor/hippo4j-monitor-prometheus/src/main/java/cn/hippo4j/monitor/prometheus/PrometheusMonitorHandler.java @@ -15,12 +15,13 @@ * limitations under the License. */ -package cn.hippo4j.core.springboot.starter.monitor; +package cn.hippo4j.monitor.prometheus; import cn.hippo4j.common.config.ApplicationContextHolder; import cn.hippo4j.common.model.ThreadPoolRunStateInfo; import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler; import cn.hutool.core.bean.BeanUtil; +import com.example.monitor.base.AbstractDynamicThreadPoolMonitor; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import io.micrometer.core.instrument.Metrics; @@ -30,12 +31,9 @@ import org.springframework.core.env.Environment; import java.util.Map; /** - * Metric monitor handler. - * - * @author chen.ma - * @date 2022/3/25 20:37 + * Prometheus monitor handler. */ -public class MetricMonitorHandler extends AbstractDynamicThreadPoolMonitor { +public class PrometheusMonitorHandler extends AbstractDynamicThreadPoolMonitor { private final static String METRIC_NAME_PREFIX = "dynamic.thread-pool"; @@ -45,7 +43,7 @@ public class MetricMonitorHandler extends AbstractDynamicThreadPoolMonitor { private final Map RUN_STATE_CACHE = Maps.newConcurrentMap(); - public MetricMonitorHandler(ThreadPoolRunStateHandler threadPoolRunStateHandler) { + public PrometheusMonitorHandler(ThreadPoolRunStateHandler threadPoolRunStateHandler) { super(threadPoolRunStateHandler); } @@ -57,13 +55,11 @@ public class MetricMonitorHandler extends AbstractDynamicThreadPoolMonitor { } else { BeanUtil.copyProperties(poolRunStateInfo, stateInfo); } - Environment environment = ApplicationContextHolder.getInstance().getEnvironment(); String applicationName = environment.getProperty("spring.application.name", "application"); Iterable tags = Lists.newArrayList( Tag.of(DYNAMIC_THREAD_POOL_ID_TAG, poolRunStateInfo.getTpId()), Tag.of(APPLICATION_NAME_TAG, applicationName)); - // load Metrics.gauge(metricName("current.load"), tags, poolRunStateInfo, ThreadPoolRunStateInfo::getSimpleCurrentLoad); Metrics.gauge(metricName("peak.load"), tags, poolRunStateInfo, ThreadPoolRunStateInfo::getSimplePeakLoad); @@ -88,6 +84,6 @@ public class MetricMonitorHandler extends AbstractDynamicThreadPoolMonitor { @Override public String getType() { - return "metric"; + return "prometheus"; } } diff --git a/hippo4j-monitor/pom.xml b/hippo4j-monitor/pom.xml new file mode 100644 index 00000000..386cbaf2 --- /dev/null +++ b/hippo4j-monitor/pom.xml @@ -0,0 +1,58 @@ + + + 4.0.0 + + cn.hippo4j + hippo4j-all + ${revision} + + hippo4j-monitor + pom + + + hippo4j-monitor-base + hippo4j-monitor-log + hippo4j-monitor-prometheus + + + + + + src/main/resources + + **/*.txt + **/*.json + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + ${project.artifactId} + ${project.version} + ${maven.build.timestamp} + chen.ma + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.3 + + + + jar + + + + + + + diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/pom.xml b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/pom.xml index 032e4ce7..b0413e06 100644 --- a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/pom.xml +++ b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/pom.xml @@ -63,20 +63,25 @@ - io.micrometer - micrometer-core - ${micrometer-core.version} - true + cn.hippo4j + hippo4j-adapter-base cn.hippo4j - hippo4j-adapter-base + hippo4j-spring-boot-starter-adapter-web cn.hippo4j - hippo4j-spring-boot-starter-adapter-web + hippo4j-monitor-log + ${revision} + + + + cn.hippo4j + hippo4j-monitor-prometheus + ${revision} diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/BootstrapCoreProperties.java b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/BootstrapCoreProperties.java index d93e8f4d..8f6a9e50 100644 --- a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/BootstrapCoreProperties.java +++ b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/BootstrapCoreProperties.java @@ -18,8 +18,8 @@ package cn.hippo4j.core.springboot.starter.config; import cn.hippo4j.core.config.BootstrapPropertiesInterface; -import cn.hippo4j.core.springboot.starter.monitor.DynamicThreadPoolMonitor; import cn.hippo4j.core.springboot.starter.parser.ConfigFileTypeEnum; +import com.example.monitor.base.DynamicThreadPoolMonitor; import lombok.Getter; import lombok.Setter; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -56,7 +56,7 @@ public class BootstrapCoreProperties implements BootstrapPropertiesInterface { private Boolean collect = Boolean.TRUE; /** - * Type of collection thread pool running data. eg: log,metric. Multiple can be used at the same time. + * Type of collection thread pool running data. eg: log,prometheus. Multiple can be used at the same time. * Custom SPI support {@link DynamicThreadPoolMonitor}. */ private String collectType; diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/DynamicThreadPoolCoreAutoConfiguration.java b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/DynamicThreadPoolCoreAutoConfiguration.java index d2d28cb9..dbbc7107 100644 --- a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/DynamicThreadPoolCoreAutoConfiguration.java +++ b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/DynamicThreadPoolCoreAutoConfiguration.java @@ -21,11 +21,8 @@ import cn.hippo4j.common.config.ApplicationContextHolder; import cn.hippo4j.core.config.UtilAutoConfiguration; import cn.hippo4j.core.enable.MarkerConfiguration; import cn.hippo4j.core.executor.ThreadPoolNotifyAlarmHandler; -import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler; import cn.hippo4j.core.handler.DynamicThreadPoolBannerHandler; import cn.hippo4j.core.springboot.starter.monitor.DynamicThreadPoolMonitorExecutor; -import cn.hippo4j.core.springboot.starter.monitor.LogMonitorHandler; -import cn.hippo4j.core.springboot.starter.monitor.MetricMonitorHandler; import cn.hippo4j.core.springboot.starter.notify.CoreNotifyConfigBuilder; import cn.hippo4j.core.springboot.starter.refresher.event.AdapterExecutorsListener; import cn.hippo4j.core.springboot.starter.refresher.event.ExecutorsListener; @@ -51,10 +48,7 @@ import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; /** - * Dynamic thread-pool auto configuration. - * - * @author chen.ma - * @date 2022/2/25 00:21 + * Dynamic thread-pool core auto-configuration. */ @Configuration @AllArgsConstructor @@ -64,7 +58,8 @@ import org.springframework.core.annotation.Order; @ConditionalOnProperty(prefix = BootstrapCoreProperties.PREFIX, value = "enable", matchIfMissing = true, havingValue = "true") @Import({ ConfigHandlerConfiguration.EmbeddedNacos.class, ConfigHandlerConfiguration.EmbeddedNacosCloud.class, - ConfigHandlerConfiguration.EmbeddedApollo.class, ConfigHandlerConfiguration.EmbeddedZookeeper.class + ConfigHandlerConfiguration.EmbeddedApollo.class, ConfigHandlerConfiguration.EmbeddedZookeeper.class, + MonitorHandlerConfiguration.EmbeddedLogMonitor.class, MonitorHandlerConfiguration.EmbeddedPrometheusMonitor.class }) public class DynamicThreadPoolCoreAutoConfiguration { @@ -97,16 +92,6 @@ public class DynamicThreadPoolCoreAutoConfiguration { return new DynamicThreadPoolMonitorExecutor(bootstrapCoreProperties); } - @Bean - public LogMonitorHandler hippo4jLogMonitorHandler(ThreadPoolRunStateHandler threadPoolRunStateHandler) { - return new LogMonitorHandler(threadPoolRunStateHandler); - } - - @Bean - public MetricMonitorHandler hippo4jMetricMonitorHandler(ThreadPoolRunStateHandler threadPoolRunStateHandler) { - return new MetricMonitorHandler(threadPoolRunStateHandler); - } - @Bean @SuppressWarnings("all") public ExecutorsListener hippo4jExecutorsListener(ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler, diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/MonitorHandlerConfiguration.java b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/MonitorHandlerConfiguration.java new file mode 100644 index 00000000..28f0b77b --- /dev/null +++ b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/MonitorHandlerConfiguration.java @@ -0,0 +1,52 @@ +/* + * 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.core.springboot.starter.config; + +import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler; +import cn.hippo4j.core.springboot.starter.config.condition.LogMonitorCondition; +import cn.hippo4j.core.springboot.starter.config.condition.PrometheusMonitorCondition; +import cn.hippo4j.monitor.log.LogMonitorHandler; +import cn.hippo4j.monitor.prometheus.PrometheusMonitorHandler; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; + +/** + * Monitor handler configuration. + */ +@Configuration(proxyBeanMethods = false) +public class MonitorHandlerConfiguration { + + @Conditional(LogMonitorCondition.class) + static class EmbeddedLogMonitor { + + @Bean + public LogMonitorHandler logMonitorHandler(ThreadPoolRunStateHandler threadPoolRunStateHandler) { + return new LogMonitorHandler(threadPoolRunStateHandler); + } + } + + @Conditional(PrometheusMonitorCondition.class) + static class EmbeddedPrometheusMonitor { + + @Bean + public PrometheusMonitorHandler prometheusMonitorHandler(ThreadPoolRunStateHandler threadPoolRunStateHandler) { + return new PrometheusMonitorHandler(threadPoolRunStateHandler); + } + } +} diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/condition/LogMonitorCondition.java b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/condition/LogMonitorCondition.java new file mode 100644 index 00000000..d3a8e4f8 --- /dev/null +++ b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/condition/LogMonitorCondition.java @@ -0,0 +1,37 @@ +/* + * 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.core.springboot.starter.config.condition; + +import cn.hippo4j.common.toolkit.StringUtil; +import cn.hippo4j.core.springboot.starter.config.BootstrapCoreProperties; +import com.example.monitor.base.MonitorTypeEnum; +import org.springframework.context.annotation.Condition; +import org.springframework.context.annotation.ConditionContext; +import org.springframework.core.type.AnnotatedTypeMetadata; + +/** + * Log monitor condition. + */ +public class LogMonitorCondition implements Condition { + + @Override + public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { + String collectType = context.getEnvironment().getProperty(BootstrapCoreProperties.PREFIX + ".collect-type", ""); + return StringUtil.isNotEmpty(collectType) && collectType.contains(MonitorTypeEnum.LOG.name().toLowerCase()) ? true : false; + } +} diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/condition/PrometheusMonitorCondition.java b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/condition/PrometheusMonitorCondition.java new file mode 100644 index 00000000..5db7b9dc --- /dev/null +++ b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/condition/PrometheusMonitorCondition.java @@ -0,0 +1,37 @@ +/* + * 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.core.springboot.starter.config.condition; + +import cn.hippo4j.common.toolkit.StringUtil; +import cn.hippo4j.core.springboot.starter.config.BootstrapCoreProperties; +import com.example.monitor.base.MonitorTypeEnum; +import org.springframework.context.annotation.Condition; +import org.springframework.context.annotation.ConditionContext; +import org.springframework.core.type.AnnotatedTypeMetadata; + +/** + * Prometheus monitor condition. + */ +public class PrometheusMonitorCondition implements Condition { + + @Override + public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { + String collectType = context.getEnvironment().getProperty(BootstrapCoreProperties.PREFIX + "collect-type", ""); + return StringUtil.isNotEmpty(collectType) && collectType.contains(MonitorTypeEnum.PROMETHEUS.name().toLowerCase()) ? true : false; + } +} diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/monitor/DynamicThreadPoolMonitorExecutor.java b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/monitor/DynamicThreadPoolMonitorExecutor.java index f75c8fa6..a489022d 100644 --- a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/monitor/DynamicThreadPoolMonitorExecutor.java +++ b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/monitor/DynamicThreadPoolMonitorExecutor.java @@ -22,6 +22,8 @@ import cn.hippo4j.common.toolkit.StringUtil; import cn.hippo4j.core.executor.support.ThreadFactoryBuilder; import cn.hippo4j.core.spi.DynamicThreadPoolServiceLoader; import cn.hippo4j.core.springboot.starter.config.BootstrapCoreProperties; +import com.example.monitor.base.DynamicThreadPoolMonitor; +import com.example.monitor.base.ThreadPoolMonitor; import com.google.common.collect.Lists; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -56,15 +58,11 @@ public class DynamicThreadPoolMonitorExecutor implements ApplicationRunner { if (!properties.getCollect() || StringUtil.isBlank(collectType)) { return; } - log.info("Start monitoring the running status of dynamic thread pool."); threadPoolMonitors = Lists.newArrayList(); - - String collectTaskName = "client.scheduled.collect.data"; collectExecutor = new ScheduledThreadPoolExecutor( new Integer(1), - ThreadFactoryBuilder.builder().daemon(true).prefix(collectTaskName).build()); - + ThreadFactoryBuilder.builder().daemon(true).prefix("client.scheduled.collect.data").build()); // Get dynamic thread pool monitoring component. List collectTypes = Arrays.asList(collectType.split(",")); ApplicationContextHolder.getBeansOfType(ThreadPoolMonitor.class) @@ -76,7 +74,6 @@ public class DynamicThreadPoolMonitorExecutor implements ApplicationRunner { Collection dynamicThreadPoolMonitors = DynamicThreadPoolServiceLoader.getSingletonServiceInstances(DynamicThreadPoolMonitor.class); dynamicThreadPoolMonitors.stream().filter(each -> collectTypes.contains(each.getType())).forEach(each -> threadPoolMonitors.add(each)); - // Execute dynamic thread pool monitoring component. collectExecutor.scheduleWithFixedDelay( () -> scheduleRunnable(), diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/pom.xml b/hippo4j-spring-boot/hippo4j-spring-boot-starter/pom.xml index 79cdc118..4c97def7 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/pom.xml +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/pom.xml @@ -96,6 +96,12 @@ cn.hippo4j hippo4j-spring-boot-starter-adapter-web + + + cn.hippo4j + hippo4j-monitor-prometheus + ${revision} + diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/BootstrapProperties.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/BootstrapProperties.java index d167eac3..73d6c0b9 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/BootstrapProperties.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/BootstrapProperties.java @@ -18,6 +18,7 @@ package cn.hippo4j.springboot.starter.config; import cn.hippo4j.core.config.BootstrapPropertiesInterface; +import com.example.monitor.base.DynamicThreadPoolMonitor; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; @@ -61,6 +62,7 @@ public class BootstrapProperties implements BootstrapPropertiesInterface { * Report type */ private String reportType; + /** * Namespace */ @@ -86,6 +88,12 @@ public class BootstrapProperties implements BootstrapPropertiesInterface { */ private Boolean collect = true; + /** + * Type of collection thread pool running data. eg: server,prometheus. Multiple can be used at the same time. + * Custom SPI support {@link DynamicThreadPoolMonitor}. + */ + private String collectType; + /** * Task buffer container capacity */ diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java index 359bbb62..683dadeb 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java @@ -53,6 +53,7 @@ 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; +import org.springframework.context.annotation.Import; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; import org.springframework.core.env.ConfigurableEnvironment; @@ -69,6 +70,7 @@ import org.springframework.core.env.ConfigurableEnvironment; @EnableConfigurationProperties(BootstrapProperties.class) @ConditionalOnProperty(prefix = BootstrapProperties.PREFIX, value = "enable", matchIfMissing = true, havingValue = "true") @ImportAutoConfiguration({HttpClientConfiguration.class, NettyClientConfiguration.class, DiscoveryConfiguration.class, MessageConfiguration.class, UtilAutoConfiguration.class}) +@Import(MonitorHandlerConfiguration.EmbeddedPrometheusMonitor.class) public class DynamicThreadPoolAutoConfiguration { private final BootstrapProperties properties; diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/MonitorHandlerConfiguration.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/MonitorHandlerConfiguration.java new file mode 100644 index 00000000..ab556baa --- /dev/null +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/MonitorHandlerConfiguration.java @@ -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.springboot.starter.config; + +import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler; +import cn.hippo4j.monitor.prometheus.PrometheusMonitorHandler; +import cn.hippo4j.springboot.starter.config.condition.PrometheusMonitorCondition; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; + +/** + * Monitor handler configuration. + */ +@Configuration(proxyBeanMethods = false) +public class MonitorHandlerConfiguration { + + @Conditional(PrometheusMonitorCondition.class) + static class EmbeddedPrometheusMonitor { + + @Bean + public PrometheusMonitorHandler prometheusMonitorHandler(ThreadPoolRunStateHandler threadPoolRunStateHandler) { + return new PrometheusMonitorHandler(threadPoolRunStateHandler); + } + } +} diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/condition/PrometheusMonitorCondition.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/condition/PrometheusMonitorCondition.java new file mode 100644 index 00000000..7bde825f --- /dev/null +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/condition/PrometheusMonitorCondition.java @@ -0,0 +1,37 @@ +/* + * 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.springboot.starter.config.condition; + +import cn.hippo4j.common.toolkit.StringUtil; +import cn.hippo4j.springboot.starter.config.BootstrapProperties; +import com.example.monitor.base.MonitorTypeEnum; +import org.springframework.context.annotation.Condition; +import org.springframework.context.annotation.ConditionContext; +import org.springframework.core.type.AnnotatedTypeMetadata; + +/** + * Prometheus monitor condition. + */ +public class PrometheusMonitorCondition implements Condition { + + @Override + public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { + String collectType = context.getEnvironment().getProperty(BootstrapProperties.PREFIX + ".collect-type", ""); + return StringUtil.isNotEmpty(collectType) && collectType.contains(MonitorTypeEnum.PROMETHEUS.name().toLowerCase()) ? true : false; + } +} diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/monitor/ReportingEventExecutor.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/monitor/ReportingEventExecutor.java index 9650cee6..acc4fd89 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/monitor/ReportingEventExecutor.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/monitor/ReportingEventExecutor.java @@ -19,13 +19,17 @@ package cn.hippo4j.springboot.starter.monitor; import cn.hippo4j.common.config.ApplicationContextHolder; import cn.hippo4j.common.monitor.Message; +import cn.hippo4j.common.toolkit.ThreadUtil; +import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; +import cn.hippo4j.core.executor.support.ThreadFactoryBuilder; import cn.hippo4j.springboot.starter.config.BootstrapProperties; import cn.hippo4j.springboot.starter.monitor.collect.Collector; -import cn.hippo4j.springboot.starter.remote.ServerHealthCheck; import cn.hippo4j.springboot.starter.monitor.send.MessageSender; -import cn.hippo4j.core.executor.support.ThreadFactoryBuilder; -import cn.hippo4j.common.toolkit.ThreadUtil; +import cn.hippo4j.springboot.starter.remote.ServerHealthCheck; import cn.hutool.core.collection.CollUtil; +import com.example.monitor.base.MonitorTypeEnum; +import com.example.monitor.base.ThreadPoolMonitor; +import com.google.common.base.Strings; import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; @@ -68,6 +72,11 @@ public class ReportingEventExecutor implements Runnable, CommandLineRunner, Disp */ private Map collectors; + /** + * Thread pool monitoring collection. + */ + private Map threadPoolMonitors; + /** * Buffer container for data collection, waiting * for ReportingEventExecutor to report to the server. @@ -95,25 +104,39 @@ public class ReportingEventExecutor implements Runnable, CommandLineRunner, Disp @Override public void run(String... args) { - if (properties.getCollect()) { - Integer bufferSize = properties.getTaskBufferSize(); - messageCollectVessel = new ArrayBlockingQueue(bufferSize); - String collectVesselTaskName = "client.scheduled.collect.data"; - collectVesselExecutor = new ScheduledThreadPoolExecutor( - new Integer(1), - ThreadFactoryBuilder.builder().daemon(true).prefix(collectVesselTaskName).build()); + if (!properties.getCollect()) { + return; + } + String collectType = Optional.ofNullable(Strings.emptyToNull(properties.getCollectType())).orElse(MonitorTypeEnum.SERVER.name().toLowerCase()); + collectVesselExecutor = new ScheduledThreadPoolExecutor( + new Integer(collectType.split(",").length), + ThreadFactoryBuilder.builder().daemon(true).prefix("client.scheduled.collect.data").build()); + if (collectType.contains(MonitorTypeEnum.PROMETHEUS.name().toLowerCase()) + || collectType.contains(MonitorTypeEnum.LOG.name().toLowerCase())) { + // Get all dynamic thread pool monitoring components. + threadPoolMonitors = ApplicationContextHolder.getBeansOfType(ThreadPoolMonitor.class); + collectVesselExecutor.scheduleWithFixedDelay( + () -> dynamicThreadPoolMonitor(), + properties.getInitialDelay(), + properties.getCollectInterval(), + TimeUnit.MILLISECONDS); + } + if (collectType.contains(MonitorTypeEnum.SERVER.name().toLowerCase())) { collectVesselExecutor.scheduleWithFixedDelay( () -> runTimeGatherTask(), properties.getInitialDelay(), properties.getCollectInterval(), TimeUnit.MILLISECONDS); - // Start reporting monitoring data thread - String reportingTaskName = "client.thread.reporting.task"; - ThreadUtil.newThread(this, reportingTaskName, Boolean.TRUE).start(); + Integer bufferSize = properties.getTaskBufferSize(); + messageCollectVessel = new ArrayBlockingQueue(bufferSize); // Get all data collection components, currently only historical operation data collection. collectors = ApplicationContextHolder.getBeansOfType(Collector.class); + // Start reporting monitoring data thread. + ThreadUtil.newThread(this, "client.thread.reporting.task", Boolean.TRUE).start(); + } + if (GlobalThreadPoolManage.getThreadPoolNum() > 0) { + log.info("Dynamic thread pool :: [{}]. The dynamic thread pool starts data collection and reporting. ", getThreadPoolNum()); } - log.info("Dynamic thread pool :: [{}]. The dynamic thread pool starts data collection and reporting. ", getThreadPoolNum()); } @Override @@ -121,6 +144,10 @@ public class ReportingEventExecutor implements Runnable, CommandLineRunner, Disp Optional.ofNullable(collectVesselExecutor).ifPresent((each) -> each.shutdown()); } + private void dynamicThreadPoolMonitor() { + threadPoolMonitors.forEach((beanName, monitor) -> monitor.collect()); + } + /** * Collect dynamic thread pool data and add buffer queues. */ diff --git a/pom.xml b/pom.xml index 29f8ee86..88be63ec 100644 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,7 @@ hippo4j-discovery hippo4j-example hippo4j-message + hippo4j-monitor hippo4j-server hippo4j-spring-boot hippo4j-tool