Commit 1d2b9e92 authored by 王蔡翾's avatar 王蔡翾
Browse files

新增磁盘使用情况和删除前一天数据定时任务

parent b9ed8286
......@@ -29,7 +29,7 @@ public class ProjectServerAlertsEntity {
private Date alertTime;
@TableField("alert_type")
@ApiModelProperty(value = "'CPU', 'MEMORY'")
@ApiModelProperty(value = "'CPU', 'MEMORY','I/O'")
private String alertType;
@TableField("metric_value")
......
......@@ -38,14 +38,18 @@ public class ProjectServerMonitorEntity {
@TableField(value = "read_count")
@ApiModelProperty(value = "磁盘读取次数")
private Integer readCount;
private Long readCount;
@TableField(value = "write_count")
@ApiModelProperty(value = "磁盘写入次数")
private Integer writeCount;
private Long writeCount;
@TableField(value = "ip_address")
@ApiModelProperty(value = "ip地址")
private String ipAddress;
@TableField(value = "io_percent")
@ApiModelProperty(value = "磁盘使用率")
private String ioPercent;
}
package com.example.operation_platform.task;
import com.example.operation_platform.model.dto.ProjectServerMonitorDTO;
import com.example.operation_platform.model.vo.ProjectServerMonitorVO;
import com.example.operation_platform.service.ProjectServerMonitorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@Component
@Slf4j
public class MonitorCleanTask {
@Resource
private ProjectServerMonitorService projectServerMonitorService;
@Scheduled(cron = "0 0 1 * * ?")
public void process() {
ProjectServerMonitorDTO projectServerMonitorDTO = new ProjectServerMonitorDTO();
// 获取前一天的开始时刻(00:00:00)
Date startOfPrevDay = getStartOfPrevDay();
// 获取前一天的结束时刻(23:59:59)
Date endOfPrevDay = getEndOfPrevDay();
projectServerMonitorDTO.setStartDate(startOfPrevDay);
projectServerMonitorDTO.setEndDate(endOfPrevDay);
//查询前一天的所有数据
List<ProjectServerMonitorVO> projectServerMonitorList = projectServerMonitorService.dataList(projectServerMonitorDTO);
//删除数据
for (ProjectServerMonitorVO projectServerMonitorVO : projectServerMonitorList) {
projectServerMonitorService.removeById(projectServerMonitorVO.getId());
}
log.info("删除前一天的数据成功");
}
/**
* 获取前一天的 00:00:00
* @return Date 对象
*/
public static Date getStartOfPrevDay() {
Calendar cal = Calendar.getInstance();
// 减一天
cal.add(Calendar.DAY_OF_MONTH, -1);
// 设置时间为当天的 00:00:00.000
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}
/**
* 获取前一天的 23:59:59
* @return Date 对象
*/
public static Date getEndOfPrevDay() {
Calendar cal = Calendar.getInstance();
// 减一天
cal.add(Calendar.DAY_OF_MONTH, -1);
// 设置时间为当天的 23:59:59.999(秒级精度一般 59 即可)
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.MINUTE, 59);
cal.set(Calendar.SECOND, 59);
cal.set(Calendar.MILLISECOND, 999);
return cal.getTime();
}
}
......@@ -4,7 +4,7 @@
<mapper namespace="com.example.operation_platform.mapper.ProjectServerMonitorMapper">
<select id="ipList" resultType="com.example.operation_platform.model.vo.ProjectServerMonitorVO">
SELECT ip_address,cpu_percent,memory_percent
SELECT ip_address,cpu_percent,memory_percent,io_percent
FROM (
SELECT *,
ROW_NUMBER() OVER (PARTITION BY ip_address ORDER BY timestamp DESC) as rn
......@@ -26,7 +26,8 @@
memory_percent,
read_count,
write_count,
ip_address
ip_address,
io_percent
from
project_server_monitor
<where>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment