mirror of https://github.com/longtai-cn/hippo4j
commit
ea729ad2cf
@ -0,0 +1,56 @@
|
||||
<img align="center" width="400" alt="image" src="https://user-images.githubusercontent.com/77398366/181906454-b46f6a14-7c2c-4b8f-8b0a-40432521bed8.png">
|
||||
|
||||
# Dynamic and observable thread pool framework
|
||||
|
||||
[](https://gitee.com/itmachen/hippo4j) [](https://github.com/opengoofy/hippo4j) [](https://store.docker.com/community/images/hippo4j/hippo4j-server) [](https://github.com/opengoofy/hippo4j/graphs/contributors) [](https://github.com/opengoofy/hippo4j/blob/develop/LICENSE)
|
||||
|
||||
-------
|
||||
|
||||
## Thread pool pain points
|
||||
|
||||
A thread pool is a tool for managing threads based on the idea of pooling.
|
||||
|
||||
Using a thread pool reduces the overhead of creating and destroying threads and avoids running out of system resources due to too many threads.
|
||||
|
||||
The use of thread pools is essential in highly concurrent and high-volume task processing scenarios.
|
||||
|
||||
If you have actually used thread pools in your projects, I believe you may have encountered the following pain points:
|
||||
|
||||
- Thread pools are defined randomly, with too many thread resources, causing high server load.
|
||||
|
||||
- The thread pool parameters are not easily evaluated and the business is at risk of failure.
|
||||
- Thread pool task execution time exceeds the average execution cycle and developers are not informed.
|
||||
- Thread pool tasks pile up and affect business operations.
|
||||
- Wireless process pool monitoring when the service has timeouts, meltdowns, and other problems.
|
||||
- Thread pools do not support the passing of runtime variables, such as MDC contexts.
|
||||
- When a project is closed, a large number of running thread pool tasks are discarded.
|
||||
- Thread pool running, task execution stopped, don't know the problem.
|
||||
|
||||
## What is Hippo-4J
|
||||
|
||||
Hippo-4J through the JDK thread pool enhancements, as well as extending the three-party framework underlying thread pools and other features for business systems to improve online operational security capabilities.
|
||||
|
||||
The following functional support is provided:
|
||||
|
||||
- Global Control - Managing Application Thread Pool Instances.
|
||||
|
||||
- Dynamic changes - dynamically changing thread pool parameters at application runtime.
|
||||
- Notify alarms - Four built-in alarm notification policies.
|
||||
- Run Monitoring - Real-time view of thread pool runtime data.
|
||||
- Feature extensions - support for thread pooling task passing contexts, etc.
|
||||
- Multiple Modes - Two built-in usage modes: Configuration Center Mode and No Middleware Mode.
|
||||
- Container Management - Tomcat, Jetty, Undertow container thread pool runtime view and thread count changes.
|
||||
- Framework adaptation - Dubbo, Hystrix, Polaris, RabbitMQ, RocketMQ and other consumer thread pool runtime data view and thread count changes.
|
||||
|
||||
## Quick Start
|
||||
|
||||
For local presentation purposes, see [Quick start](https://hippo4j.cn/docs/user_docs/user_guide/quick-start).
|
||||
|
||||
Demo Environment: [http://console.hippo4j.cn/index.html](http://console.hippo4j.cn/index.html).
|
||||
|
||||
## Who is using
|
||||
|
||||
More companies with access are welcome to register at [registration address](https://github.com/opengoofy/hippo4j/issues/13), registration is only for product promotion.
|
||||
|
||||
## Contributors
|
||||
Thanks to all the developers who contributed to the project. If interested in contributing, refer to [good first issue](https://github.com/opengoofy/hippo4j/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22).
|
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* 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.toolkit;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.MemoryMXBean;
|
||||
import java.lang.management.MemoryUsage;
|
||||
|
||||
/**
|
||||
* memory util<br>
|
||||
* the obtained information is not invalid, after a long wait, obtain it again
|
||||
*
|
||||
* @author liuwenhao
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class MemoryUtil {
|
||||
|
||||
static MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
|
||||
static MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage();
|
||||
static MemoryUsage noHeapMemoryUsage = memoryMXBean.getNonHeapMemoryUsage();
|
||||
|
||||
/**
|
||||
* get used memory in heap
|
||||
*
|
||||
* @return long bytes
|
||||
*/
|
||||
public static long heapMemoryUsed() {
|
||||
return heapMemoryUsage.getUsed();
|
||||
}
|
||||
|
||||
/**
|
||||
* get max memory in heap
|
||||
*
|
||||
* @return long bytes
|
||||
*/
|
||||
public static long heapMemoryMax() {
|
||||
return heapMemoryUsage.getMax();
|
||||
}
|
||||
|
||||
/**
|
||||
* get free memory in heap
|
||||
*
|
||||
* @return long bytes
|
||||
*/
|
||||
public static long heapMemoryFree() {
|
||||
return Math.subtractExact(heapMemoryMax(), heapMemoryUsed());
|
||||
}
|
||||
|
||||
/**
|
||||
* get used memory in no-heap
|
||||
*
|
||||
* @return long bytes
|
||||
*/
|
||||
public static long noHeapMemoryUsed() {
|
||||
return noHeapMemoryUsage.getUsed();
|
||||
}
|
||||
|
||||
/**
|
||||
* get max memory in no-heap
|
||||
*
|
||||
* @return long bytes
|
||||
*/
|
||||
public static long noHeapMemoryMax() {
|
||||
return noHeapMemoryUsage.getMax();
|
||||
}
|
||||
|
||||
/**
|
||||
* get free memory in no-heap
|
||||
*
|
||||
* @return long bytes
|
||||
*/
|
||||
public static long noHeapMemoryFree() {
|
||||
return Math.subtractExact(noHeapMemoryMax(), noHeapMemoryUsed());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.toolkit;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MemoryUtilTest {
|
||||
|
||||
@Test
|
||||
public void heapMemoryUsed() {
|
||||
long memoryUsed = MemoryUtil.heapMemoryUsed();
|
||||
Assert.assertNotEquals(0, memoryUsed);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void heapMemoryMax() {
|
||||
long memoryUsed = MemoryUtil.heapMemoryMax();
|
||||
Assert.assertNotEquals(0, memoryUsed);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void heapMemoryFree() {
|
||||
long memoryUsed = MemoryUtil.heapMemoryFree();
|
||||
Assert.assertNotEquals(0, memoryUsed);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noHeapMemoryUsed() {
|
||||
long memoryUsed = MemoryUtil.noHeapMemoryUsed();
|
||||
Assert.assertNotEquals(0, memoryUsed);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noHeapMemoryMax() {
|
||||
long memoryUsed = MemoryUtil.noHeapMemoryMax();
|
||||
Assert.assertNotEquals(0, memoryUsed);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noHeapMemoryFree() {
|
||||
long memoryUsed = MemoryUtil.noHeapMemoryFree();
|
||||
Assert.assertNotEquals(0, memoryUsed);
|
||||
}
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
/*
|
||||
* 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.toolkit;
|
||||
|
||||
import cn.hippo4j.common.toolkit.CollectionUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
/**
|
||||
* Map util.
|
||||
*/
|
||||
public class MapUtil {
|
||||
|
||||
public static Object computeIfAbsent(Map target, Object key, BiFunction mappingFunction, Object param1, Object param2) {
|
||||
Objects.requireNonNull(target, "target");
|
||||
Objects.requireNonNull(key, "key");
|
||||
Objects.requireNonNull(mappingFunction, "mappingFunction");
|
||||
Objects.requireNonNull(param1, "param1");
|
||||
Objects.requireNonNull(param2, "param2");
|
||||
Object val = target.get(key);
|
||||
if (val == null) {
|
||||
Object ret = mappingFunction.apply(param1, param2);
|
||||
target.put(key, ret);
|
||||
return ret;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fuzzy matching based on Key.
|
||||
*
|
||||
* @param sourceMap
|
||||
* @param filters
|
||||
* @return
|
||||
*/
|
||||
public static List<String> parseMapForFilter(Map<String, ?> sourceMap, String filters) {
|
||||
List<String> resultList = new ArrayList<>();
|
||||
if (CollectionUtil.isEmpty(sourceMap)) {
|
||||
return resultList;
|
||||
}
|
||||
sourceMap.forEach((key, val) -> {
|
||||
if (checkKey(key, filters)) {
|
||||
resultList.add(key);
|
||||
}
|
||||
});
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Match the characters you want to query.
|
||||
*
|
||||
* @param key
|
||||
* @param filters
|
||||
* @return
|
||||
*/
|
||||
private static boolean checkKey(String key, String filters) {
|
||||
if (key.indexOf(filters) > -1) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
.editor-container[data-v-7505e034]{height:82vh;overflow:auto}
|
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 35 KiB |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-2fd02e04"],{"64b7":function(e,t,n){"use strict";n("de5f")},ab3b:function(e,t,n){"use strict";n.r(t);var a=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{staticClass:"app-container"},[n("split-pane",{attrs:{split:"vertical"},on:{resize:e.resize}},[n("template",{slot:"paneL"},[n("el-input",{attrs:{type:"textarea",rows:36,placeholder:"请输入内容",clearable:""},on:{change:e.originChange},model:{value:e.originText,callback:function(t){e.originText=t},expression:"originText"}})],1),e._v(" "),n("template",{slot:"paneR"},[n("div",{staticClass:"editor-container"},[n("JSONEditor",{attrs:{json:e.formatedValue}})],1)])],2)],1)},i=[],o=n("19ab"),r=n.n(o),s=n("33c3"),c={name:"JsonFormat",components:{splitPane:r.a,JSONEditor:s["a"]},data:function(){return{originText:"",formatedValue:""}},watch:{originText:function(e){try{this.formatedValue=JSON.parse(e)}catch(t){}}},methods:{resize:function(){},originChange:function(e){}}},l=c,u=(n("64b7"),n("2877")),p=Object(u["a"])(l,a,i,!1,null,"7505e034",null);t["default"]=p.exports},de5f:function(e,t,n){}}]);
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,52 @@
|
||||
# \u4EE5\u4E0B\u5185\u5BB9\u590D\u5236\u5230 apollo \u914D\u7F6E\u6587\u4EF6\u4E2D
|
||||
# Copy the following to the apollo configuration file
|
||||
|
||||
spring.dynamic.thread-pool.tomcat.core-pool-size=64
|
||||
spring.dynamic.thread-pool.tomcat.maximum-pool-size=128
|
||||
spring.dynamic.thread-pool.tomcat.keep-alive-time=1000
|
||||
spring.dynamic.thread-pool.tomcat.enable=true
|
||||
spring.dynamic.thread-pool.default-executor.core-pool-size=1
|
||||
spring.dynamic.thread-pool.default-executor.maximum-pool-size=2
|
||||
spring.dynamic.thread-pool.default-executor.blocking-queue=ResizableCapacityLinkedBlockingQueue
|
||||
spring.dynamic.thread-pool.default-executor.execute-time-out=100
|
||||
spring.dynamic.thread-pool.default-executor.keep-alive-time=6691
|
||||
spring.dynamic.thread-pool.default-executor.queue-capacity=1
|
||||
spring.dynamic.thread-pool.default-executor.rejected-handler=AbortPolicy
|
||||
spring.dynamic.thread-pool.default-executor.active-alarm=90
|
||||
spring.dynamic.thread-pool.default-executor.capacity-alarm=85
|
||||
spring.dynamic.thread-pool.default-executor.alarm=true
|
||||
spring.dynamic.thread-pool.default-executor.allow-core-thread-time-out=true
|
||||
spring.dynamic.thread-pool.default-executor.notify.interval=5
|
||||
spring.dynamic.thread-pool.default-executor.notify.receives=chen.ma
|
||||
spring.dynamic.thread-pool.notify-platforms[0].platform=WECHAT
|
||||
spring.dynamic.thread-pool.notify-platforms[0].secret-key=ec3be378-6c99-45d2-a147-b400c7e94a08
|
||||
spring.dynamic.thread-pool.executors[0].thread-pool-id=message-consume
|
||||
spring.dynamic.thread-pool.executors[0].thread-name-prefix=message-consume
|
||||
spring.dynamic.thread-pool.executors[0].core-pool-size=2
|
||||
spring.dynamic.thread-pool.executors[0].maximum-pool-size=4
|
||||
spring.dynamic.thread-pool.executors[0].queue-capacity=1024
|
||||
spring.dynamic.thread-pool.executors[0].blocking-queue=ResizableCapacityLinkedBlockingQueue
|
||||
spring.dynamic.thread-pool.executors[0].execute-time-out=800
|
||||
spring.dynamic.thread-pool.executors[0].rejected-handler=AbortPolicy
|
||||
spring.dynamic.thread-pool.executors[0].keep-alive-time=6691
|
||||
spring.dynamic.thread-pool.executors[0].allow-core-thread-time-out=true
|
||||
spring.dynamic.thread-pool.executors[0].alarm=true
|
||||
spring.dynamic.thread-pool.executors[0].active-alarm=80
|
||||
spring.dynamic.thread-pool.executors[0].capacity-alarm=80
|
||||
spring.dynamic.thread-pool.executors[0].notify.interval=8
|
||||
spring.dynamic.thread-pool.executors[0].notify.receives=chen.ma
|
||||
spring.dynamic.thread-pool.executors[1].thread-pool-id=message-produce
|
||||
spring.dynamic.thread-pool.executors[1].thread-name-prefix=message-produce
|
||||
spring.dynamic.thread-pool.executors[1].core-pool-size=2
|
||||
spring.dynamic.thread-pool.executors[1].maximum-pool-size=4
|
||||
spring.dynamic.thread-pool.executors[1].queue-capacity=1024
|
||||
spring.dynamic.thread-pool.executors[1].blocking-queue=ResizableCapacityLinkedBlockingQueue
|
||||
spring.dynamic.thread-pool.executors[1].execute-time-out=800
|
||||
spring.dynamic.thread-pool.executors[1].rejected-handler=AbortPolicy
|
||||
spring.dynamic.thread-pool.executors[1].keep-alive-time=6691
|
||||
spring.dynamic.thread-pool.executors[1].allow-core-thread-time-out=true
|
||||
spring.dynamic.thread-pool.executors[1].alarm=true
|
||||
spring.dynamic.thread-pool.executors[1].active-alarm=80
|
||||
spring.dynamic.thread-pool.executors[1].capacity-alarm=80
|
||||
spring.dynamic.thread-pool.executors[1].notify.interval=8
|
||||
spring.dynamic.thread-pool.executors[1].notify.receives=chen.ma
|
@ -0,0 +1,52 @@
|
||||
# \u4EE5\u4E0B\u5185\u5BB9\u590D\u5236\u5230 apollo \u914D\u7F6E\u6587\u4EF6\u4E2D
|
||||
# Copy the following to the apollo configuration file
|
||||
|
||||
spring.dynamic.thread-pool.tomcat.core-pool-size=64
|
||||
spring.dynamic.thread-pool.tomcat.maximum-pool-size=128
|
||||
spring.dynamic.thread-pool.tomcat.keep-alive-time=1000
|
||||
spring.dynamic.thread-pool.tomcat.enable=true
|
||||
spring.dynamic.thread-pool.default-executor.core-pool-size=1
|
||||
spring.dynamic.thread-pool.default-executor.maximum-pool-size=2
|
||||
spring.dynamic.thread-pool.default-executor.blocking-queue=ResizableCapacityLinkedBlockingQueue
|
||||
spring.dynamic.thread-pool.default-executor.execute-time-out=100
|
||||
spring.dynamic.thread-pool.default-executor.keep-alive-time=6691
|
||||
spring.dynamic.thread-pool.default-executor.queue-capacity=1
|
||||
spring.dynamic.thread-pool.default-executor.rejected-handler=AbortPolicy
|
||||
spring.dynamic.thread-pool.default-executor.active-alarm=90
|
||||
spring.dynamic.thread-pool.default-executor.capacity-alarm=85
|
||||
spring.dynamic.thread-pool.default-executor.alarm=true
|
||||
spring.dynamic.thread-pool.default-executor.allow-core-thread-time-out=true
|
||||
spring.dynamic.thread-pool.default-executor.notify.interval=5
|
||||
spring.dynamic.thread-pool.default-executor.notify.receives=chen.ma
|
||||
spring.dynamic.thread-pool.notify-platforms[0].platform=WECHAT
|
||||
spring.dynamic.thread-pool.notify-platforms[0].secret-key=ec3be378-6c99-45d2-a147-b400c7e94a08
|
||||
spring.dynamic.thread-pool.executors[0].thread-pool-id=message-consume
|
||||
spring.dynamic.thread-pool.executors[0].thread-name-prefix=message-consume
|
||||
spring.dynamic.thread-pool.executors[0].core-pool-size=2
|
||||
spring.dynamic.thread-pool.executors[0].maximum-pool-size=4
|
||||
spring.dynamic.thread-pool.executors[0].queue-capacity=1024
|
||||
spring.dynamic.thread-pool.executors[0].blocking-queue=ResizableCapacityLinkedBlockingQueue
|
||||
spring.dynamic.thread-pool.executors[0].execute-time-out=800
|
||||
spring.dynamic.thread-pool.executors[0].rejected-handler=AbortPolicy
|
||||
spring.dynamic.thread-pool.executors[0].keep-alive-time=6691
|
||||
spring.dynamic.thread-pool.executors[0].allow-core-thread-time-out=true
|
||||
spring.dynamic.thread-pool.executors[0].alarm=true
|
||||
spring.dynamic.thread-pool.executors[0].active-alarm=80
|
||||
spring.dynamic.thread-pool.executors[0].capacity-alarm=80
|
||||
spring.dynamic.thread-pool.executors[0].notify.interval=8
|
||||
spring.dynamic.thread-pool.executors[0].notify.receives=chen.ma
|
||||
spring.dynamic.thread-pool.executors[1].thread-pool-id=message-produce
|
||||
spring.dynamic.thread-pool.executors[1].thread-name-prefix=message-produce
|
||||
spring.dynamic.thread-pool.executors[1].core-pool-size=2
|
||||
spring.dynamic.thread-pool.executors[1].maximum-pool-size=4
|
||||
spring.dynamic.thread-pool.executors[1].queue-capacity=1024
|
||||
spring.dynamic.thread-pool.executors[1].blocking-queue=ResizableCapacityLinkedBlockingQueue
|
||||
spring.dynamic.thread-pool.executors[1].execute-time-out=800
|
||||
spring.dynamic.thread-pool.executors[1].rejected-handler=AbortPolicy
|
||||
spring.dynamic.thread-pool.executors[1].keep-alive-time=6691
|
||||
spring.dynamic.thread-pool.executors[1].allow-core-thread-time-out=true
|
||||
spring.dynamic.thread-pool.executors[1].alarm=true
|
||||
spring.dynamic.thread-pool.executors[1].active-alarm=80
|
||||
spring.dynamic.thread-pool.executors[1].capacity-alarm=80
|
||||
spring.dynamic.thread-pool.executors[1].notify.interval=8
|
||||
spring.dynamic.thread-pool.executors[1].notify.receives=chen.ma
|
@ -0,0 +1,52 @@
|
||||
# \u4EE5\u4E0B\u5185\u5BB9\u590D\u5236\u5230 etcd \u914D\u7F6E\u6587\u4EF6\u4E2D
|
||||
# Copy the following to the etcd configuration file
|
||||
|
||||
spring.dynamic.thread-pool.tomcat.core-pool-size=64
|
||||
spring.dynamic.thread-pool.tomcat.maximum-pool-size=128
|
||||
spring.dynamic.thread-pool.tomcat.keep-alive-time=1000
|
||||
spring.dynamic.thread-pool.tomcat.enable=true
|
||||
spring.dynamic.thread-pool.default-executor.core-pool-size=1
|
||||
spring.dynamic.thread-pool.default-executor.maximum-pool-size=2
|
||||
spring.dynamic.thread-pool.default-executor.blocking-queue=ResizableCapacityLinkedBlockingQueue
|
||||
spring.dynamic.thread-pool.default-executor.execute-time-out=100
|
||||
spring.dynamic.thread-pool.default-executor.keep-alive-time=6691
|
||||
spring.dynamic.thread-pool.default-executor.queue-capacity=1
|
||||
spring.dynamic.thread-pool.default-executor.rejected-handler=AbortPolicy
|
||||
spring.dynamic.thread-pool.default-executor.active-alarm=90
|
||||
spring.dynamic.thread-pool.default-executor.capacity-alarm=85
|
||||
spring.dynamic.thread-pool.default-executor.alarm=true
|
||||
spring.dynamic.thread-pool.default-executor.allow-core-thread-time-out=true
|
||||
spring.dynamic.thread-pool.default-executor.notify.interval=5
|
||||
spring.dynamic.thread-pool.default-executor.notify.receives=chen.ma
|
||||
spring.dynamic.thread-pool.notify-platforms[0].platform=WECHAT
|
||||
spring.dynamic.thread-pool.notify-platforms[0].secret-key=ec3be378-6c99-45d2-a147-b400c7e94a08
|
||||
spring.dynamic.thread-pool.executors[0].thread-pool-id=message-consume
|
||||
spring.dynamic.thread-pool.executors[0].thread-name-prefix=message-consume
|
||||
spring.dynamic.thread-pool.executors[0].core-pool-size=2
|
||||
spring.dynamic.thread-pool.executors[0].maximum-pool-size=4
|
||||
spring.dynamic.thread-pool.executors[0].queue-capacity=1024
|
||||
spring.dynamic.thread-pool.executors[0].blocking-queue=ResizableCapacityLinkedBlockingQueue
|
||||
spring.dynamic.thread-pool.executors[0].execute-time-out=800
|
||||
spring.dynamic.thread-pool.executors[0].rejected-handler=AbortPolicy
|
||||
spring.dynamic.thread-pool.executors[0].keep-alive-time=6691
|
||||
spring.dynamic.thread-pool.executors[0].allow-core-thread-time-out=true
|
||||
spring.dynamic.thread-pool.executors[0].alarm=true
|
||||
spring.dynamic.thread-pool.executors[0].active-alarm=80
|
||||
spring.dynamic.thread-pool.executors[0].capacity-alarm=80
|
||||
spring.dynamic.thread-pool.executors[0].notify.interval=8
|
||||
spring.dynamic.thread-pool.executors[0].notify.receives=chen.ma
|
||||
spring.dynamic.thread-pool.executors[1].thread-pool-id=message-produce
|
||||
spring.dynamic.thread-pool.executors[1].thread-name-prefix=message-produce
|
||||
spring.dynamic.thread-pool.executors[1].core-pool-size=2
|
||||
spring.dynamic.thread-pool.executors[1].maximum-pool-size=4
|
||||
spring.dynamic.thread-pool.executors[1].queue-capacity=1024
|
||||
spring.dynamic.thread-pool.executors[1].blocking-queue=ResizableCapacityLinkedBlockingQueue
|
||||
spring.dynamic.thread-pool.executors[1].execute-time-out=800
|
||||
spring.dynamic.thread-pool.executors[1].rejected-handler=AbortPolicy
|
||||
spring.dynamic.thread-pool.executors[1].keep-alive-time=6691
|
||||
spring.dynamic.thread-pool.executors[1].allow-core-thread-time-out=true
|
||||
spring.dynamic.thread-pool.executors[1].alarm=true
|
||||
spring.dynamic.thread-pool.executors[1].active-alarm=80
|
||||
spring.dynamic.thread-pool.executors[1].capacity-alarm=80
|
||||
spring.dynamic.thread-pool.executors[1].notify.interval=8
|
||||
spring.dynamic.thread-pool.executors[1].notify.receives=chen.ma
|
@ -0,0 +1,52 @@
|
||||
# \u4EE5\u4E0B\u5185\u5BB9\u590D\u5236\u5230 nacos \u914D\u7F6E\u6587\u4EF6\u4E2D
|
||||
# Copy the following to the nacos configuration file
|
||||
|
||||
spring.dynamic.thread-pool.tomcat.core-pool-size=64
|
||||
spring.dynamic.thread-pool.tomcat.maximum-pool-size=128
|
||||
spring.dynamic.thread-pool.tomcat.keep-alive-time=1000
|
||||
spring.dynamic.thread-pool.tomcat.enable=true
|
||||
spring.dynamic.thread-pool.default-executor.core-pool-size=1
|
||||
spring.dynamic.thread-pool.default-executor.maximum-pool-size=2
|
||||
spring.dynamic.thread-pool.default-executor.blocking-queue=ResizableCapacityLinkedBlockingQueue
|
||||
spring.dynamic.thread-pool.default-executor.execute-time-out=100
|
||||
spring.dynamic.thread-pool.default-executor.keep-alive-time=6691
|
||||
spring.dynamic.thread-pool.default-executor.queue-capacity=1
|
||||
spring.dynamic.thread-pool.default-executor.rejected-handler=AbortPolicy
|
||||
spring.dynamic.thread-pool.default-executor.active-alarm=90
|
||||
spring.dynamic.thread-pool.default-executor.capacity-alarm=85
|
||||
spring.dynamic.thread-pool.default-executor.alarm=true
|
||||
spring.dynamic.thread-pool.default-executor.allow-core-thread-time-out=true
|
||||
spring.dynamic.thread-pool.default-executor.notify.interval=5
|
||||
spring.dynamic.thread-pool.default-executor.notify.receives=chen.ma
|
||||
spring.dynamic.thread-pool.notify-platforms[0].platform=WECHAT
|
||||
spring.dynamic.thread-pool.notify-platforms[0].secret-key=ec3be378-6c99-45d2-a147-b400c7e94a08
|
||||
spring.dynamic.thread-pool.executors[0].thread-pool-id=message-consume
|
||||
spring.dynamic.thread-pool.executors[0].thread-name-prefix=message-consume
|
||||
spring.dynamic.thread-pool.executors[0].core-pool-size=2
|
||||
spring.dynamic.thread-pool.executors[0].maximum-pool-size=4
|
||||
spring.dynamic.thread-pool.executors[0].queue-capacity=1024
|
||||
spring.dynamic.thread-pool.executors[0].blocking-queue=ResizableCapacityLinkedBlockingQueue
|
||||
spring.dynamic.thread-pool.executors[0].execute-time-out=800
|
||||
spring.dynamic.thread-pool.executors[0].rejected-handler=AbortPolicy
|
||||
spring.dynamic.thread-pool.executors[0].keep-alive-time=6691
|
||||
spring.dynamic.thread-pool.executors[0].allow-core-thread-time-out=true
|
||||
spring.dynamic.thread-pool.executors[0].alarm=true
|
||||
spring.dynamic.thread-pool.executors[0].active-alarm=80
|
||||
spring.dynamic.thread-pool.executors[0].capacity-alarm=80
|
||||
spring.dynamic.thread-pool.executors[0].notify.interval=8
|
||||
spring.dynamic.thread-pool.executors[0].notify.receives=chen.ma
|
||||
spring.dynamic.thread-pool.executors[1].thread-pool-id=message-produce
|
||||
spring.dynamic.thread-pool.executors[1].thread-name-prefix=message-produce
|
||||
spring.dynamic.thread-pool.executors[1].core-pool-size=2
|
||||
spring.dynamic.thread-pool.executors[1].maximum-pool-size=4
|
||||
spring.dynamic.thread-pool.executors[1].queue-capacity=1024
|
||||
spring.dynamic.thread-pool.executors[1].blocking-queue=ResizableCapacityLinkedBlockingQueue
|
||||
spring.dynamic.thread-pool.executors[1].execute-time-out=800
|
||||
spring.dynamic.thread-pool.executors[1].rejected-handler=AbortPolicy
|
||||
spring.dynamic.thread-pool.executors[1].keep-alive-time=6691
|
||||
spring.dynamic.thread-pool.executors[1].allow-core-thread-time-out=true
|
||||
spring.dynamic.thread-pool.executors[1].alarm=true
|
||||
spring.dynamic.thread-pool.executors[1].active-alarm=80
|
||||
spring.dynamic.thread-pool.executors[1].capacity-alarm=80
|
||||
spring.dynamic.thread-pool.executors[1].notify.interval=8
|
||||
spring.dynamic.thread-pool.executors[1].notify.receives=chen.ma
|
@ -0,0 +1,52 @@
|
||||
# \u4EE5\u4E0B\u5185\u5BB9\u590D\u5236\u5230 nacos \u914D\u7F6E\u6587\u4EF6\u4E2D
|
||||
# Copy the following to the nacos configuration file
|
||||
|
||||
spring.dynamic.thread-pool.tomcat.core-pool-size=64
|
||||
spring.dynamic.thread-pool.tomcat.maximum-pool-size=128
|
||||
spring.dynamic.thread-pool.tomcat.keep-alive-time=1000
|
||||
spring.dynamic.thread-pool.tomcat.enable=true
|
||||
spring.dynamic.thread-pool.default-executor.core-pool-size=1
|
||||
spring.dynamic.thread-pool.default-executor.maximum-pool-size=2
|
||||
spring.dynamic.thread-pool.default-executor.blocking-queue=ResizableCapacityLinkedBlockingQueue
|
||||
spring.dynamic.thread-pool.default-executor.execute-time-out=100
|
||||
spring.dynamic.thread-pool.default-executor.keep-alive-time=6691
|
||||
spring.dynamic.thread-pool.default-executor.queue-capacity=1
|
||||
spring.dynamic.thread-pool.default-executor.rejected-handler=AbortPolicy
|
||||
spring.dynamic.thread-pool.default-executor.active-alarm=90
|
||||
spring.dynamic.thread-pool.default-executor.capacity-alarm=85
|
||||
spring.dynamic.thread-pool.default-executor.alarm=true
|
||||
spring.dynamic.thread-pool.default-executor.allow-core-thread-time-out=true
|
||||
spring.dynamic.thread-pool.default-executor.notify.interval=5
|
||||
spring.dynamic.thread-pool.default-executor.notify.receives=chen.ma
|
||||
spring.dynamic.thread-pool.notify-platforms[0].platform=WECHAT
|
||||
spring.dynamic.thread-pool.notify-platforms[0].secret-key=ec3be378-6c99-45d2-a147-b400c7e94a08
|
||||
spring.dynamic.thread-pool.executors[0].thread-pool-id=message-consume
|
||||
spring.dynamic.thread-pool.executors[0].thread-name-prefix=message-consume
|
||||
spring.dynamic.thread-pool.executors[0].core-pool-size=2
|
||||
spring.dynamic.thread-pool.executors[0].maximum-pool-size=4
|
||||
spring.dynamic.thread-pool.executors[0].queue-capacity=1024
|
||||
spring.dynamic.thread-pool.executors[0].blocking-queue=ResizableCapacityLinkedBlockingQueue
|
||||
spring.dynamic.thread-pool.executors[0].execute-time-out=800
|
||||
spring.dynamic.thread-pool.executors[0].rejected-handler=AbortPolicy
|
||||
spring.dynamic.thread-pool.executors[0].keep-alive-time=6691
|
||||
spring.dynamic.thread-pool.executors[0].allow-core-thread-time-out=true
|
||||
spring.dynamic.thread-pool.executors[0].alarm=true
|
||||
spring.dynamic.thread-pool.executors[0].active-alarm=80
|
||||
spring.dynamic.thread-pool.executors[0].capacity-alarm=80
|
||||
spring.dynamic.thread-pool.executors[0].notify.interval=8
|
||||
spring.dynamic.thread-pool.executors[0].notify.receives=chen.ma
|
||||
spring.dynamic.thread-pool.executors[1].thread-pool-id=message-produce
|
||||
spring.dynamic.thread-pool.executors[1].thread-name-prefix=message-produce
|
||||
spring.dynamic.thread-pool.executors[1].core-pool-size=2
|
||||
spring.dynamic.thread-pool.executors[1].maximum-pool-size=4
|
||||
spring.dynamic.thread-pool.executors[1].queue-capacity=1024
|
||||
spring.dynamic.thread-pool.executors[1].blocking-queue=ResizableCapacityLinkedBlockingQueue
|
||||
spring.dynamic.thread-pool.executors[1].execute-time-out=800
|
||||
spring.dynamic.thread-pool.executors[1].rejected-handler=AbortPolicy
|
||||
spring.dynamic.thread-pool.executors[1].keep-alive-time=6691
|
||||
spring.dynamic.thread-pool.executors[1].allow-core-thread-time-out=true
|
||||
spring.dynamic.thread-pool.executors[1].alarm=true
|
||||
spring.dynamic.thread-pool.executors[1].active-alarm=80
|
||||
spring.dynamic.thread-pool.executors[1].capacity-alarm=80
|
||||
spring.dynamic.thread-pool.executors[1].notify.interval=8
|
||||
spring.dynamic.thread-pool.executors[1].notify.receives=chen.ma
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.monitor.base;
|
||||
|
||||
import cn.hippo4j.adapter.base.ThreadPoolAdapter;
|
||||
import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
|
||||
import cn.hippo4j.common.config.ApplicationContextHolder;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Abstract adapter thread-pool monitor.
|
||||
*/
|
||||
public abstract class AbstractAdapterThreadPoolMonitor implements AdapterThreadPoolMonitor {
|
||||
|
||||
/**
|
||||
* Execute collection thread pool running data.
|
||||
*
|
||||
* @param threadPoolAdapterState thread-pool adapter state
|
||||
*/
|
||||
protected abstract void execute(ThreadPoolAdapterState threadPoolAdapterState);
|
||||
|
||||
@Override
|
||||
public void collect() {
|
||||
Map<String, ThreadPoolAdapter> threadPoolAdapterMap = ApplicationContextHolder.getBeansOfType(ThreadPoolAdapter.class);
|
||||
threadPoolAdapterMap.forEach((beanName, bean) -> bean.getThreadPoolStates().forEach(each -> execute(each)));
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.monitor.base;
|
||||
|
||||
import cn.hippo4j.adapter.web.WebThreadPoolService;
|
||||
import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* Abstract web thread-pool monitor.
|
||||
*/
|
||||
public abstract class AbstractWebThreadPoolMonitor implements WebThreadPoolMonitor {
|
||||
|
||||
@Resource
|
||||
private WebThreadPoolService webThreadPoolService;
|
||||
|
||||
/**
|
||||
* Execute collection thread pool running data.
|
||||
*
|
||||
* @param webThreadPoolRunStateInfo web thread-pool run state info
|
||||
*/
|
||||
protected abstract void execute(ThreadPoolRunStateInfo webThreadPoolRunStateInfo);
|
||||
|
||||
@Override
|
||||
public void collect() {
|
||||
ThreadPoolRunStateInfo webThreadPoolRunStateInfo = webThreadPoolService.getWebRunStateInfo();
|
||||
execute(webThreadPoolRunStateInfo);
|
||||
}
|
||||
}
|
16
hippo4j-spring-boot/hippo4j-spring-boot-starter-monitor/hippo4j-spring-boot-starter-monitor-elasticsearch/src/main/java/cn/hippo4j/springboot/starter/monitor/es/EsMonitorAutoConfiguration.java → hippo4j-monitor/hippo4j-monitor-base/src/main/java/cn/hippo4j/monitor/base/AdapterThreadPoolMonitor.java
16
hippo4j-spring-boot/hippo4j-spring-boot-starter-monitor/hippo4j-spring-boot-starter-monitor-elasticsearch/src/main/java/cn/hippo4j/springboot/starter/monitor/es/EsMonitorAutoConfiguration.java → hippo4j-monitor/hippo4j-monitor-base/src/main/java/cn/hippo4j/monitor/base/AdapterThreadPoolMonitor.java
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.monitor.elasticsearch;
|
||||
|
||||
import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
|
||||
import cn.hippo4j.monitor.base.AbstractDynamicThreadPoolMonitor;
|
||||
import cn.hippo4j.monitor.base.MonitorTypeEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Adapter thread-pool elastic-search monitor handler.
|
||||
*/
|
||||
@Slf4j
|
||||
public class AdapterThreadPoolElasticSearchMonitorHandler extends AbstractDynamicThreadPoolMonitor {
|
||||
|
||||
@Override
|
||||
protected void execute(ThreadPoolRunStateInfo poolRunStateInfo) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return MonitorTypeEnum.ELASTICSEARCH.name().toLowerCase();
|
||||
}
|
||||
}
|
27
hippo4j-spring-boot/hippo4j-spring-boot-starter-monitor/hippo4j-spring-boot-starter-monitor-local-log/src/main/java/cn/hippo4j/springboot/starter/monitor/local/log/LocalLogMonitorConfiguration.java → hippo4j-monitor/hippo4j-monitor-elasticsearch/src/main/java/cn/hippo4j/monitor/elasticsearch/WebThreadPoolElasticSearchMonitorHandler.java
27
hippo4j-spring-boot/hippo4j-spring-boot-starter-monitor/hippo4j-spring-boot-starter-monitor-local-log/src/main/java/cn/hippo4j/springboot/starter/monitor/local/log/LocalLogMonitorConfiguration.java → hippo4j-monitor/hippo4j-monitor-elasticsearch/src/main/java/cn/hippo4j/monitor/elasticsearch/WebThreadPoolElasticSearchMonitorHandler.java
28
hippo4j-spring-boot/hippo4j-spring-boot-starter-monitor/hippo4j-spring-boot-starter-monitor-micrometer/src/main/java/cn/hippo4j/springboot/starter/monitor/micrometer/MicrometerMonitorConfiguration.java → hippo4j-monitor/hippo4j-monitor-local-log/src/main/java/cn/hippo4j/monitor/local/log/AdapterThreadPoolLocalLogMonitorHandler.java
28
hippo4j-spring-boot/hippo4j-spring-boot-starter-monitor/hippo4j-spring-boot-starter-monitor-micrometer/src/main/java/cn/hippo4j/springboot/starter/monitor/micrometer/MicrometerMonitorConfiguration.java → hippo4j-monitor/hippo4j-monitor-local-log/src/main/java/cn/hippo4j/monitor/local/log/AdapterThreadPoolLocalLogMonitorHandler.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.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 lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Web thread-pool local log monitor handler.
|
||||
*/
|
||||
@Slf4j
|
||||
public class WebThreadPoolLocalLogMonitorHandler extends AbstractWebThreadPoolMonitor {
|
||||
|
||||
@Override
|
||||
protected void execute(ThreadPoolRunStateInfo poolRunStateInfo) {
|
||||
log.info("{}", JSONUtil.toJSONString(poolRunStateInfo));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return MonitorTypeEnum.LOG.name().toLowerCase();
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.monitor.micrometer;
|
||||
|
||||
import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
|
||||
import cn.hippo4j.common.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 io.micrometer.core.instrument.Metrics;
|
||||
import io.micrometer.core.instrument.Tag;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Adapter thread-pool micrometer monitor handler.
|
||||
*/
|
||||
public class AdapterThreadPoolMicrometerMonitorHandler extends AbstractAdapterThreadPoolMonitor {
|
||||
|
||||
private final static String METRIC_NAME_PREFIX = "adapter.thread-pool";
|
||||
|
||||
private final static String ADAPTER_THREAD_POOL_ID_TAG = METRIC_NAME_PREFIX + ".id";
|
||||
|
||||
private final static String APPLICATION_NAME_TAG = "application.name";
|
||||
|
||||
private final Map<String, ThreadPoolAdapterState> RUN_STATE_CACHE = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
protected void execute(ThreadPoolAdapterState threadPoolAdapterState) {
|
||||
ThreadPoolAdapterState stateInfo = RUN_STATE_CACHE.get(threadPoolAdapterState.getThreadPoolKey());
|
||||
if (stateInfo == null) {
|
||||
RUN_STATE_CACHE.put(threadPoolAdapterState.getThreadPoolKey(), threadPoolAdapterState);
|
||||
} else {
|
||||
BeanUtil.convert(threadPoolAdapterState, stateInfo);
|
||||
}
|
||||
Environment environment = ApplicationContextHolder.getInstance().getEnvironment();
|
||||
String applicationName = environment.getProperty("spring.application.name", "application");
|
||||
Iterable<Tag> tags = CollectionUtil.newArrayList(
|
||||
Tag.of(ADAPTER_THREAD_POOL_ID_TAG, threadPoolAdapterState.getThreadPoolKey()),
|
||||
Tag.of(APPLICATION_NAME_TAG, applicationName));
|
||||
Metrics.gauge(metricName("core.size"), tags, threadPoolAdapterState, ThreadPoolAdapterState::getCoreSize);
|
||||
Metrics.gauge(metricName("maximum.size"), tags, threadPoolAdapterState, ThreadPoolAdapterState::getMaximumSize);
|
||||
Metrics.gauge(metricName("queue.capacity"), tags, threadPoolAdapterState, ThreadPoolAdapterState::getBlockingQueueCapacity);
|
||||
}
|
||||
|
||||
private String metricName(String name) {
|
||||
return String.join(".", METRIC_NAME_PREFIX, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return MonitorTypeEnum.MICROMETER.name().toLowerCase();
|
||||
}
|
||||
}
|
@ -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.monitor.micrometer;
|
||||
|
||||
import cn.hippo4j.common.config.ApplicationContextHolder;
|
||||
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 io.micrometer.core.instrument.Metrics;
|
||||
import io.micrometer.core.instrument.Tag;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Web thread-pool micrometer monitor handler.
|
||||
*/
|
||||
public class WebThreadPoolMicrometerMonitorHandler extends AbstractWebThreadPoolMonitor {
|
||||
|
||||
private final static String METRIC_NAME_PREFIX = "web.thread-pool";
|
||||
|
||||
private final static String APPLICATION_NAME_TAG = "application.name";
|
||||
|
||||
private final Map<String, ThreadPoolRunStateInfo> RUN_STATE_CACHE = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
protected void execute(ThreadPoolRunStateInfo webThreadPoolRunStateInfo) {
|
||||
Environment environment = ApplicationContextHolder.getInstance().getEnvironment();
|
||||
String applicationName = environment.getProperty("spring.application.name", "application");
|
||||
ThreadPoolRunStateInfo stateInfo = RUN_STATE_CACHE.get(applicationName);
|
||||
if (stateInfo == null) {
|
||||
RUN_STATE_CACHE.put(applicationName, webThreadPoolRunStateInfo);
|
||||
} else {
|
||||
BeanUtil.convert(webThreadPoolRunStateInfo, stateInfo);
|
||||
}
|
||||
Iterable<Tag> tags = CollectionUtil.newArrayList(Tag.of(APPLICATION_NAME_TAG, applicationName));
|
||||
Metrics.gauge(metricName("current.load"), tags, webThreadPoolRunStateInfo, ThreadPoolRunStateInfo::getSimpleCurrentLoad);
|
||||
Metrics.gauge(metricName("peak.load"), tags, webThreadPoolRunStateInfo, ThreadPoolRunStateInfo::getSimplePeakLoad);
|
||||
Metrics.gauge(metricName("core.size"), tags, webThreadPoolRunStateInfo, ThreadPoolRunStateInfo::getCoreSize);
|
||||
Metrics.gauge(metricName("maximum.size"), tags, webThreadPoolRunStateInfo, ThreadPoolRunStateInfo::getMaximumSize);
|
||||
Metrics.gauge(metricName("current.size"), tags, webThreadPoolRunStateInfo, ThreadPoolRunStateInfo::getPoolSize);
|
||||
Metrics.gauge(metricName("largest.size"), tags, webThreadPoolRunStateInfo, ThreadPoolRunStateInfo::getLargestPoolSize);
|
||||
Metrics.gauge(metricName("active.size"), tags, webThreadPoolRunStateInfo, ThreadPoolRunStateInfo::getActiveSize);
|
||||
Metrics.gauge(metricName("queue.size"), tags, webThreadPoolRunStateInfo, ThreadPoolRunStateInfo::getQueueSize);
|
||||
Metrics.gauge(metricName("queue.capacity"), tags, webThreadPoolRunStateInfo, ThreadPoolRunStateInfo::getQueueCapacity);
|
||||
Metrics.gauge(metricName("queue.remaining.capacity"), tags, webThreadPoolRunStateInfo, ThreadPoolRunStateInfo::getQueueRemainingCapacity);
|
||||
Metrics.gauge(metricName("completed.task.count"), tags, webThreadPoolRunStateInfo, ThreadPoolRunStateInfo::getCompletedTaskCount);
|
||||
}
|
||||
|
||||
private String metricName(String name) {
|
||||
return String.join(".", METRIC_NAME_PREFIX, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return MonitorTypeEnum.MICROMETER.name().toLowerCase();
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue