From 5bb1f4ab332ce89daed02be7a0691d2ce925ec4b Mon Sep 17 00:00:00 2001 From: magestack Date: Sat, 30 Sep 2023 09:05:00 +0800 Subject: [PATCH] Develop thread pool monitoring capabilities (#1489) --- .../biz/monitor/MonitorActiveRespDTO.java | 17 ++++-- .../model/biz/monitor/MonitorQueryReqDTO.java | 10 ++++ .../biz/impl/HisRunDataServiceImpl.java | 58 ++++++++++++------- 3 files changed, 60 insertions(+), 25 deletions(-) diff --git a/threadpool/server/config/src/main/java/cn/hippo4j/config/model/biz/monitor/MonitorActiveRespDTO.java b/threadpool/server/config/src/main/java/cn/hippo4j/config/model/biz/monitor/MonitorActiveRespDTO.java index 83c4b6b2bc..53e9e8f301 100644 --- a/threadpool/server/config/src/main/java/cn/hippo4j/config/model/biz/monitor/MonitorActiveRespDTO.java +++ b/threadpool/server/config/src/main/java/cn/hippo4j/config/model/biz/monitor/MonitorActiveRespDTO.java @@ -18,6 +18,7 @@ package cn.hippo4j.config.model.biz.monitor; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; @@ -27,6 +28,7 @@ * Monitor active resp dto. */ @Data +@Builder @NoArgsConstructor @AllArgsConstructor public class MonitorActiveRespDTO { @@ -51,11 +53,21 @@ public class MonitorActiveRespDTO { */ private List queueSizeList; + /** + * Range completed task count list + */ + private List rangeCompletedTaskCountList; + /** * Completed task count list */ private List completedTaskCountList; + /** + * Range reject count list + */ + private List rangeRejectCountList; + /** * Reject count list */ @@ -66,11 +78,6 @@ public class MonitorActiveRespDTO { */ private List queueRemainingCapacityList; - /** - * Current load list - */ - private List currentLoadList; - /** * Queue capacity list */ diff --git a/threadpool/server/config/src/main/java/cn/hippo4j/config/model/biz/monitor/MonitorQueryReqDTO.java b/threadpool/server/config/src/main/java/cn/hippo4j/config/model/biz/monitor/MonitorQueryReqDTO.java index f5e4e11928..93c9e09d7c 100644 --- a/threadpool/server/config/src/main/java/cn/hippo4j/config/model/biz/monitor/MonitorQueryReqDTO.java +++ b/threadpool/server/config/src/main/java/cn/hippo4j/config/model/biz/monitor/MonitorQueryReqDTO.java @@ -44,4 +44,14 @@ public class MonitorQueryReqDTO { * Instance id */ private String instanceId; + + /** + * Start time + */ + private Long startTime; + + /** + * End time + */ + private Long endTime; } diff --git a/threadpool/server/config/src/main/java/cn/hippo4j/config/service/biz/impl/HisRunDataServiceImpl.java b/threadpool/server/config/src/main/java/cn/hippo4j/config/service/biz/impl/HisRunDataServiceImpl.java index 385ccbd3f6..f0894f45dc 100644 --- a/threadpool/server/config/src/main/java/cn/hippo4j/config/service/biz/impl/HisRunDataServiceImpl.java +++ b/threadpool/server/config/src/main/java/cn/hippo4j/config/service/biz/impl/HisRunDataServiceImpl.java @@ -17,13 +17,14 @@ package cn.hippo4j.config.service.biz.impl; +import cn.hippo4j.common.model.Result; import cn.hippo4j.common.monitor.Message; import cn.hippo4j.common.monitor.MessageWrapper; import cn.hippo4j.common.monitor.RuntimeMessage; +import cn.hippo4j.common.toolkit.BeanUtil; import cn.hippo4j.common.toolkit.DateUtil; import cn.hippo4j.common.toolkit.GroupKey; import cn.hippo4j.common.toolkit.MessageConvert; -import cn.hippo4j.common.model.Result; import cn.hippo4j.config.config.ServerBootstrapProperties; import cn.hippo4j.config.mapper.HisRunDataMapper; import cn.hippo4j.config.model.HisRunDataInfo; @@ -33,7 +34,6 @@ import cn.hippo4j.config.monitor.QueryMonitorExecuteChoose; import cn.hippo4j.config.service.ConfigCacheService; import cn.hippo4j.config.service.biz.HisRunDataService; -import cn.hippo4j.common.toolkit.BeanUtil; import cn.hippo4j.server.common.base.Results; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.AllArgsConstructor; @@ -45,7 +45,6 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; import static cn.hippo4j.common.constant.MagicNumberConstants.INDEX_0; import static cn.hippo4j.common.constant.MagicNumberConstants.INDEX_1; @@ -84,15 +83,20 @@ public List query(MonitorQueryReqDTO reqDTO) { @Override public MonitorActiveRespDTO queryInfoThreadPoolMonitor(MonitorQueryReqDTO reqDTO) { - LocalDateTime currentDate = LocalDateTime.now(); - LocalDateTime dateTime = currentDate.plusMinutes(-properties.getCleanHistoryDataPeriod()); - long startTime = DateUtil.getTime(dateTime); + Long startTime = reqDTO.getStartTime(); + Long endTime = reqDTO.getEndTime(); + if (startTime == null || endTime == null) { + LocalDateTime currentDate = LocalDateTime.now(); + LocalDateTime dateTime = currentDate.plusMinutes(-properties.getCleanHistoryDataPeriod()); + startTime = DateUtil.getTime(dateTime); + endTime = DateUtil.getTime(currentDate); + } List hisRunDataInfos = this.lambdaQuery() .eq(HisRunDataInfo::getTenantId, reqDTO.getTenantId()) .eq(HisRunDataInfo::getItemId, reqDTO.getItemId()) .eq(HisRunDataInfo::getTpId, reqDTO.getTpId()) .eq(HisRunDataInfo::getInstanceId, reqDTO.getInstanceId()) - .between(HisRunDataInfo::getTimestamp, startTime, DateUtil.getTime(currentDate)) + .between(HisRunDataInfo::getTimestamp, startTime, endTime) .orderByAsc(HisRunDataInfo::getTimestamp) .list(); List times = new ArrayList<>(); @@ -100,34 +104,48 @@ public MonitorActiveRespDTO queryInfoThreadPoolMonitor(MonitorQueryReqDTO reqDTO List activeSizeList = new ArrayList<>(); List queueCapacityList = new ArrayList<>(); List queueSizeList = new ArrayList<>(); + List rangeCompletedTaskCountList = new ArrayList<>(); List completedTaskCountList = new ArrayList<>(); + List rangeRejectCountList = new ArrayList<>(); List rejectCountList = new ArrayList<>(); List queueRemainingCapacityList = new ArrayList<>(); - List currentLoadList = new ArrayList<>(); - long countTemp = 0L; - AtomicBoolean firstFlag = new AtomicBoolean(Boolean.TRUE); + long completedTaskCountTemp = 0L; + long rejectCountTemp = 0L; + boolean firstFlag = true; for (HisRunDataInfo each : hisRunDataInfos) { String time = DateUtil.format(new Date(each.getTimestamp()), NORM_TIME_PATTERN); times.add(time); poolSizeList.add(each.getPoolSize()); activeSizeList.add(each.getActiveSize()); queueSizeList.add(each.getQueueSize()); - rejectCountList.add(each.getRejectCount()); queueRemainingCapacityList.add(each.getQueueRemainingCapacity()); - currentLoadList.add(each.getCurrentLoad()); queueCapacityList.add(each.getQueueCapacity()); - if (firstFlag.get()) { + if (firstFlag) { + firstFlag = false; completedTaskCountList.add(0L); - firstFlag.set(Boolean.FALSE); - countTemp = each.getCompletedTaskCount(); + completedTaskCountTemp = each.getCompletedTaskCount(); + rejectCountTemp = each.getRejectCount(); continue; } - long completedTaskCount = each.getCompletedTaskCount(); - long countTask = completedTaskCount - countTemp; - completedTaskCountList.add(countTask); - countTemp = each.getCompletedTaskCount(); + rangeCompletedTaskCountList.add(each.getCompletedTaskCount() - completedTaskCountTemp); + completedTaskCountList.add(each.getCompletedTaskCount()); + rangeRejectCountList.add(each.getRejectCount() - rejectCountTemp); + rejectCountList.add(each.getRejectCount()); + completedTaskCountTemp = each.getCompletedTaskCount(); + rejectCountTemp = each.getRejectCount(); } - return new MonitorActiveRespDTO(times, poolSizeList, activeSizeList, queueSizeList, completedTaskCountList, rejectCountList, queueRemainingCapacityList, currentLoadList, queueCapacityList); + return MonitorActiveRespDTO.builder() + .times(times) + .poolSizeList(poolSizeList) + .activeSizeList(activeSizeList) + .queueSizeList(queueSizeList) + .queueCapacityList(queueCapacityList) + .rangeRejectCountList(rangeRejectCountList) + .rejectCountList(rejectCountList) + .completedTaskCountList(completedTaskCountList) + .rangeCompletedTaskCountList(rangeCompletedTaskCountList) + .queueRemainingCapacityList(queueRemainingCapacityList) + .build(); } @Override