1、增加磁盘HDD类型已用空间图形接口。
2、增加磁盘HDD类型总空间字段计算。 3、增加硬盘设备监控列表接口。
This commit is contained in:
+104
-33
@@ -53,7 +53,7 @@ public class EchartsDataUtils {
|
||||
return Math.round(microseconds / 1_000_000.0 * 100.0) / 100.0;
|
||||
}
|
||||
/**
|
||||
* 构建ECharts图表数据(带时间补全和特殊值处理)
|
||||
* 构建ECharts图表数据(带时间补全和特殊值处理)- 修复版本
|
||||
*/
|
||||
public static <T> Map<String, Object> buildEchartsDataAutoPadding(
|
||||
List<T> list,
|
||||
@@ -84,57 +84,64 @@ public class EchartsDataUtils {
|
||||
.sorted(Comparator.comparing(timeExtractor))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 自动检测时间间隔(用于数据期间)
|
||||
// 自动检测时间间隔
|
||||
long timeInterval = detectTimeInterval(sortedList, timeExtractor);
|
||||
|
||||
// 获取数据实际的时间范围
|
||||
Date actualStartTime = timeExtractor.apply(sortedList.get(0));
|
||||
Date actualEndTime = timeExtractor.apply(sortedList.get(sortedList.size() - 1));
|
||||
|
||||
// 计算稀疏间隔(用于数据期间外)
|
||||
// 计算稀疏间隔
|
||||
long totalTimeRange = endDate.getTime() - startDate.getTime();
|
||||
long sparseInterval = totalTimeRange > 12L * 30 * 24 * 60 * 60 * 1000 ?
|
||||
30L * 24 * 60 * 60 * 1000 : 2L * 24 * 60 * 60 * 1000;
|
||||
|
||||
// 生成三段时间序列
|
||||
// 生成完整的时间序列
|
||||
List<Date> fullTimeSeries = new ArrayList<>();
|
||||
|
||||
// 1. 开始时间到数据开始时间(稀疏间隔)
|
||||
if (startDate.before(actualStartTime)) {
|
||||
List<Date> beforeSeries = generateTimeSeries(startDate, actualStartTime, sparseInterval);
|
||||
List<Date> beforeSeries = generateSparseTimeSeries(startDate, actualStartTime, sparseInterval);
|
||||
fullTimeSeries.addAll(beforeSeries);
|
||||
}
|
||||
|
||||
// 2. 数据开始时间到数据结束时间(正常间隔)
|
||||
List<Date> dataSeries = generateTimeSeries(actualStartTime, actualEndTime, timeInterval);
|
||||
// 2. 数据开始时间到数据结束时间 - 以第一个数据点的时间为基准生成序列
|
||||
List<Date> dataSeries = generateTimeSeriesFromDataPoints(actualStartTime, actualEndTime,
|
||||
timeInterval, actualStartTime);
|
||||
fullTimeSeries.addAll(dataSeries);
|
||||
|
||||
// 3. 数据结束时间到结束时间(稀疏间隔)
|
||||
if (actualEndTime.before(endDate)) {
|
||||
// 调整actualEndTime的下一个点开始,避免重复
|
||||
// 从actualEndTime的下一个时间点开始
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(actualEndTime);
|
||||
cal.setTimeInMillis(cal.getTimeInMillis() + timeInterval);
|
||||
cal.add(Calendar.MILLISECOND, (int)timeInterval);
|
||||
Date nextAfterActualEnd = cal.getTime();
|
||||
|
||||
if (nextAfterActualEnd.before(endDate) || nextAfterActualEnd.equals(endDate)) {
|
||||
List<Date> afterSeries = generateTimeSeries(nextAfterActualEnd, endDate, sparseInterval);
|
||||
List<Date> afterSeries = generateSparseTimeSeries(nextAfterActualEnd, endDate, sparseInterval);
|
||||
fullTimeSeries.addAll(afterSeries);
|
||||
}
|
||||
}
|
||||
|
||||
// 创建时间到数据的映射(考虑时间精度)
|
||||
Map<Long, T> timeDataMap = sortedList.stream()
|
||||
.collect(Collectors.toMap(
|
||||
item -> normalizeTime(timeExtractor.apply(item), timeInterval),
|
||||
Function.identity(),
|
||||
(a, b) -> a
|
||||
));
|
||||
// 去重并排序
|
||||
fullTimeSeries = fullTimeSeries.stream()
|
||||
.distinct()
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 创建时间到数据的映射
|
||||
Map<String, T> timeDataMap = new HashMap<>();
|
||||
for (T item : sortedList) {
|
||||
Date itemTime = timeExtractor.apply(item);
|
||||
String timeKey = parseDateToStr(itemTime);
|
||||
timeDataMap.put(timeKey, item);
|
||||
}
|
||||
|
||||
// 检测整个数据集中是否有真实数据
|
||||
boolean hasRealData = checkHasRealData(sortedList, dataExtractors);
|
||||
|
||||
// 特殊处理:查找percentile95的固定值
|
||||
// 查找特殊字段的固定值
|
||||
Object fixedPercentile95Value = findFixedValueForPercentile95(sortedList, dataExtractors);
|
||||
|
||||
// 准备X轴和Y轴数据
|
||||
@@ -145,19 +152,16 @@ public class EchartsDataUtils {
|
||||
dataExtractors.keySet().forEach(name ->
|
||||
yData.put(name, new ArrayList<>()));
|
||||
|
||||
// 记录当前处理的时间点索引
|
||||
int timeIndex = 0;
|
||||
|
||||
for (Date time : fullTimeSeries) {
|
||||
// X轴数据
|
||||
xAxisData.add(parseDateToStr(time));
|
||||
String timeStr = parseDateToStr(time);
|
||||
xAxisData.add(timeStr);
|
||||
|
||||
// 判断当前时间点是否在数据实际时间范围内
|
||||
boolean isInDataRange = !time.before(actualStartTime) && !time.after(actualEndTime);
|
||||
|
||||
// Y轴数据
|
||||
Long normalizedTime = normalizeTime(time, timeInterval);
|
||||
T item = timeDataMap.get(normalizedTime);
|
||||
// 查找对应的数据项
|
||||
T item = timeDataMap.get(timeStr);
|
||||
|
||||
for (Map.Entry<String, Function<T, ?>> entry : dataExtractors.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
@@ -169,20 +173,18 @@ public class EchartsDataUtils {
|
||||
if (item != null) {
|
||||
// 有真实数据
|
||||
Object value = extractor.apply(item);
|
||||
seriesData.add(value != null ? value : getDefaultValue(name, fixedPercentile95Value, timeIndex, hasRealData));
|
||||
seriesData.add(value != null ? value : null);
|
||||
} else {
|
||||
// 智能数据补全
|
||||
if (isInDataRange) {
|
||||
// 在数据时间范围内但该时间点无数据:使用智能补全策略
|
||||
seriesData.add(getDefaultValue(name, fixedPercentile95Value, timeIndex, hasRealData));
|
||||
// 在数据时间范围内但该时间点无数据(数据缺失点)
|
||||
seriesData.add(getDefaultValue(name, fixedPercentile95Value, xAxisData.size()-1, hasRealData));
|
||||
} else {
|
||||
// 在数据时间范围外(开始时间前或结束时间后):使用空数据补全策略
|
||||
seriesData.add(getEmptyDataDefaultValue(name, timeIndex));
|
||||
// 在数据时间范围外
|
||||
seriesData.add(getEmptyDataDefaultValue(name, xAxisData.size()-1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
timeIndex++;
|
||||
}
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
@@ -191,12 +193,81 @@ public class EchartsDataUtils {
|
||||
return result;
|
||||
|
||||
} catch (Exception e) {
|
||||
// 记录日志
|
||||
System.err.println("构建图表数据失败: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
return createEmptyResult(dataExtractors.keySet(), startTime, endTime);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从第一个数据点开始生成时间序列
|
||||
*/
|
||||
private static List<Date> generateTimeSeriesFromDataPoints(Date start, Date end,
|
||||
long interval, Date firstDataPoint) {
|
||||
List<Date> timeSeries = new ArrayList<>();
|
||||
|
||||
if (interval <= 0) {
|
||||
interval = 300000L; // 默认5分钟
|
||||
}
|
||||
|
||||
// 使用第一个数据点的时间作为基准
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(firstDataPoint);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
// 从第一个数据点开始向前找,直到找到小于等于start的时间点
|
||||
while (calendar.getTime().after(start)) {
|
||||
calendar.add(Calendar.MILLISECOND, -(int)interval);
|
||||
}
|
||||
|
||||
// 如果当前位置在start之前,前进一个间隔
|
||||
if (calendar.getTime().before(start)) {
|
||||
calendar.add(Calendar.MILLISECOND, (int)interval);
|
||||
}
|
||||
|
||||
// 生成时间序列
|
||||
while (!calendar.getTime().after(end)) {
|
||||
timeSeries.add(calendar.getTime());
|
||||
calendar.add(Calendar.MILLISECOND, (int)interval);
|
||||
}
|
||||
|
||||
return timeSeries.stream()
|
||||
.distinct()
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成稀疏时间序列
|
||||
*/
|
||||
private static List<Date> generateSparseTimeSeries(Date start, Date end, long interval) {
|
||||
List<Date> timeSeries = new ArrayList<>();
|
||||
|
||||
if (interval <= 0) {
|
||||
interval = 2L * 24 * 60 * 60 * 1000; // 默认2天
|
||||
}
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(start);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
// 包含开始时间
|
||||
timeSeries.add(calendar.getTime());
|
||||
|
||||
while (true) {
|
||||
calendar.add(Calendar.MILLISECOND, (int)interval);
|
||||
if (calendar.getTime().after(end)) {
|
||||
break;
|
||||
}
|
||||
timeSeries.add(calendar.getTime());
|
||||
}
|
||||
|
||||
return timeSeries.stream()
|
||||
.distinct()
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取空数据默认值(用于数据时间范围外的点)
|
||||
*/
|
||||
|
||||
+35
@@ -383,4 +383,39 @@ public class SpeedUtils {
|
||||
if (mbitValue == null) return BigDecimal.ZERO;
|
||||
return mbitValue.multiply(new BigDecimal("1000000"));
|
||||
}
|
||||
public static String determineUnitByValue(Long value) {
|
||||
if (value == null || value == 0) {
|
||||
return "KB";
|
||||
}
|
||||
|
||||
// 注意:这里使用二进制单位(1024)
|
||||
if (value >= 1024L * 1024 * 1024 * 1024) { // >= 1TB
|
||||
return "TB";
|
||||
} else if (value >= 1024L * 1024 * 1024) { // >= 1GB
|
||||
return "GB";
|
||||
} else if (value >= 1024L * 1024) { // >= 1MB
|
||||
return "MB";
|
||||
} else {
|
||||
return "KB";
|
||||
}
|
||||
}
|
||||
// 工具方法:获取单位换算除数
|
||||
public static BigDecimal get1024Divisor(String unit) {
|
||||
switch (unit) {
|
||||
case "GB":
|
||||
case "Gb":
|
||||
return new BigDecimal(1024L * 1024 * 1024); // 1GB = 1024^3
|
||||
case "MB":
|
||||
case "Mb":
|
||||
return new BigDecimal(1024L * 1024); // 1MB = 1024^2
|
||||
case "KB":
|
||||
case "Kb":
|
||||
return new BigDecimal(1024); // 1KB = 1024
|
||||
case "TB":
|
||||
case "Tb":
|
||||
return new BigDecimal(1024L * 1024 * 1024 * 1024); // 1TB = 1024^4
|
||||
default:
|
||||
return new BigDecimal(1024); // 默认返回KB的除数
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-3
@@ -199,7 +199,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
update_by VARCHAR(64) COMMENT '修改人',
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_client_fiber_time (client_id, create_time, fiber_port_name)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='光模块信息表';
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='光模块信息表';
|
||||
</update>
|
||||
<update id="createDiskInfo">
|
||||
CREATE TABLE IF NOT EXISTS ${tableName} (
|
||||
@@ -221,8 +221,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
`type` varchar(255) COMMENT '磁盘类型',
|
||||
`used_space` bigint(20) COMMENT '已用空间',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY uk_client_disk_time (`client_id`, `name`, `create_time`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='磁盘监控信息表';
|
||||
UNIQUE KEY uk_client_disk_time (`client_id`, `name`, `create_time`),
|
||||
INDEX idx_clent_type_time(`client_id`, `create_time`, `type`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='磁盘监控信息表';
|
||||
</update>
|
||||
<!-- 单条插入语句 -->
|
||||
<insert id="insert">
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ public class AllDiskNameController extends BaseController
|
||||
@PostMapping("/list")
|
||||
public AjaxResult list(@RequestBody AllDiskName allDiskName)
|
||||
{
|
||||
List<AllDiskName> list = allDiskNameService.selectAllDiskNameList(allDiskName);
|
||||
List<AllDiskName> list = allDiskNameService.selectDiskInfoList(allDiskName);
|
||||
return success(list);
|
||||
}
|
||||
|
||||
|
||||
+10
@@ -138,6 +138,16 @@ public class InitialDiskInfoController extends BaseController
|
||||
Map<String, Object> echartsData = initialDiskInfoService.rwBytesEcharts(initialDiskInfo);
|
||||
return success(echartsData);
|
||||
}
|
||||
/**
|
||||
* HDD类型已用空间
|
||||
* @param initialDiskInfo
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/usedSpaceEcharts")
|
||||
public AjaxResult usedSpaceEcharts(@RequestBody InitialDiskInfo initialDiskInfo){
|
||||
Map<String, Object> echartsData = initialDiskInfoService.usedSpaceEcharts(initialDiskInfo);
|
||||
return success(echartsData);
|
||||
}
|
||||
/**
|
||||
* 获取指定服务器的磁盘名称
|
||||
* @param initialDiskInfo
|
||||
|
||||
@@ -39,5 +39,26 @@ public class AllDiskName extends BaseEntity
|
||||
private String writeIops;
|
||||
/** 操纵类型 1测试磁盘IOPS,2卸载分区 */
|
||||
private Integer processType;
|
||||
/** 磁盘序列号 */
|
||||
@Excel(name = "磁盘序列号")
|
||||
private String serial;
|
||||
|
||||
/** 磁盘总大小(GB) */
|
||||
@Excel(name = "磁盘总大小(GB)")
|
||||
private Long total;
|
||||
|
||||
/** 磁盘写入速率(字节/秒) */
|
||||
@Excel(name = "磁盘写入速率(字节/秒)")
|
||||
private Long writeSpeed;
|
||||
|
||||
/** 磁盘读取速率(字节/秒) */
|
||||
@Excel(name = "磁盘读取速率(字节/秒)")
|
||||
private Long readSpeed;
|
||||
/** 已用空间 */
|
||||
private Long usedSpace;
|
||||
/** 磁盘类型 */
|
||||
private String type;
|
||||
/** 表名 */
|
||||
private String tableName;
|
||||
|
||||
}
|
||||
|
||||
@@ -83,6 +83,8 @@ public class InitialDiskInfo extends BaseEntity
|
||||
private String tableName;
|
||||
/** 批量插入列表 */
|
||||
private List<InitialDiskInfo> list;
|
||||
/** 单位 */
|
||||
private String unit;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -61,4 +61,6 @@ public interface AllDiskNameMapper
|
||||
public int deleteAllDiskNameByIds(Long[] ids);
|
||||
|
||||
int batchInsertAllDistName(List<AllDiskName> dataList);
|
||||
|
||||
List<AllDiskName> selectDiskInfoList(AllDiskName allDiskName);
|
||||
}
|
||||
|
||||
@@ -84,4 +84,6 @@ public interface InitialDiskInfoMapper
|
||||
List<Map> getAllDistName(InitialDiskInfo initialDiskInfo);
|
||||
|
||||
List<InitialDiskInfo> selectInitialDiskInfoListByCondition(InitialDiskInfo condition);
|
||||
|
||||
InitialDiskInfo getDiskTotal(InitialDiskInfo initialDiskInfo);
|
||||
}
|
||||
|
||||
@@ -64,4 +64,6 @@ public interface IAllDiskNameService
|
||||
int batchInsertAllDistName(List<InitialDiskInfo> dataList);
|
||||
|
||||
int issuanceOperation(AllDiskName allDiskName);
|
||||
|
||||
List<AllDiskName> selectDiskInfoList(AllDiskName allDiskName);
|
||||
}
|
||||
|
||||
+8
@@ -94,6 +94,12 @@ public interface IInitialDiskInfoService
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> rwBytesEcharts(InitialDiskInfo initialDiskInfo);
|
||||
/**
|
||||
* HDD类型已用空间图
|
||||
* @param initialDiskInfo
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> usedSpaceEcharts(InitialDiskInfo initialDiskInfo);
|
||||
|
||||
/**
|
||||
* 获取指定服务器的磁盘名称
|
||||
@@ -101,4 +107,6 @@ public interface IInitialDiskInfoService
|
||||
* @return
|
||||
*/
|
||||
List<Map> getAllDistName(InitialDiskInfo initialDiskInfo);
|
||||
|
||||
InitialDiskInfo getDiskTotal(InitialDiskInfo initialDiskInfo);
|
||||
}
|
||||
|
||||
+9
@@ -3,6 +3,7 @@ package com.tongran.rocketmq.service.impl;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.tongran.common.core.enums.MsgEnum;
|
||||
import com.tongran.common.core.utils.DateUtils;
|
||||
import com.tongran.common.core.utils.TableSubUtil;
|
||||
import com.tongran.rocketmq.domain.AllDiskName;
|
||||
import com.tongran.rocketmq.domain.DeviceMessage;
|
||||
import com.tongran.rocketmq.domain.InitialDiskInfo;
|
||||
@@ -153,4 +154,12 @@ public class AllDiskNameServiceImpl implements IAllDiskNameService
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AllDiskName> selectDiskInfoList(AllDiskName allDiskName) {
|
||||
String tableName = TableSubUtil.getTableName(DateUtils.getNowDate(), "initial_disk_info");
|
||||
allDiskName.setTableName(tableName);
|
||||
List<AllDiskName> list = allDiskNameMapper.selectDiskInfoList(allDiskName);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
+10
-8
@@ -1,15 +1,10 @@
|
||||
package com.tongran.rocketmq.service.impl;
|
||||
|
||||
import com.tongran.common.core.utils.*;
|
||||
import com.tongran.rocketmq.domain.InitialBandwidthTraffic;
|
||||
import com.tongran.rocketmq.domain.InitialCpuInfo;
|
||||
import com.tongran.rocketmq.domain.InitialSystemOtherCollectData;
|
||||
import com.tongran.rocketmq.domain.RmNetworkInterfaceChild;
|
||||
import com.tongran.rocketmq.mapper.InitialBandwidthTrafficMapper;
|
||||
import com.tongran.rocketmq.mapper.InitialCpuInfoMapper;
|
||||
import com.tongran.rocketmq.mapper.InitialSystemOtherCollectDataMapper;
|
||||
import com.tongran.rocketmq.mapper.RmNetworkInterfaceChildMapper;
|
||||
import com.tongran.rocketmq.domain.*;
|
||||
import com.tongran.rocketmq.mapper.*;
|
||||
import com.tongran.rocketmq.service.IInitialBandwidthTrafficService;
|
||||
import com.tongran.rocketmq.service.IInitialDiskInfoService;
|
||||
import com.tongran.rocketmq.utils.TableRouterUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@@ -43,6 +38,8 @@ public class InitialBandwidthTrafficServiceImpl implements IInitialBandwidthTraf
|
||||
private InitialSystemOtherCollectDataMapper initialSystemOtherCollectDataMapper;
|
||||
@Autowired
|
||||
private InitialCpuInfoMapper initialCpuInfoMapper;
|
||||
@Autowired
|
||||
private IInitialDiskInfoService diskInfoService;
|
||||
|
||||
/**
|
||||
* 查询初始带宽流量
|
||||
@@ -631,6 +628,11 @@ public class InitialBandwidthTrafficServiceImpl implements IInitialBandwidthTraf
|
||||
}
|
||||
resultMap.put("cpuUti", cpuInfo.getUti());
|
||||
resultMap.put("cpuCores", cpuInfo.getCores());
|
||||
InitialDiskInfo diskInfo = new InitialDiskInfo();
|
||||
diskInfo.setClientId(initialBandwidthTraffic.getClientId());
|
||||
diskInfo.setType("HDD");
|
||||
InitialDiskInfo initialDiskInfo = diskInfoService.getDiskTotal(diskInfo);
|
||||
resultMap.put("diskTotal", initialDiskInfo.getTotal());
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
|
||||
+45
-5
@@ -1,9 +1,6 @@
|
||||
package com.tongran.rocketmq.service.impl;
|
||||
|
||||
import com.tongran.common.core.utils.DateUtils;
|
||||
import com.tongran.common.core.utils.EchartsDataUtils;
|
||||
import com.tongran.common.core.utils.TableSubUtil;
|
||||
import com.tongran.common.core.utils.UnitChangeUtil;
|
||||
import com.tongran.common.core.utils.*;
|
||||
import com.tongran.rocketmq.domain.InitialDiskInfo;
|
||||
import com.tongran.rocketmq.mapper.InitialDiskInfoMapper;
|
||||
import com.tongran.rocketmq.service.IAllDiskNameService;
|
||||
@@ -15,6 +12,8 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -175,6 +174,19 @@ public class InitialDiskInfoServiceImpl implements IInitialDiskInfoService
|
||||
}
|
||||
return info;
|
||||
}
|
||||
@Override
|
||||
public InitialDiskInfo getDiskTotal(InitialDiskInfo initialDiskInfo) {
|
||||
String tableName = TableSubUtil.getTableName(DateUtils.getNowDate(), TABLE_PREFIX);
|
||||
initialDiskInfo.setTableName(tableName);
|
||||
InitialDiskInfo info = initialDiskInfoMapper.getDiskTotal(initialDiskInfo);
|
||||
if(info != null){
|
||||
long gbUnit = 1024L * 1024 * 1024;
|
||||
info.setTotal(info.getTotal() / gbUnit);
|
||||
}else {
|
||||
return new InitialDiskInfo();
|
||||
}
|
||||
return info;
|
||||
}
|
||||
/**
|
||||
* 分表查询硬盘信息
|
||||
* @param queryParam
|
||||
@@ -191,6 +203,7 @@ public class InitialDiskInfoServiceImpl implements IInitialDiskInfoService
|
||||
condition.setTableName(tableName);
|
||||
condition.setClientId(queryParam.getClientId());
|
||||
condition.setName(queryParam.getName());
|
||||
condition.setType(queryParam.getType());
|
||||
condition.setStartTime(queryParam.getStartTime());
|
||||
condition.setEndTime(queryParam.getEndTime());
|
||||
return initialDiskInfoMapper.selectInitialDiskInfoListByCondition(condition).stream();
|
||||
@@ -236,7 +249,34 @@ public class InitialDiskInfoServiceImpl implements IInitialDiskInfoService
|
||||
extractors.put("writeBytesData", info -> info.getWriteBytes());
|
||||
return EchartsDataUtils.buildEchartsData(list, InitialDiskInfo::getCreateTime, extractors);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> usedSpaceEcharts(InitialDiskInfo initialDiskInfo) {
|
||||
initialDiskInfo.setType("HDD");
|
||||
List<InitialDiskInfo> list = getDistInfoSharding(initialDiskInfo);
|
||||
String unit = "KB";
|
||||
if(list != null && !list.isEmpty()){
|
||||
Long totalUsedSpace = 0L;
|
||||
for (InitialDiskInfo diskInfo : list) {
|
||||
totalUsedSpace += diskInfo.getUsedSpace();
|
||||
}
|
||||
Long avgUsedSpace = totalUsedSpace/list.size();
|
||||
unit = SpeedUtils.determineUnitByValue(avgUsedSpace);
|
||||
}
|
||||
// 计算单位
|
||||
if (initialDiskInfo.getUnit() != null) {
|
||||
unit = initialDiskInfo.getUnit();
|
||||
}
|
||||
BigDecimal divisor = SpeedUtils.get1024Divisor(unit);
|
||||
Map<String, Function<InitialDiskInfo, ?>> extractors = new LinkedHashMap<>();
|
||||
extractors.put("usedSpace", info -> {
|
||||
BigDecimal usedSpace = new BigDecimal(info.getUsedSpace());
|
||||
return usedSpace.divide(divisor, 0, RoundingMode.DOWN).longValue();
|
||||
});
|
||||
Map<String, Object> resultMap = EchartsDataUtils.buildEchartsDataAutoPadding(
|
||||
list,InitialDiskInfo::getCreateTime, extractors, initialDiskInfo.getStartTime(), initialDiskInfo.getEndTime());
|
||||
resultMap.put("unit", unit);
|
||||
return resultMap;
|
||||
}
|
||||
/**
|
||||
* 获取指定服务器的磁盘名称
|
||||
* @param initialDiskInfo
|
||||
|
||||
@@ -23,7 +23,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
|
||||
<select id="selectAllDiskNameList" parameterType="AllDiskName" resultMap="AllDiskNameResult">
|
||||
<include refid="selectAllDiskNameVo"/>
|
||||
<where>
|
||||
<where>
|
||||
<if test="clientId != null and clientId != ''"> and client_id = #{clientId}</if>
|
||||
<if test="name != null and name != ''"> and name = #{name}</if>
|
||||
<if test="status != null "> and status = #{status}</if>
|
||||
@@ -126,4 +126,37 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<select id="selectDiskInfoList" parameterType="AllDiskName" resultType="AllDiskName">
|
||||
SELECT
|
||||
a.id,
|
||||
a.client_id as clientId,
|
||||
a.name,
|
||||
a.status,
|
||||
a.read_iops as readIops,
|
||||
a.write_iops as writeIops,
|
||||
a.create_time as createTime,
|
||||
a.update_time as updateTime,
|
||||
b.serial,
|
||||
b.total,
|
||||
b.write_speed as writeSpeed,
|
||||
b.read_speed as readSpeed,
|
||||
b.type,
|
||||
b.used_space as usedSpace
|
||||
FROM all_disk_name a
|
||||
LEFT JOIN (
|
||||
SELECT client_id, name, MAX(create_time) as max_create_time
|
||||
FROM ${tableName}
|
||||
GROUP BY client_id, name
|
||||
) latest ON a.client_id = latest.client_id AND a.name = latest.name
|
||||
LEFT JOIN ${tableName} b
|
||||
ON latest.client_id = b.client_id
|
||||
AND latest.name = b.name
|
||||
AND latest.max_create_time = b.create_time
|
||||
<where>
|
||||
<if test="clientId != null">
|
||||
AND a.client_id = #{clientId}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -213,4 +213,16 @@
|
||||
</where>
|
||||
group by name
|
||||
</select>
|
||||
<select id="getDiskTotal" parameterType="InitialDiskInfo" resultMap="InitialDiskInfoResult">
|
||||
select sum(t2.total) as total
|
||||
from ${tableName} t2
|
||||
inner join (
|
||||
select client_id, type, max(create_time) as latest_time
|
||||
from ${tableName}
|
||||
where client_id = #{clientId} and type = #{type}
|
||||
group by client_id, type
|
||||
) t1 on t2.client_id = t1.client_id
|
||||
and t2.type = t1.type
|
||||
and t2.create_time = t1.latest_time
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user