线程池实例参数弹框添加实例 ID 和线程池状态. (#67)

pull/84/head
chen.ma 3 years ago
parent 71ca22318e
commit eb89d06fca

@ -38,6 +38,8 @@ public class InstanceInfo {
private String identify; private String identify;
private String active;
private volatile String vipAddress; private volatile String vipAddress;
private volatile String secureVipAddress; private volatile String secureVipAddress;

@ -0,0 +1,24 @@
package cn.hippo4j.common.model;
import lombok.Data;
/**
* Many pool run state info.
*
* @author chen.ma
* @date 2022/1/8 12:54
*/
@Data
public class ManyPoolRunStateInfo extends PoolRunStateInfo {
/**
* identify
*/
private String identify;
/**
* active
*/
private String active;
}

@ -77,6 +77,7 @@ public class ThreadPoolController {
content.forEach((key, val) -> { content.forEach((key, val) -> {
ThreadPoolInstanceInfo threadPoolInstanceInfo = BeanUtil.convert(val.configAllInfo, ThreadPoolInstanceInfo.class); ThreadPoolInstanceInfo threadPoolInstanceInfo = BeanUtil.convert(val.configAllInfo, ThreadPoolInstanceInfo.class);
threadPoolInstanceInfo.setClientAddress(StrUtil.subBefore(key, Constants.IDENTIFY_SLICER_SYMBOL, false)); threadPoolInstanceInfo.setClientAddress(StrUtil.subBefore(key, Constants.IDENTIFY_SLICER_SYMBOL, false));
threadPoolInstanceInfo.setActive(holder.getActive());
threadPoolInstanceInfo.setIdentify(key); threadPoolInstanceInfo.setIdentify(key);
threadPoolInstanceInfo.setClientBasePath(holder.getClientBasePath()); threadPoolInstanceInfo.setClientBasePath(holder.getClientBasePath());
returnThreadPool.add(threadPoolInstanceInfo); returnThreadPool.add(threadPoolInstanceInfo);

@ -27,4 +27,9 @@ public class ThreadPoolInstanceInfo extends ConfigAllInfo {
*/ */
private String clientBasePath; private String clientBasePath;
/**
* active
*/
private String active;
} }

@ -41,6 +41,7 @@ public class DiscoveryConfig {
String itemId = properties.getItemId(); String itemId = properties.getItemId();
String port = environment.getProperty("server.port"); String port = environment.getProperty("server.port");
String applicationName = environment.getProperty("spring.application.name"); String applicationName = environment.getProperty("spring.application.name");
String active = environment.getProperty("spring.profiles.active", "UNKNOWN");
InstanceInfo instanceInfo = new InstanceInfo(); InstanceInfo instanceInfo = new InstanceInfo();
String instanceId = getDefaultInstanceId(environment, hippo4JInetUtils); String instanceId = getDefaultInstanceId(environment, hippo4JInetUtils);
@ -62,6 +63,7 @@ public class DiscoveryConfig {
String identify = IdentifyUtil.generate(environment, hippo4JInetUtils); String identify = IdentifyUtil.generate(environment, hippo4JInetUtils);
instanceInfo.setIdentify(identify); instanceInfo.setIdentify(identify);
instanceInfo.setActive(active.toUpperCase());
return instanceInfo; return instanceInfo;
} }

@ -82,8 +82,9 @@ public class DynamicThreadPoolAutoConfiguration {
} }
@Bean @Bean
public ThreadPoolRunStateHandler threadPoolRunStateHandler() { @SuppressWarnings("all")
return new ThreadPoolRunStateHandler(); public ThreadPoolRunStateHandler threadPoolRunStateHandler(InetUtils hippo4JInetUtils) {
return new ThreadPoolRunStateHandler(hippo4JInetUtils, environment);
} }
@Bean @Bean

@ -1,17 +1,22 @@
package cn.hippo4j.starter.handler; package cn.hippo4j.starter.handler;
import cn.hippo4j.common.model.ManyPoolRunStateInfo;
import cn.hippo4j.common.model.PoolRunStateInfo; import cn.hippo4j.common.model.PoolRunStateInfo;
import cn.hippo4j.starter.core.GlobalThreadPoolManage; import cn.hippo4j.starter.core.GlobalThreadPoolManage;
import cn.hippo4j.starter.toolkit.ByteConvertUtil; import cn.hippo4j.starter.toolkit.ByteConvertUtil;
import cn.hippo4j.starter.toolkit.inet.InetUtils;
import cn.hippo4j.starter.wrapper.DynamicThreadPoolWrapper; import cn.hippo4j.starter.wrapper.DynamicThreadPoolWrapper;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.system.RuntimeInfo; import cn.hutool.system.RuntimeInfo;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.core.env.ConfigurableEnvironment;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import static cn.hippo4j.starter.config.DynamicThreadPoolAutoConfiguration.CLIENT_IDENTIFICATION_VALUE;
/** /**
* Thread pool run state service. * Thread pool run state service.
* *
@ -19,17 +24,12 @@ import java.util.concurrent.ThreadPoolExecutor;
* @date 2021/7/12 21:25 * @date 2021/7/12 21:25
*/ */
@Slf4j @Slf4j
@AllArgsConstructor
public class ThreadPoolRunStateHandler extends AbstractThreadPoolRuntime { public class ThreadPoolRunStateHandler extends AbstractThreadPoolRuntime {
private static InetAddress INET_ADDRESS; private final InetUtils hippo4JInetUtils;
static { private final ConfigurableEnvironment environment;
try {
INET_ADDRESS = InetAddress.getLocalHost();
} catch (UnknownHostException ex) {
log.error("Local IP acquisition failed.", ex);
}
}
@Override @Override
protected PoolRunStateInfo supplement(PoolRunStateInfo poolRunStateInfo) { protected PoolRunStateInfo supplement(PoolRunStateInfo poolRunStateInfo) {
@ -44,7 +44,9 @@ public class ThreadPoolRunStateHandler extends AbstractThreadPoolRuntime {
poolRunStateInfo.setCurrentLoad(poolRunStateInfo.getCurrentLoad() + "%"); poolRunStateInfo.setCurrentLoad(poolRunStateInfo.getCurrentLoad() + "%");
poolRunStateInfo.setPeakLoad(poolRunStateInfo.getPeakLoad() + "%"); poolRunStateInfo.setPeakLoad(poolRunStateInfo.getPeakLoad() + "%");
poolRunStateInfo.setHost(INET_ADDRESS.getHostAddress());
String ipAddress = hippo4JInetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
poolRunStateInfo.setHost(ipAddress);
poolRunStateInfo.setMemoryProportion(memoryProportion); poolRunStateInfo.setMemoryProportion(memoryProportion);
poolRunStateInfo.setFreeMemory(ByteConvertUtil.getPrintSize(runtimeInfo.getFreeMemory())); poolRunStateInfo.setFreeMemory(ByteConvertUtil.getPrintSize(runtimeInfo.getFreeMemory()));
@ -54,7 +56,13 @@ public class ThreadPoolRunStateHandler extends AbstractThreadPoolRuntime {
String rejectedName = pool.getRejectedExecutionHandler().getClass().getSimpleName(); String rejectedName = pool.getRejectedExecutionHandler().getClass().getSimpleName();
poolRunStateInfo.setRejectedName(rejectedName); poolRunStateInfo.setRejectedName(rejectedName);
return poolRunStateInfo; ManyPoolRunStateInfo manyPoolRunStateInfo = BeanUtil.toBean(poolRunStateInfo, ManyPoolRunStateInfo.class);
manyPoolRunStateInfo.setIdentify(CLIENT_IDENTIFICATION_VALUE);
String active = environment.getProperty("spring.profiles.active", "UNKNOWN");
manyPoolRunStateInfo.setActive(active.toUpperCase());
return manyPoolRunStateInfo;
} }
} }

Loading…
Cancel
Save