Develop thread pool monitoring capabilities (#1489)

pull/1493/head
magestack 1 year ago committed by GitHub
parent 910f594076
commit 5bb1f4ab33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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 @@ import java.util.List;
* Monitor active resp dto.
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MonitorActiveRespDTO {
@ -51,11 +53,21 @@ public class MonitorActiveRespDTO {
*/
private List<Long> queueSizeList;
/**
* Range completed task count list
*/
private List<Long> rangeCompletedTaskCountList;
/**
* Completed task count list
*/
private List<Long> completedTaskCountList;
/**
* Range reject count list
*/
private List<Long> rangeRejectCountList;
/**
* Reject count list
*/
@ -66,11 +78,6 @@ public class MonitorActiveRespDTO {
*/
private List<Long> queueRemainingCapacityList;
/**
* Current load list
*/
private List<Long> currentLoadList;
/**
* Queue capacity list
*/

@ -44,4 +44,14 @@ public class MonitorQueryReqDTO {
* Instance id
*/
private String instanceId;
/**
* Start time
*/
private Long startTime;
/**
* End time
*/
private Long endTime;
}

@ -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.model.biz.monitor.MonitorRespDTO;
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.time.LocalDateTime;
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 class HisRunDataServiceImpl extends ServiceImpl<HisRunDataMapper, HisRunD
@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<HisRunDataInfo> 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<String> times = new ArrayList<>();
@ -100,34 +104,48 @@ public class HisRunDataServiceImpl extends ServiceImpl<HisRunDataMapper, HisRunD
List<Long> activeSizeList = new ArrayList<>();
List<Long> queueCapacityList = new ArrayList<>();
List<Long> queueSizeList = new ArrayList<>();
List<Long> rangeCompletedTaskCountList = new ArrayList<>();
List<Long> completedTaskCountList = new ArrayList<>();
List<Long> rangeRejectCountList = new ArrayList<>();
List<Long> rejectCountList = new ArrayList<>();
List<Long> queueRemainingCapacityList = new ArrayList<>();
List<Long> 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

Loading…
Cancel
Save