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
181b02cc
Commit
181b02cc
authored
Mar 20, 2026
by
wujipeng
Browse files
服务器cpu、内存超阈值报警
parent
99c2501f
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/main/java/com/example/operation_platform/mapper/ProjectServerAlertsMapper.java
View file @
181b02cc
...
@@ -6,7 +6,9 @@ import com.example.operation_platform.model.dto.ProjectServerAlertsDTO;
...
@@ -6,7 +6,9 @@ import com.example.operation_platform.model.dto.ProjectServerAlertsDTO;
import
com.example.operation_platform.model.entity.ProjectServerAlertsEntity
;
import
com.example.operation_platform.model.entity.ProjectServerAlertsEntity
;
import
com.example.operation_platform.model.vo.ProjectServerAlertsVO
;
import
com.example.operation_platform.model.vo.ProjectServerAlertsVO
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -19,4 +21,7 @@ import java.util.List;
...
@@ -19,4 +21,7 @@ import java.util.List;
public
interface
ProjectServerAlertsMapper
extends
BaseMapper
<
ProjectServerAlertsEntity
>
{
public
interface
ProjectServerAlertsMapper
extends
BaseMapper
<
ProjectServerAlertsEntity
>
{
List
<
ProjectServerAlertsVO
>
alertsList
(
ProjectServerAlertsDTO
projectServerAlertsDTO
);
List
<
ProjectServerAlertsVO
>
alertsList
(
ProjectServerAlertsDTO
projectServerAlertsDTO
);
List
<
ProjectServerAlertsVO
>
selectData
(
@Param
(
"time"
)
Date
time
);
}
}
src/main/java/com/example/operation_platform/model/vo/ProjectServerAlertsVO.java
View file @
181b02cc
...
@@ -14,4 +14,7 @@ import lombok.EqualsAndHashCode;
...
@@ -14,4 +14,7 @@ import lombok.EqualsAndHashCode;
@EqualsAndHashCode
(
callSuper
=
true
)
@EqualsAndHashCode
(
callSuper
=
true
)
@Data
@Data
public
class
ProjectServerAlertsVO
extends
ProjectServerAlertsEntity
{
public
class
ProjectServerAlertsVO
extends
ProjectServerAlertsEntity
{
private
String
projectId
;
}
}
src/main/java/com/example/operation_platform/service/ProjectServerAlertsService.java
View file @
181b02cc
...
@@ -5,6 +5,7 @@ import com.example.operation_platform.model.dto.ProjectServerAlertsDTO;
...
@@ -5,6 +5,7 @@ import com.example.operation_platform.model.dto.ProjectServerAlertsDTO;
import
com.example.operation_platform.model.entity.ProjectServerAlertsEntity
;
import
com.example.operation_platform.model.entity.ProjectServerAlertsEntity
;
import
com.example.operation_platform.model.vo.ProjectServerAlertsVO
;
import
com.example.operation_platform.model.vo.ProjectServerAlertsVO
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -16,4 +17,6 @@ import java.util.List;
...
@@ -16,4 +17,6 @@ import java.util.List;
public
interface
ProjectServerAlertsService
extends
IService
<
ProjectServerAlertsEntity
>
{
public
interface
ProjectServerAlertsService
extends
IService
<
ProjectServerAlertsEntity
>
{
List
<
ProjectServerAlertsVO
>
alertsList
(
ProjectServerAlertsDTO
projectServerAlertsDTO
);
List
<
ProjectServerAlertsVO
>
alertsList
(
ProjectServerAlertsDTO
projectServerAlertsDTO
);
List
<
ProjectServerAlertsVO
>
selectData
(
Date
time
);
}
}
src/main/java/com/example/operation_platform/service/impl/ProjectServerAlertsServiceImpl.java
View file @
181b02cc
...
@@ -9,6 +9,7 @@ import com.example.operation_platform.model.vo.ProjectServerAlertsVO;
...
@@ -9,6 +9,7 @@ import com.example.operation_platform.model.vo.ProjectServerAlertsVO;
import
com.example.operation_platform.service.ProjectServerAlertsService
;
import
com.example.operation_platform.service.ProjectServerAlertsService
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -23,4 +24,9 @@ public class ProjectServerAlertsServiceImpl extends ServiceImpl<ProjectServerAle
...
@@ -23,4 +24,9 @@ public class ProjectServerAlertsServiceImpl extends ServiceImpl<ProjectServerAle
public
List
<
ProjectServerAlertsVO
>
alertsList
(
ProjectServerAlertsDTO
projectServerAlertsDTO
)
{
public
List
<
ProjectServerAlertsVO
>
alertsList
(
ProjectServerAlertsDTO
projectServerAlertsDTO
)
{
return
baseMapper
.
alertsList
(
projectServerAlertsDTO
);
return
baseMapper
.
alertsList
(
projectServerAlertsDTO
);
}
}
@Override
public
List
<
ProjectServerAlertsVO
>
selectData
(
Date
time
)
{
return
baseMapper
.
selectData
(
time
);
}
}
}
src/main/java/com/example/operation_platform/task/ServerAlertTask.java
0 → 100644
View file @
181b02cc
package
com.example.operation_platform.task
;
import
com.example.operation_platform.model.dto.BsWorkDTO
;
import
com.example.operation_platform.model.entity.ScheduleEntity
;
import
com.example.operation_platform.model.entity.UserEntity
;
import
com.example.operation_platform.model.vo.ProjectServerAlertsVO
;
import
com.example.operation_platform.service.BsWorkService
;
import
com.example.operation_platform.service.ProjectServerAlertsService
;
import
com.example.operation_platform.service.ScheduleService
;
import
com.example.operation_platform.service.UserService
;
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
;
/**
* @author : wujipeng
* @date : 2026/3/20 10:22
* @Version: 1.0
* @Desc : 描述信息
*/
@Component
public
class
ServerAlertTask
{
@Resource
private
ProjectServerAlertsService
projectServerAlertsService
;
@Resource
private
BsWorkService
bsWorkService
;
@Resource
private
ScheduleService
scheduleService
;
@Resource
private
UserService
userService
;
@Scheduled
(
cron
=
"0 */1 * * * ?"
)
public
void
processRealTimeAlerts
()
{
//查询项目信息
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
new
Date
());
calendar
.
add
(
Calendar
.
MINUTE
,
-
1
);
//查询一分钟内的数据
List
<
ProjectServerAlertsVO
>
projectServerAlertsList
=
projectServerAlertsService
.
selectData
(
calendar
.
getTime
());
if
(!
projectServerAlertsList
.
isEmpty
())
{
ScheduleEntity
schedule
=
scheduleService
.
getUser
();
UserEntity
user
=
userService
.
getById
(
schedule
.
getUserId
());
for
(
ProjectServerAlertsVO
projectServerAlertsVO
:
projectServerAlertsList
)
{
BsWorkDTO
bsWorkDTO
=
new
BsWorkDTO
();
bsWorkDTO
.
setProjectId
(
projectServerAlertsVO
.
getProjectId
());
bsWorkDTO
.
setLevel
(
"P1"
);
bsWorkDTO
.
setType
(
"服务器异常"
);
bsWorkDTO
.
setDetail
(
projectServerAlertsVO
.
getDescription
());
bsWorkDTO
.
setLoginName
(
user
.
getName
());
bsWorkDTO
.
setHandleBy
(
schedule
.
getUserId
());
bsWorkService
.
addWork
(
bsWorkDTO
);
}
}
}
// @Scheduled(cron = "*/10 * * * * ?")
// public void processRealTimeAlertsTest() {
// ScheduleEntity schedule = scheduleService.getUser();
// UserEntity user = userService.getById(schedule.getUserId());
// BsWorkDTO bsWorkDTO = new BsWorkDTO();
// bsWorkDTO.setProjectId("2011321281488302081");
// bsWorkDTO.setLevel("P1");
// bsWorkDTO.setType("服务器异常");
// bsWorkDTO.setDetail("测试");
// bsWorkDTO.setLoginName(user.getName());
// bsWorkDTO.setHandleBy(schedule.getUserId());
// bsWorkService.addWork(bsWorkDTO);
// }
}
src/main/resources/mapper/ProjectServerAlertsMapper.xml
View file @
181b02cc
...
@@ -21,4 +21,19 @@
...
@@ -21,4 +21,19 @@
alert_time
alert_time
limit 10
limit 10
</select>
</select>
<select
id=
"selectData"
resultType=
"com.example.operation_platform.model.vo.ProjectServerAlertsVO"
>
select psa.id,
psa.alert_time,
psa.alert_type,
psa.metric_value,
psa.threshold,
psa.ip_address,
psa.description,
psa.resolved,
bp.id as projectId
from project_server_alerts psa
left join bs_project bp on bp.ips like concat('%',psa.ip_address,'%')
where psa.alert_time >= #{time}
and psa.resolved = false
</select>
</mapper>
</mapper>
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