查看客户端线程池运行信息时, 添加内存详情.

pull/10/head
chen.ma 3 years ago
parent 34ae5e09df
commit 5c59511813

@ -90,4 +90,14 @@ public class PoolRunStateInfo implements Serializable {
*/ */
private String host; private String host;
/**
* memoryProportion
*/
private String memoryProportion;
/**
* freeMemory
*/
private String freeMemory;
} }

@ -1,10 +1,13 @@
package cn.hippo4j.starter.handler; package cn.hippo4j.starter.handler;
import cn.hippo4j.common.model.PoolRunStateInfo; import cn.hippo4j.common.model.PoolRunStateInfo;
import cn.hippo4j.starter.toolkit.CalculateUtil;
import cn.hippo4j.starter.core.GlobalThreadPoolManage;
import cn.hippo4j.starter.core.DynamicThreadPoolExecutor; import cn.hippo4j.starter.core.DynamicThreadPoolExecutor;
import cn.hippo4j.starter.core.GlobalThreadPoolManage;
import cn.hippo4j.starter.toolkit.ByteConvertUtil;
import cn.hippo4j.starter.toolkit.CalculateUtil;
import cn.hippo4j.starter.wrapper.DynamicThreadPoolWrapper; import cn.hippo4j.starter.wrapper.DynamicThreadPoolWrapper;
import cn.hutool.core.util.StrUtil;
import cn.hutool.system.RuntimeInfo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import java.net.InetAddress; import java.net.InetAddress;
@ -62,6 +65,15 @@ public class ThreadPoolRunStateHandler {
// 队列容量 // 队列容量
int queueCapacity = queueSize + remainingCapacity; int queueCapacity = queueSize + remainingCapacity;
// 内存占比: 使用内存 / 最大内存
RuntimeInfo runtimeInfo = new RuntimeInfo();
String memoryProportion = StrUtil.builder(
"已分配: ",
ByteConvertUtil.getPrintSize(runtimeInfo.getTotalMemory()),
" / 最大可用: ",
ByteConvertUtil.getPrintSize(runtimeInfo.getMaxMemory())
).toString();
PoolRunStateInfo stateInfo = new PoolRunStateInfo(); PoolRunStateInfo stateInfo = new PoolRunStateInfo();
stateInfo.setCoreSize(corePoolSize); stateInfo.setCoreSize(corePoolSize);
stateInfo.setMaximumSize(maximumPoolSize); stateInfo.setMaximumSize(maximumPoolSize);
@ -77,6 +89,8 @@ public class ThreadPoolRunStateHandler {
stateInfo.setCompletedTaskCount(completedTaskCount); stateInfo.setCompletedTaskCount(completedTaskCount);
stateInfo.setHost(INET_ADDRESS.getHostAddress()); stateInfo.setHost(INET_ADDRESS.getHostAddress());
stateInfo.setTpId(tpId); stateInfo.setTpId(tpId);
stateInfo.setMemoryProportion(memoryProportion);
stateInfo.setFreeMemory(ByteConvertUtil.getPrintSize(runtimeInfo.getFreeMemory()));
int rejectCount = pool instanceof DynamicThreadPoolExecutor int rejectCount = pool instanceof DynamicThreadPoolExecutor
? ((DynamicThreadPoolExecutor) pool).getRejectCount() ? ((DynamicThreadPoolExecutor) pool).getRejectCount()

@ -0,0 +1,38 @@
package cn.hippo4j.starter.toolkit;
/**
* .
*
* @author chen.ma
* @date 2021/11/20 12:21
*/
public class ByteConvertUtil {
/**
* .
*
* @param size
* @return
*/
public static String getPrintSize(long size) {
long covertNum = 1024;
if (size < covertNum) {
return size + "B";
} else {
size = size / covertNum;
}
if (size < covertNum) {
return size + "KB";
} else {
size = size / covertNum;
}
if (size < covertNum) {
size = size * 100;
return (size / 100) + "." + (size % 100) + "MB";
} else {
size = size * 100 / covertNum;
return (size / 100) + "." + (size % 100) + "GB";
}
}
}
Loading…
Cancel
Save