Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop thread pool monitoring capabilities #1489

Merged
merged 1 commit into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package cn.hippo4j.config.model.biz.monitor;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

Expand All @@ -27,6 +28,7 @@
* Monitor active resp dto.
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MonitorActiveRespDTO {
Expand All @@ -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
*/
Expand All @@ -66,11 +78,6 @@ public class MonitorActiveRespDTO {
*/
private List<Long> queueRemainingCapacityList;

/**
* Current load list
*/
private List<Long> currentLoadList;

/**
* Queue capacity list
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,14 @@ public class MonitorQueryReqDTO {
* Instance id
*/
private String instanceId;

/**
* Start time
*/
private Long startTime;

/**
* End time
*/
private Long endTime;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -84,50 +83,69 @@ public List<MonitorRespDTO> 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<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<>();
List<Long> poolSizeList = new ArrayList<>();
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
Expand Down