Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
hertzbeat
Hertzbeat
提交
ddbd8aa7
Hertzbeat
项目概览
hertzbeat
/
Hertzbeat
9 个月 前同步成功
通知
1
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Hertzbeat
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
ddbd8aa7
编写于
7月 17, 2023
作者:
L
l646505418
提交者:
GitHub
7月 17, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
auto update alert status (#1104)
上级
823ab127
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
73 addition
and
9 deletion
+73
-9
alerter/src/main/java/org/dromara/hertzbeat/alert/calculate/CalculateAlarm.java
...org/dromara/hertzbeat/alert/calculate/CalculateAlarm.java
+57
-9
alerter/src/main/java/org/dromara/hertzbeat/alert/service/AlertService.java
...ava/org/dromara/hertzbeat/alert/service/AlertService.java
+10
-0
alerter/src/main/java/org/dromara/hertzbeat/alert/service/impl/AlertServiceImpl.java
...romara/hertzbeat/alert/service/impl/AlertServiceImpl.java
+6
-0
未找到文件。
alerter/src/main/java/org/dromara/hertzbeat/alert/calculate/CalculateAlarm.java
浏览文件 @
ddbd8aa7
...
...
@@ -23,7 +23,9 @@ import com.googlecode.aviator.exception.CompileExpressionErrorException;
import
com.googlecode.aviator.exception.ExpressionRuntimeException
;
import
com.googlecode.aviator.exception.ExpressionSyntaxErrorException
;
import
org.dromara.hertzbeat.alert.AlerterWorkerPool
;
import
org.dromara.hertzbeat.alert.dao.AlertDao
;
import
org.dromara.hertzbeat.alert.reduce.AlarmCommonReduce
;
import
org.dromara.hertzbeat.alert.service.AlertService
;
import
org.dromara.hertzbeat.common.queue.CommonDataQueue
;
import
org.dromara.hertzbeat.alert.dao.AlertMonitorDao
;
import
org.dromara.hertzbeat.common.entity.alerter.Alert
;
...
...
@@ -37,16 +39,21 @@ import org.dromara.hertzbeat.common.util.CommonUtil;
import
org.dromara.hertzbeat.common.util.ResourceBundleUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.jpa.domain.Specification
;
import
javax.persistence.criteria.Predicate
;
import
java.util.*
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.stream.Collectors
;
import
static
org
.
dromara
.
hertzbeat
.
common
.
constants
.
CommonConstants
.
ALERT_STATUS_CODE_PENDING
;
import
static
org
.
dromara
.
hertzbeat
.
common
.
constants
.
CommonConstants
.
ALERT_STATUS_CODE_SOLVED
;
/**
* Calculate alarms based on the alarm definition rules and collected data
* 根据告警定义规则和采集数据匹配计算告警
* @author tom
*
* @author tom
*/
@Configuration
@Slf4j
...
...
@@ -65,14 +72,16 @@ public class CalculateAlarm {
private
final
AlertDefineService
alertDefineService
;
private
final
AlarmCommonReduce
alarmCommonReduce
;
private
final
ResourceBundle
bundle
;
private
final
AlertService
alertService
;
public
CalculateAlarm
(
AlerterWorkerPool
workerPool
,
CommonDataQueue
dataQueue
,
AlertDefineService
alertDefineService
,
AlertMonitorDao
monitorDao
,
AlarmCommonReduce
alarmCommonRedu
ce
)
{
public
CalculateAlarm
(
AlerterWorkerPool
workerPool
,
CommonDataQueue
dataQueue
,
AlertDefineService
alertDefineService
,
AlertMonitorDao
monitorDao
,
AlarmCommonReduce
alarmCommonReduce
,
AlertService
alertServi
ce
)
{
this
.
workerPool
=
workerPool
;
this
.
dataQueue
=
dataQueue
;
this
.
alarmCommonReduce
=
alarmCommonReduce
;
this
.
alertDefineService
=
alertDefineService
;
this
.
alertService
=
alertService
;
this
.
bundle
=
ResourceBundleUtil
.
getBundle
(
"alerter"
);
this
.
triggeredAlertMap
=
new
ConcurrentHashMap
<>(
128
);
this
.
unAvailableMonitors
=
Collections
.
synchronizedSet
(
new
HashSet
<>(
16
));
...
...
@@ -154,7 +163,8 @@ public class CalculateAlarm {
try
{
Expression
expression
=
AviatorEvaluator
.
compile
(
expr
,
true
);
match
=
(
Boolean
)
expression
.
execute
(
fieldValueMap
);
}
catch
(
CompileExpressionErrorException
|
ExpressionSyntaxErrorException
compileException
)
{
}
catch
(
CompileExpressionErrorException
|
ExpressionSyntaxErrorException
compileException
)
{
log
.
error
(
"Alert Define Rule: {} Compile Error: {}."
,
expr
,
compileException
.
getMessage
());
}
catch
(
ExpressionRuntimeException
expressionRuntimeException
)
{
log
.
error
(
"Alert Define Rule: {} Run Error: {}."
,
expr
,
expressionRuntimeException
.
getMessage
());
...
...
@@ -188,7 +198,7 @@ public class CalculateAlarm {
.
tags
(
tags
)
.
alertDefineId
(
define
.
getId
())
.
priority
(
define
.
getPriority
())
.
status
(
CommonConstants
.
ALERT_STATUS_CODE_PENDING
)
.
status
(
ALERT_STATUS_CODE_PENDING
)
.
target
(
app
+
"."
+
metrics
+
"."
+
define
.
getField
())
.
triggerTimes
(
1
)
.
firstAlarmTime
(
currentTimeMilli
)
...
...
@@ -263,6 +273,10 @@ public class CalculateAlarm {
.
triggerTimes
(
1
)
.
build
();
alarmCommonReduce
.
reduceAndSendAlarm
(
resumeAlert
);
Runnable
updateStatusJob
=
()
->
{
updateAvailabilityAlertStatus
(
monitorId
,
resumeAlert
);
};
workerPool
.
executeJob
(
updateStatusJob
);
}
}
}
...
...
@@ -285,7 +299,7 @@ public class CalculateAlarm {
Alert
.
AlertBuilder
alertBuilder
=
Alert
.
builder
()
.
tags
(
tags
)
.
priority
(
CommonConstants
.
ALERT_PRIORITY_CODE_EMERGENCY
)
.
status
(
CommonConstants
.
ALERT_STATUS_CODE_PENDING
)
.
status
(
ALERT_STATUS_CODE_PENDING
)
.
target
(
CommonConstants
.
AVAILABILITY
)
.
content
(
AlertTemplateUtil
.
render
(
avaAlertDefine
.
getTemplate
(),
valueMap
))
.
firstAlarmTime
(
currentTimeMill
)
...
...
@@ -300,7 +314,7 @@ public class CalculateAlarm {
triggeredAlertMap
.
put
(
String
.
valueOf
(
monitorId
),
alertBuilder
.
build
());
}
else
{
int
times
=
preAlert
.
getTriggerTimes
()
+
1
;
if
(
preAlert
.
getStatus
()
==
CommonConstants
.
ALERT_STATUS_CODE_PENDING
)
{
if
(
preAlert
.
getStatus
()
==
ALERT_STATUS_CODE_PENDING
)
{
times
=
1
;
preAlert
.
setContent
(
AlertTemplateUtil
.
render
(
avaAlertDefine
.
getTemplate
(),
valueMap
));
preAlert
.
setTags
(
tags
);
...
...
@@ -310,7 +324,7 @@ public class CalculateAlarm {
preAlert
.
setLastAlarmTime
(
currentTimeMill
);
int
defineTimes
=
avaAlertDefine
.
getTimes
()
==
null
?
1
:
avaAlertDefine
.
getTimes
();
if
(
times
>=
defineTimes
)
{
preAlert
.
setStatus
(
CommonConstants
.
ALERT_STATUS_CODE_PENDING
);
preAlert
.
setStatus
(
ALERT_STATUS_CODE_PENDING
);
alarmCommonReduce
.
reduceAndSendAlarm
(
preAlert
.
clone
());
unAvailableMonitors
.
add
(
monitorId
);
}
else
{
...
...
@@ -318,4 +332,38 @@ public class CalculateAlarm {
}
}
}
private
void
updateAvailabilityAlertStatus
(
long
monitorId
,
Alert
restoreAlert
)
{
List
<
Alert
>
availabilityAlerts
=
queryAvailabilityAlerts
(
monitorId
,
restoreAlert
);
availabilityAlerts
.
stream
().
parallel
().
forEach
(
alert
->
{
log
.
info
(
"updating alert id:{}"
,
alert
.
getId
());
alertService
.
editAlertStatus
(
ALERT_STATUS_CODE_SOLVED
,
List
.
of
(
alert
.
getId
()));
});
}
private
List
<
Alert
>
queryAvailabilityAlerts
(
long
monitorId
,
Alert
restoreAlert
)
{
//create query condition
Specification
<
Alert
>
specification
=
(
root
,
query
,
criteriaBuilder
)
->
{
List
<
Predicate
>
andList
=
new
ArrayList
<>();
Predicate
predicateTags
=
criteriaBuilder
.
like
(
root
.
get
(
"tags"
).
as
(
String
.
class
),
"%"
+
monitorId
+
"%"
);
andList
.
add
(
predicateTags
);
Predicate
predicatePriority
=
criteriaBuilder
.
equal
(
root
.
get
(
"priority"
),
CommonConstants
.
ALERT_PRIORITY_CODE_EMERGENCY
);
andList
.
add
(
predicatePriority
);
Predicate
predicateStatus
=
criteriaBuilder
.
equal
(
root
.
get
(
"status"
),
ALERT_STATUS_CODE_PENDING
);
andList
.
add
(
predicateStatus
);
Predicate
predicateAlertTime
=
criteriaBuilder
.
lessThanOrEqualTo
(
root
.
get
(
"lastAlarmTime"
),
restoreAlert
.
getLastAlarmTime
());
andList
.
add
(
predicateAlertTime
);
Predicate
[]
predicates
=
new
Predicate
[
andList
.
size
()];
return
criteriaBuilder
.
and
(
andList
.
toArray
(
predicates
));
};
//query results
return
alertService
.
getAlerts
(
specification
);
}
}
alerter/src/main/java/org/dromara/hertzbeat/alert/service/AlertService.java
浏览文件 @
ddbd8aa7
...
...
@@ -91,4 +91,14 @@ public interface AlertService {
*/
void
addNewAlertReport
(
AlertReport
alertReport
);
/**
* Dynamic conditional query
* 动态条件查询
*
* @param specification Query conditions 查询条件
* @return search result 查询结果
*/
List
<
Alert
>
getAlerts
(
Specification
<
Alert
>
specification
);
}
alerter/src/main/java/org/dromara/hertzbeat/alert/service/impl/AlertServiceImpl.java
浏览文件 @
ddbd8aa7
...
...
@@ -133,6 +133,12 @@ public class AlertServiceImpl implements AlertService {
alarmCommonReduce
.
reduceAndSendAlarm
(
buildAlertData
(
alertReport
));
}
@Override
public
List
<
Alert
>
getAlerts
(
Specification
<
Alert
>
specification
)
{
return
alertDao
.
findAll
(
specification
);
}
/**
* The external alarm information is converted to Alert 对外告警信息 转换为Alert
* @param alertReport 对外告警信息
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录