Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add alarm rrd #883

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2022 Holoinsight Project Authors. Licensed under Apache-2.0.
*/
package io.holoinsight.server.common.dao.entity;

import lombok.Data;

/**
* 报警计数
*
* @author limengyang
* @version AlarmCountable.java, v 0.1 2024年09月19日 17:38 limengyang
*/
@Data
public class AlarmCountable {
public Long customPluginId;
public Long parentFolderId;
public Long historyId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public class Folder {
public String tenant;
public String workspace;
public Long parentFolderId;
public Boolean alarmed;
public Integer recentAlarm;
public Long alarmRrdTime;
public String recentAlarmHistoryId;
public String creator;
public String modifier;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2022 Holoinsight Project Authors. Licensed under Apache-2.0.
*/
package io.holoinsight.server.common.dao.entity;

import lombok.Data;

import java.io.Serializable;

/**
* @author limengyang
* @version FolderPath.java, v 0.1 2024年09月20日 11:14 limengyang
*/
@Data
public class FolderPath implements Serializable {
private static final long serialVersionUID = -783815229535552853L;
private Long id;
private String name;
private String type = FOLDER;

public static final String FILE = "file";
public static final String FOLDER = "folder";

public FolderPath(Long id, String name) {
super();
this.id = id;
this.name = name;
}

public FolderPath(Long id, String name, String type) {
super();
this.id = id;
this.name = name;
this.type = type;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2022 Holoinsight Project Authors. Licensed under Apache-2.0.
*/
package io.holoinsight.server.common.dao.entity;

import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
* 文件夹路径
*
* @author limengyang
* @version FolderPaths.java, v 0.1 2024年09月20日 10:09 limengyang
*/
@Data
public class FolderPaths implements Serializable {
private static final long serialVersionUID = 685496251839004159L;
public List<FolderPath> paths = new ArrayList<FolderPath>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.baomidou.mybatisplus.extension.service.IService;
import io.holoinsight.server.common.MonitorPageRequest;
import io.holoinsight.server.common.MonitorPageResult;
import io.holoinsight.server.common.dao.entity.AlarmHistory;
import io.holoinsight.server.common.dao.entity.AlarmHistoryDetail;
import io.holoinsight.server.common.dao.entity.dto.AlarmHistoryDetailDTO;

Expand All @@ -24,4 +25,6 @@ MonitorPageResult<AlarmHistoryDetailDTO> getListByPage(

List<Map<String, Object>> count(MonitorPageRequest<AlarmHistoryDetailDTO> pageRequest);

List<AlarmHistoryDetail> queryByTime(long from, long to);

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ MonitorPageResult<AlarmHistoryDTO> getListByPage(MonitorPageRequest<AlarmHistory

Boolean deleteById(Long id);

List<AlarmHistory> queryByTime(long from, long to);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.holoinsight.server.common.DateUtil;
import io.holoinsight.server.common.J;
import io.holoinsight.server.common.dao.converter.AlarmHistoryDetailConverter;
import io.holoinsight.server.common.dao.entity.AlarmHistory;
import io.holoinsight.server.common.dao.mapper.AlarmHistoryDetailMapper;
import io.holoinsight.server.common.dao.entity.AlarmHistoryDetail;
import io.holoinsight.server.common.dao.entity.dto.AlarmHistoryDetailDTO;
Expand Down Expand Up @@ -122,4 +123,13 @@ public List<Map<String, Object>> count(MonitorPageRequest<AlarmHistoryDetailDTO>

return list;
}

@Override
public List<AlarmHistoryDetail> queryByTime(long from, long to) {
QueryWrapper<AlarmHistoryDetail> wrapper = new QueryWrapper<>();
wrapper.le("alarm_time", new Date(to));
wrapper.ge("alarm_time", new Date(from));
List<AlarmHistoryDetail> alarmHistoryDetails = list(wrapper);
return alarmHistoryDetails;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.holoinsight.server.common.EventBusHolder;
import io.holoinsight.server.common.J;
import io.holoinsight.server.common.MonitorPageRequest;
import io.holoinsight.server.common.MonitorPageResult;
import io.holoinsight.server.common.dao.converter.AlarmHistoryConverter;
Expand All @@ -22,7 +23,10 @@

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@Service
public class AlarmHistoryServiceImpl extends ServiceImpl<AlarmHistoryMapper, AlarmHistory>
Expand Down Expand Up @@ -57,6 +61,16 @@ public Boolean deleteById(Long id) {
return this.removeById(id);
}

@Override
public List<AlarmHistory> queryByTime(long from, long to) {
QueryWrapper<AlarmHistory> wrapper = new QueryWrapper<>();
wrapper.le("alarm_time", to);
wrapper.ge("alarm_time", from);
wrapper.eq("deleted", false);
List<AlarmHistory> alarmHistories = list(wrapper);
return alarmHistories;
}

@Override
public MonitorPageResult<AlarmHistoryDTO> getListByPage(
MonitorPageRequest<AlarmHistoryDTO> pageRequest, List<String> uniqueIds) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ALTER TABLE `custom_plugin`
ADD COLUMN `alarmed` TINYINT(4) NULL COMMENT '(归档)是否报警';
ALTER TABLE `custom_plugin`
ADD COLUMN `recent_alarm_rule_unique_id` varchar(5000) DEFAULT NULL COMMENT '(归档)最近报警unique ID';
ALTER TABLE `custom_plugin`
ADD COLUMN `recent_alarm` int(11) NULL COMMENT '(归档)最近报警数量';
ALTER TABLE `custom_plugin`
ADD COLUMN `alarm_rrd_time` bigint(20) NULL COMMENT '归档时间';
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE `folder` ADD COLUMN `alarmed` tinyint(4) DEFAULT NULL COMMENT '(归档)是否报警';
ALTER TABLE `folder` ADD COLUMN `recent_alarm_rule_unique_id` varchar(5000) DEFAULT NULL COMMENT '(归档)最近报警unique ID';
ALTER TABLE `folder` ADD COLUMN `recent_alarm` int(11) DEFAULT NULL COMMENT '(归档)最近报警数量';
ALTER TABLE `folder` ADD COLUMN `alarm_rrd_time` bigint(20) DEFAULT NULL COMMENT '归档时间';
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE `folder` ADD COLUMN `recent_alarm_history_id` varchar(5000) DEFAULT NULL COMMENT '(归档)最近报警历史ID';
ALTER TABLE `custom_plugin` ADD COLUMN `recent_alarm_history_id` varchar(5000) DEFAULT NULL COMMENT '(归档)最近报警历史ID';
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public class WebhookInfo implements Cloneable {
*/
private String webhookMsg;

/**
* 回调类型
*/
private Byte type;

public WebhookInfo clone() {
try {
return (WebhookInfo) super.clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,23 @@ public void handle(List<AlertNotify> alertNotifies) {
break;
case "webhook":
if (!alertNotify.getIsRecover()) {
AlarmWebhook alertWebhook =
alarmWebhookDOMapper.selectById(alertSubscribe.getGroupId());
if (alertWebhook != null && alertWebhook.getStatus().equals((byte) 1)) {
webhookInfos.add(DoConvert.alertWebhookDoConverter(alertWebhook));
List<AlarmWebhook> alertWebhookList =
getAllAlertWebHook(alertSubscribe.getTenant());
List<Long> alertWebhookIdList = alertWebhookList.stream()
.map(AlarmWebhook::getId).collect(Collectors.toList());
if (!alertWebhookIdList.contains(alertSubscribe.getGroupId())) {
AlarmWebhook alertWebhook =
alarmWebhookDOMapper.selectById(alertSubscribe.getGroupId());
if (alertWebhook != null) {
alertWebhookList.add(alertWebhook);
}
}
if (!CollectionUtils.isEmpty(alertWebhookList)) {
for (AlarmWebhook webhook : alertWebhookList) {
if (webhook != null && webhook.getStatus().equals((byte) 1)) {
webhookInfos.add(DoConvert.alertWebhookDoConverter(webhook));
}
}
}
LOGGER.info("{} webhookInfos is {}.", alertNotify.getTraceId(),
J.toJson(webhookInfos));
Expand Down Expand Up @@ -230,6 +243,16 @@ public void handle(List<AlertNotify> alertNotifies) {
}
}

public List<AlarmWebhook> getAllAlertWebHook(String tenant) {
QueryWrapper<AlarmWebhook> wrapper = new QueryWrapper<>();
if (StringUtils.isNotBlank(tenant)) {
wrapper.eq("tenant", tenant);
}
wrapper.eq("type", 1);
List<AlarmWebhook> alarmWebhookList = alarmWebhookDOMapper.selectList(wrapper);
return alarmWebhookList;
}

private boolean keepSilence(boolean notifyRecover, AlertSilenceConfig alertSilenceConfig,
Long alarmTime) {
if (notifyRecover) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ public class CustomPlugin {

public String sampleLog;

public Boolean alarmed;

public Integer recentAlarm;

public Long alarmRrdTime;

public String recentAlarmHistoryId;

public String creator;

public String modifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ public class CustomPluginDTO {

public String sampleLog;

public Boolean alarmed;

public Integer recentAlarm;

public Long alarmRrdTime;

public String recentAlarmHistoryId;

public String creator;

public String modifier;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2022 Holoinsight Project Authors. Licensed under Apache-2.0.
*/
package io.holoinsight.server.home.task;

import io.holoinsight.server.common.model.CLUSTER_ROLE_CONST;
import io.holoinsight.server.common.service.AlarmHistoryDetailService;
import io.holoinsight.server.common.service.AlarmMetricService;
import io.holoinsight.server.common.service.FolderService;
import io.holoinsight.server.common.service.MetricInfoService;
import io.holoinsight.server.home.biz.service.CustomPluginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author limengyang
* @version MonitorAlarmRrdTask.java, v 0.1 2024年09月19日 15:41 limengyang
*/
@Service
@TaskHandler(code = "MONITOR_ALARM_RRD")
public class MonitorAlarmRrdTask extends AbstractMonitorTask {

public final static String TASK_ID = "MONITOR_ALARM_RRD";

public final static Long PERIOD = 5 * MINUTE;

@Autowired
private AlarmHistoryDetailService alarmHistoryDetailService;

@Autowired
private CustomPluginService customPluginService;

@Autowired
private FolderService folderService;

@Autowired
private MetricInfoService metricInfoService;

@Autowired
private AlarmMetricService alarmMetricService;


public MonitorAlarmRrdTask() {
super(1, 10, "MONITOR_ALARM_RRD");
}

@Override
public long getTaskPeriod() {
return PERIOD;
}

@Override
public boolean needRun() {
return true;
}

@Override
public List<MonitorTaskJob> buildJobs(long period) {
List<MonitorTaskJob> jobs = new ArrayList<>();
jobs.add(new MonitorAlarmRrdTaskJob(period, alarmHistoryDetailService, customPluginService,
metricInfoService, alarmMetricService, folderService));
return jobs;
}

public String getRole() {
// 代表执行本任务的具体Role
return CLUSTER_ROLE_CONST.META;
}

}
Loading
Loading