mirror of https://github.com/longtai-cn/hippo4j
开发线程池历史数据存储以及监控功能, 拉去代码报错请查看 (https://github.com/acmenlt/dynamic-threadpool/issues/24)
parent
4e2a03fad0
commit
51f93b1fbd
@ -0,0 +1,35 @@
|
||||
package cn.hippo4j.common.monitor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Message request.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/12/10 21:17
|
||||
*/
|
||||
public interface MessageRequest<T extends Message> {
|
||||
|
||||
/**
|
||||
* Get content params.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<Map<String, Object>> getContentParams();
|
||||
|
||||
/**
|
||||
* Get response class.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Class<T> getResponseClass();
|
||||
|
||||
/**
|
||||
* Get message type.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
MessageTypeEnum getMessageType();
|
||||
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package cn.hippo4j.common.toolkit;
|
||||
|
||||
import cn.hippo4j.common.monitor.AbstractMessage;
|
||||
import cn.hippo4j.common.monitor.Message;
|
||||
import cn.hippo4j.common.monitor.MessageWrapper;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Message convert.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/12/10 21:27
|
||||
*/
|
||||
public class MessageConvert {
|
||||
|
||||
/**
|
||||
* {@link Message} to {@link MessageWrapper}.
|
||||
*
|
||||
* @param message
|
||||
* @return
|
||||
*/
|
||||
public static MessageWrapper convert(Message message) {
|
||||
MessageWrapper wrapper = new MessageWrapper();
|
||||
wrapper.setResponseClass(message.getClass());
|
||||
wrapper.setMessageType(message.getMessageType());
|
||||
|
||||
List<Map<String, Object>> messageMapList = new ArrayList();
|
||||
List<Message> messages = message.getMessages();
|
||||
messages.forEach(each -> messageMapList.add(BeanUtil.beanToMap(each)));
|
||||
|
||||
wrapper.setContentParams(messageMapList);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link MessageWrapper} to {@link Message}.
|
||||
*
|
||||
* @param messageWrapper
|
||||
* @return
|
||||
*/
|
||||
@SneakyThrows
|
||||
public static Message convert(MessageWrapper messageWrapper) {
|
||||
AbstractMessage message = (AbstractMessage) messageWrapper.getResponseClass().newInstance();
|
||||
List<Map<String, Object>> contentParams = messageWrapper.getContentParams();
|
||||
|
||||
List<Message> messages = new ArrayList();
|
||||
contentParams.forEach(each -> messages.add(BeanUtil.toBean(each, messageWrapper.getResponseClass())));
|
||||
|
||||
message.setMessages(messages);
|
||||
message.setMessageType(messageWrapper.getMessageType());
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package cn.hippo4j.config.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* Dashboard mapper.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/12/11 15:16
|
||||
*/
|
||||
@Mapper
|
||||
public interface DashboardMapper {
|
||||
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package cn.hippo4j.config.mapper;
|
||||
|
||||
import cn.hippo4j.config.model.HisRunDataInfo;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import lombok.Data;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* His run data mapper.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/12/10 21:33
|
||||
*/
|
||||
@Mapper
|
||||
public interface HisRunDataMapper extends BaseMapper<HisRunDataInfo> {
|
||||
|
||||
/**
|
||||
* Query thread pool task sum ranking.
|
||||
*
|
||||
* @param startTime
|
||||
* @param endTime
|
||||
* @return
|
||||
*/
|
||||
@Select("SELECT " +
|
||||
"tenant_id, item_id, tp_id, max(completed_task_count) as max_completed_task_count " +
|
||||
"FROM his_run_data " +
|
||||
"where timestamp between #{startTime} and #{endTime} " +
|
||||
"group by tenant_id, item_id, tp_id " +
|
||||
"order by max_completed_task_count desc " +
|
||||
"limit 8")
|
||||
List<ThreadPoolTaskRanking> queryThreadPoolTaskSumRanking(@Param("startTime") Long startTime, @Param("endTime") Long endTime);
|
||||
|
||||
@Data
|
||||
class ThreadPoolTaskRanking {
|
||||
|
||||
/**
|
||||
* 租户id
|
||||
*/
|
||||
private String tenantId;
|
||||
|
||||
/**
|
||||
* 项目id
|
||||
*/
|
||||
private String itemId;
|
||||
|
||||
/**
|
||||
* 线程池id
|
||||
*/
|
||||
private String tpId;
|
||||
|
||||
/**
|
||||
* 执行任务数
|
||||
*/
|
||||
private Long maxCompletedTaskCount;
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
package cn.hippo4j.config.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* His run data info.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/12/10 21:30
|
||||
*/
|
||||
@Data
|
||||
@TableName("his_run_data")
|
||||
public class HisRunDataInfo {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 租户id
|
||||
*/
|
||||
private String tenantId;
|
||||
|
||||
/**
|
||||
* 项目id
|
||||
*/
|
||||
private String itemId;
|
||||
|
||||
/**
|
||||
* 实例id
|
||||
*/
|
||||
private String instanceId;
|
||||
|
||||
/**
|
||||
* 线程池id
|
||||
*/
|
||||
private String tpId;
|
||||
|
||||
/**
|
||||
* 当前负载
|
||||
*/
|
||||
private Long currentLoad;
|
||||
|
||||
/**
|
||||
* 峰值负载
|
||||
*/
|
||||
private Long peakLoad;
|
||||
|
||||
/**
|
||||
* 线程数
|
||||
*/
|
||||
private Long poolSize;
|
||||
|
||||
/**
|
||||
* 活跃线程数
|
||||
*/
|
||||
private Long activeSize;
|
||||
|
||||
/**
|
||||
* 队列容量
|
||||
*/
|
||||
private Long queueCapacity;
|
||||
|
||||
/**
|
||||
* 队列元素
|
||||
*/
|
||||
private Long queueSize;
|
||||
|
||||
/**
|
||||
* 队列剩余容量
|
||||
*/
|
||||
private Long queueRemainingCapacity;
|
||||
|
||||
/**
|
||||
* 已完成任务计数
|
||||
*/
|
||||
private Long completedTaskCount;
|
||||
|
||||
/**
|
||||
* 拒绝次数
|
||||
*/
|
||||
private Long rejectCount;
|
||||
|
||||
/**
|
||||
* 时间戳
|
||||
*/
|
||||
private Long timestamp;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Date gmtCreate;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Date gmtModified;
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package cn.hippo4j.config.model.biz.monitor;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Monitor active resp dto.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/12/12 17:18
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class MonitorActiveRespDTO {
|
||||
|
||||
/**
|
||||
* times
|
||||
*/
|
||||
private List<String> times;
|
||||
|
||||
/**
|
||||
* poolSizeList
|
||||
*/
|
||||
List<Long> poolSizeList;
|
||||
|
||||
/**
|
||||
* activeSizeList
|
||||
*/
|
||||
List<Long> activeSizeList;
|
||||
|
||||
/**
|
||||
* queueSizeList
|
||||
*/
|
||||
List<Long> queueSizeList;
|
||||
|
||||
/**
|
||||
* completedTaskCountList
|
||||
*/
|
||||
List<Long> completedTaskCountList;
|
||||
|
||||
/**
|
||||
* rejectCountList
|
||||
*/
|
||||
List<Long> rejectCountList;
|
||||
|
||||
/**
|
||||
* queueRemainingCapacityList
|
||||
*/
|
||||
List<Long> queueRemainingCapacityList;
|
||||
|
||||
/**
|
||||
* currentLoadList
|
||||
*/
|
||||
List<Long> currentLoadList;
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package cn.hippo4j.config.model.biz.monitor;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Monitor query req dto.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/12/10 20:18
|
||||
*/
|
||||
@Data
|
||||
public class MonitorQueryReqDTO {
|
||||
|
||||
/**
|
||||
* 租户id
|
||||
*/
|
||||
private String tenantId;
|
||||
|
||||
/**
|
||||
* 项目id
|
||||
*/
|
||||
private String itemId;
|
||||
|
||||
/**
|
||||
* 线程池id
|
||||
*/
|
||||
private String tpId;
|
||||
|
||||
/**
|
||||
* 实例id
|
||||
*/
|
||||
private String instanceId;
|
||||
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package cn.hippo4j.config.model.biz.monitor;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Monitor resp dto.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/12/10 20:23
|
||||
*/
|
||||
@Data
|
||||
public class MonitorRespDTO {
|
||||
|
||||
/**
|
||||
* 租户id
|
||||
*/
|
||||
private String tenantId;
|
||||
|
||||
/**
|
||||
* 项目id
|
||||
*/
|
||||
private String itemId;
|
||||
|
||||
/**
|
||||
* 实例id
|
||||
*/
|
||||
private String instanceId;
|
||||
|
||||
/**
|
||||
* 已完成任务计数
|
||||
*/
|
||||
private String completedTaskCount;
|
||||
|
||||
/**
|
||||
* 线程池id
|
||||
*/
|
||||
private String tpId;
|
||||
|
||||
/**
|
||||
* 当前负载
|
||||
*/
|
||||
private String currentLoad;
|
||||
|
||||
/**
|
||||
* 峰值负载
|
||||
*/
|
||||
private String peakLoad;
|
||||
|
||||
/**
|
||||
* 线程数
|
||||
*/
|
||||
private String poolSize;
|
||||
|
||||
/**
|
||||
* 活跃线程数
|
||||
*/
|
||||
private String activeSize;
|
||||
|
||||
/**
|
||||
* 队列容量
|
||||
*/
|
||||
private String queueCapacity;
|
||||
|
||||
/**
|
||||
* 队列元素
|
||||
*/
|
||||
private String queueSize;
|
||||
|
||||
/**
|
||||
* 队列剩余容量
|
||||
*/
|
||||
private String queueRemainingCapacity;
|
||||
|
||||
/**
|
||||
* 拒绝次数
|
||||
*/
|
||||
private String rejectCount;
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package cn.hippo4j.config.monitor;
|
||||
|
||||
import cn.hippo4j.common.monitor.Message;
|
||||
|
||||
/**
|
||||
* Abstract monitor data execute strategy.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/12/10 20:14
|
||||
*/
|
||||
public abstract class AbstractMonitorDataExecuteStrategy<T extends Message> {
|
||||
|
||||
/**
|
||||
* Mark.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract String mark();
|
||||
|
||||
/**
|
||||
* Execute.
|
||||
*
|
||||
* @param message
|
||||
*/
|
||||
public abstract void execute(T message);
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package cn.hippo4j.config.monitor;
|
||||
|
||||
import cn.hippo4j.common.monitor.Message;
|
||||
import cn.hippo4j.common.monitor.MessageTypeEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Default monitor data resolver.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/12/10 21:47
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class DefaultMonitorDataResolver extends AbstractMonitorDataExecuteStrategy<Message> {
|
||||
|
||||
@Override
|
||||
public String mark() {
|
||||
return MessageTypeEnum.DEFAULT.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Message message) {
|
||||
log.warn("There is no suitable monitoring data storage actuator.");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package cn.hippo4j.config.monitor;
|
||||
|
||||
import cn.hippo4j.common.config.ApplicationContextHolder;
|
||||
import cn.hippo4j.common.monitor.Message;
|
||||
import cn.hippo4j.common.monitor.MessageTypeEnum;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Query monitor execute choose.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/12/10 20:12
|
||||
*/
|
||||
@Component
|
||||
public class QueryMonitorExecuteChoose implements CommandLineRunner {
|
||||
|
||||
/**
|
||||
* Storage monitoring data execution container.
|
||||
*/
|
||||
private Map<String, AbstractMonitorDataExecuteStrategy> monitorDataExecuteStrategyChooseMap = Maps.newHashMap();
|
||||
|
||||
/**
|
||||
* Choose by {@link cn.hippo4j.common.monitor.MessageTypeEnum}.
|
||||
*
|
||||
* @param messageTypeEnum {@link cn.hippo4j.common.monitor.MessageTypeEnum}
|
||||
* @return
|
||||
*/
|
||||
public AbstractMonitorDataExecuteStrategy choose(MessageTypeEnum messageTypeEnum) {
|
||||
return choose(messageTypeEnum.name());
|
||||
}
|
||||
|
||||
/**
|
||||
* Choose by mark type.
|
||||
*
|
||||
* @param markType {@link cn.hippo4j.common.monitor.MessageTypeEnum#name()}
|
||||
* @return
|
||||
*/
|
||||
public AbstractMonitorDataExecuteStrategy choose(String markType) {
|
||||
AbstractMonitorDataExecuteStrategy executeStrategy = monitorDataExecuteStrategyChooseMap.get(markType);
|
||||
if (executeStrategy == null) {
|
||||
executeStrategy = monitorDataExecuteStrategyChooseMap.get(MessageTypeEnum.DEFAULT.name());
|
||||
}
|
||||
return executeStrategy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Choose and execute.
|
||||
*
|
||||
* @param message {@link Message}
|
||||
*/
|
||||
public void chooseAndExecute(Message message) {
|
||||
MessageTypeEnum messageType = message.getMessageType();
|
||||
AbstractMonitorDataExecuteStrategy executeStrategy = choose(messageType);
|
||||
executeStrategy.execute(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
Map<String, AbstractMonitorDataExecuteStrategy> monitorDataExecuteStrategyMap =
|
||||
ApplicationContextHolder.getBeansOfType(AbstractMonitorDataExecuteStrategy.class);
|
||||
|
||||
monitorDataExecuteStrategyMap.values().forEach(each -> monitorDataExecuteStrategyChooseMap.put(each.mark(), each));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package cn.hippo4j.config.monitor;
|
||||
|
||||
import cn.hippo4j.common.monitor.MessageTypeEnum;
|
||||
import cn.hippo4j.common.monitor.RuntimeMessage;
|
||||
import cn.hippo4j.config.service.biz.HisRunDataService;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Runtime data resolver.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/12/10 20:18
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class RuntimeDataResolver extends AbstractMonitorDataExecuteStrategy<RuntimeMessage> {
|
||||
|
||||
private final HisRunDataService hisRunDataService;
|
||||
|
||||
@Override
|
||||
public String mark() {
|
||||
return MessageTypeEnum.RUNTIME.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(RuntimeMessage message) {
|
||||
log.info("[{}] Perform monitoring data persistence. content :: {}", this.getClass().getName(), JSON.toJSONString(message, SerializerFeature.PrettyFormat));
|
||||
|
||||
hisRunDataService.save(message);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package cn.hippo4j.config.service.biz;
|
||||
|
||||
import cn.hippo4j.common.monitor.Message;
|
||||
import cn.hippo4j.config.model.HisRunDataInfo;
|
||||
import cn.hippo4j.config.model.biz.monitor.MonitorActiveRespDTO;
|
||||
import cn.hippo4j.config.model.biz.monitor.MonitorQueryReqDTO;
|
||||
import cn.hippo4j.config.model.biz.monitor.MonitorRespDTO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* His run data service.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/12/10 21:28
|
||||
*/
|
||||
public interface HisRunDataService extends IService<HisRunDataInfo> {
|
||||
|
||||
/**
|
||||
* Query.
|
||||
*
|
||||
* @param reqDTO
|
||||
* @return
|
||||
*/
|
||||
List<MonitorRespDTO> query(MonitorQueryReqDTO reqDTO);
|
||||
|
||||
/**
|
||||
* Query active thread pool monitor.
|
||||
*
|
||||
* @param reqDTO
|
||||
* @return
|
||||
*/
|
||||
MonitorActiveRespDTO queryInfoThreadPoolMonitor(MonitorQueryReqDTO reqDTO);
|
||||
|
||||
/**
|
||||
* Save.
|
||||
*
|
||||
* @param message
|
||||
*/
|
||||
void save(Message message);
|
||||
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
package cn.hippo4j.config.service.biz.impl;
|
||||
|
||||
import cn.hippo4j.common.monitor.Message;
|
||||
import cn.hippo4j.common.monitor.RuntimeMessage;
|
||||
import cn.hippo4j.common.toolkit.GroupKey;
|
||||
import cn.hippo4j.config.mapper.HisRunDataMapper;
|
||||
import cn.hippo4j.config.model.HisRunDataInfo;
|
||||
import cn.hippo4j.config.model.biz.monitor.MonitorActiveRespDTO;
|
||||
import cn.hippo4j.config.model.biz.monitor.MonitorQueryReqDTO;
|
||||
import cn.hippo4j.config.model.biz.monitor.MonitorRespDTO;
|
||||
import cn.hippo4j.config.service.biz.HisRunDataService;
|
||||
import cn.hippo4j.config.toolkit.BeanUtil;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.hutool.core.date.DatePattern.NORM_TIME_PATTERN;
|
||||
|
||||
/**
|
||||
* His run data service impl.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/12/10 21:28
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class HisRunDataServiceImpl extends ServiceImpl<HisRunDataMapper, HisRunDataInfo> implements HisRunDataService {
|
||||
|
||||
@Override
|
||||
public List<MonitorRespDTO> query(MonitorQueryReqDTO reqDTO) {
|
||||
Date currentDate = new Date();
|
||||
DateTime dateTime = DateUtil.offsetMinute(currentDate, -30);
|
||||
long startTime = dateTime.getTime();
|
||||
|
||||
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, currentDate.getTime())
|
||||
.list();
|
||||
|
||||
return BeanUtil.convert(hisRunDataInfos, MonitorRespDTO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MonitorActiveRespDTO queryInfoThreadPoolMonitor(MonitorQueryReqDTO reqDTO) {
|
||||
Date currentDate = new Date();
|
||||
DateTime dateTime = DateUtil.offsetMinute(currentDate, -60);
|
||||
long startTime = dateTime.getTime();
|
||||
|
||||
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, currentDate.getTime())
|
||||
.list();
|
||||
|
||||
List<String> times = Lists.newArrayList();
|
||||
List<Long> poolSizeList = Lists.newArrayList();
|
||||
List<Long> activeSizeList = Lists.newArrayList();
|
||||
List<Long> queueSizeList = Lists.newArrayList();
|
||||
List<Long> completedTaskCountList = Lists.newArrayList();
|
||||
List<Long> rejectCountList = Lists.newArrayList();
|
||||
List<Long> queueRemainingCapacityList = Lists.newArrayList();
|
||||
List<Long> currentLoadList = Lists.newArrayList();
|
||||
|
||||
hisRunDataInfos.forEach(each -> {
|
||||
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());
|
||||
completedTaskCountList.add(each.getCompletedTaskCount());
|
||||
rejectCountList.add(each.getRejectCount());
|
||||
queueRemainingCapacityList.add(each.getQueueRemainingCapacity());
|
||||
currentLoadList.add(each.getCurrentLoad());
|
||||
});
|
||||
|
||||
return new MonitorActiveRespDTO(times, poolSizeList, activeSizeList, queueSizeList, completedTaskCountList, rejectCountList, queueRemainingCapacityList, currentLoadList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(Message message) {
|
||||
List<RuntimeMessage> runtimeMessages = message.getMessages();
|
||||
List<HisRunDataInfo> hisRunDataInfos = Lists.newArrayList();
|
||||
|
||||
runtimeMessages.forEach(each -> {
|
||||
HisRunDataInfo hisRunDataInfo = BeanUtil.convert(each, HisRunDataInfo.class);
|
||||
String[] parseKey = GroupKey.parseKey(each.getGroupKey());
|
||||
|
||||
hisRunDataInfo.setTpId(parseKey[0]);
|
||||
hisRunDataInfo.setItemId(parseKey[1]);
|
||||
hisRunDataInfo.setTenantId(parseKey[2]);
|
||||
hisRunDataInfo.setInstanceId(parseKey[3]);
|
||||
|
||||
hisRunDataInfos.add(hisRunDataInfo);
|
||||
});
|
||||
|
||||
this.saveBatch(hisRunDataInfos);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package cn.hippo4j.console.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Line chart info.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/12/11 12:49
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class LineChartInfo {
|
||||
|
||||
/**
|
||||
* completedTaskCounts
|
||||
*/
|
||||
private List<Long> completedTaskCounts;
|
||||
|
||||
/**
|
||||
* rejectCounts
|
||||
*/
|
||||
private List<Long> rejectCounts;
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package cn.hippo4j.console.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Pie chart info.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/12/11 14:27
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class PieChartInfo {
|
||||
|
||||
/**
|
||||
* itemIds
|
||||
*/
|
||||
private List<String> itemIds;
|
||||
|
||||
/**
|
||||
* pieDataList
|
||||
*/
|
||||
private List<Map<String, Object>> pieDataList;
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package cn.hippo4j.console.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Ranking chart.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/12/11 19:39
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class RankingChart {
|
||||
|
||||
/**
|
||||
* rankingChartInfoList
|
||||
*/
|
||||
private List<RankingChartInfo> rankingChartInfoList;
|
||||
|
||||
@Data
|
||||
public static class RankingChartInfo {
|
||||
|
||||
/**
|
||||
* groupKey
|
||||
*/
|
||||
private String groupKey;
|
||||
|
||||
/**
|
||||
* completedTaskCount
|
||||
*/
|
||||
private Long maxCompletedTaskCount;
|
||||
|
||||
/**
|
||||
* inst
|
||||
*/
|
||||
private Integer inst;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package cn.hippo4j.console.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Tenant chart.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/12/11 16:35
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class TenantChart {
|
||||
|
||||
/**
|
||||
* tenantCharts
|
||||
*/
|
||||
private List<Map<String, Object>> tenantCharts;
|
||||
|
||||
}
|
Loading…
Reference in new issue