Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
王蔡翾
operation_platform
Commits
1d2b9e92
Commit
1d2b9e92
authored
Apr 10, 2026
by
王蔡翾
Browse files
新增磁盘使用情况和删除前一天数据定时任务
parent
b9ed8286
Changes
4
Show whitespace changes
Inline
Side-by-side
src/main/java/com/example/operation_platform/model/entity/ProjectServerAlertsEntity.java
View file @
1d2b9e92
...
@@ -29,7 +29,7 @@ public class ProjectServerAlertsEntity {
...
@@ -29,7 +29,7 @@ public class ProjectServerAlertsEntity {
private
Date
alertTime
;
private
Date
alertTime
;
@TableField
(
"alert_type"
)
@TableField
(
"alert_type"
)
@ApiModelProperty
(
value
=
"'CPU', 'MEMORY'"
)
@ApiModelProperty
(
value
=
"'CPU', 'MEMORY'
,'I/O'
"
)
private
String
alertType
;
private
String
alertType
;
@TableField
(
"metric_value"
)
@TableField
(
"metric_value"
)
...
...
src/main/java/com/example/operation_platform/model/entity/ProjectServerMonitorEntity.java
View file @
1d2b9e92
...
@@ -38,14 +38,18 @@ public class ProjectServerMonitorEntity {
...
@@ -38,14 +38,18 @@ public class ProjectServerMonitorEntity {
@TableField
(
value
=
"read_count"
)
@TableField
(
value
=
"read_count"
)
@ApiModelProperty
(
value
=
"磁盘读取次数"
)
@ApiModelProperty
(
value
=
"磁盘读取次数"
)
private
Integer
readCount
;
private
Long
readCount
;
@TableField
(
value
=
"write_count"
)
@TableField
(
value
=
"write_count"
)
@ApiModelProperty
(
value
=
"磁盘写入次数"
)
@ApiModelProperty
(
value
=
"磁盘写入次数"
)
private
Integer
writeCount
;
private
Long
writeCount
;
@TableField
(
value
=
"ip_address"
)
@TableField
(
value
=
"ip_address"
)
@ApiModelProperty
(
value
=
"ip地址"
)
@ApiModelProperty
(
value
=
"ip地址"
)
private
String
ipAddress
;
private
String
ipAddress
;
@TableField
(
value
=
"io_percent"
)
@ApiModelProperty
(
value
=
"磁盘使用率"
)
private
String
ioPercent
;
}
}
src/main/java/com/example/operation_platform/task/MonitorCleanTask.java
0 → 100644
View file @
1d2b9e92
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
();
}
}
src/main/resources/mapper/ProjectServerMonitorMapper.xml
View file @
1d2b9e92
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
<mapper
namespace=
"com.example.operation_platform.mapper.ProjectServerMonitorMapper"
>
<mapper
namespace=
"com.example.operation_platform.mapper.ProjectServerMonitorMapper"
>
<select
id=
"ipList"
resultType=
"com.example.operation_platform.model.vo.ProjectServerMonitorVO"
>
<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 (
FROM (
SELECT *,
SELECT *,
ROW_NUMBER() OVER (PARTITION BY ip_address ORDER BY timestamp DESC) as rn
ROW_NUMBER() OVER (PARTITION BY ip_address ORDER BY timestamp DESC) as rn
...
@@ -26,7 +26,8 @@
...
@@ -26,7 +26,8 @@
memory_percent,
memory_percent,
read_count,
read_count,
write_count,
write_count,
ip_address
ip_address,
io_percent
from
from
project_server_monitor
project_server_monitor
<where>
<where>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment