Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DiDi
nightingale
提交
eaacf04c
N
nightingale
项目概览
DiDi
/
nightingale
9 个月 前同步成功
通知
45
Star
7053
Fork
1161
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
nightingale
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
eaacf04c
编写于
9月 04, 2021
作者:
U
UlricQin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feature: load alert_events to memory when start
上级
ee859df0
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
57 addition
and
7 deletion
+57
-7
alert/alert.go
alert/alert.go
+3
-1
judge/judge.go
judge/judge.go
+3
-0
judge/last_event.go
judge/last_event.go
+33
-2
models/alert_event.go
models/alert_event.go
+18
-4
未找到文件。
alert/alert.go
浏览文件 @
eaacf04c
package
alert
import
"context"
import
(
"context"
)
func
Start
(
ctx
context
.
Context
)
{
go
popEvent
()
...
...
judge/judge.go
浏览文件 @
eaacf04c
...
...
@@ -28,6 +28,9 @@ func Start(ctx context.Context) {
// PUSH型的告警引擎,依赖内存里缓存的数据来做告警判断,两层map减小锁粒度
initPointCaches
()
// 把数据库中的未恢复告警同步一份到内存中,便于后续判断告警是否应该发送
LastEvents
.
Init
()
// 默认初始化的大小是1000万,相当于内存里有1000万事件,应该够用了
EventQueue
=
list
.
NewSafeListLimited
(
10000000
)
...
...
judge/last_event.go
浏览文件 @
eaacf04c
package
judge
import
(
"fmt"
"os"
"sync"
"time"
...
...
@@ -35,9 +37,9 @@ func (s *SafeEventMap) Set(event *models.AlertEvent) {
s
.
Lock
()
defer
s
.
Unlock
()
m
,
has
:=
s
.
M
[
event
.
RuleId
]
_
,
has
:=
s
.
M
[
event
.
RuleId
]
if
!
has
{
m
=
make
(
map
[
string
]
*
models
.
AlertEvent
)
m
:
=
make
(
map
[
string
]
*
models
.
AlertEvent
)
m
[
event
.
HashId
]
=
event
s
.
M
[
event
.
RuleId
]
=
m
}
else
{
...
...
@@ -45,6 +47,35 @@ func (s *SafeEventMap) Set(event *models.AlertEvent) {
}
}
func
(
s
*
SafeEventMap
)
Init
()
{
aes
,
err
:=
models
.
AlertEventGetAll
()
if
err
!=
nil
{
fmt
.
Println
(
"load all alert_event fail:"
,
err
)
os
.
Exit
(
1
)
}
if
len
(
aes
)
==
0
{
return
}
data
:=
make
(
map
[
int64
]
map
[
string
]
*
models
.
AlertEvent
)
for
i
:=
0
;
i
<
len
(
aes
);
i
++
{
event
:=
aes
[
i
]
_
,
has
:=
data
[
event
.
RuleId
]
if
!
has
{
m
:=
make
(
map
[
string
]
*
models
.
AlertEvent
)
m
[
event
.
HashId
]
=
event
data
[
event
.
RuleId
]
=
m
}
else
{
data
[
event
.
RuleId
][
event
.
HashId
]
=
event
}
}
s
.
Lock
()
s
.
M
=
data
s
.
Unlock
()
}
func
(
s
*
SafeEventMap
)
Del
(
ruleId
int64
,
hashId
string
)
{
s
.
Lock
()
defer
s
.
Unlock
()
...
...
models/alert_event.go
浏览文件 @
eaacf04c
...
...
@@ -13,10 +13,10 @@ import (
)
type
AlertEvent
struct
{
Id
int64
`json:"id"`
RuleId
int64
`json:"rule_id"`
RuleName
string
`json:"rule_name"`
RuleNote
string
`json:"rule_note"`
Id
int64
`json:"id"`
RuleId
int64
`json:"rule_id"`
RuleName
string
`json:"rule_name"`
RuleNote
string
`json:"rule_note"`
// ProcessorUid int64 `json:"processor_uid"`
// ProcessorObj User `json:"processor_user_obj" xorm:"-"`
// EventNote string `json:"event_note"`
...
...
@@ -269,6 +269,20 @@ func AlertEventGet(where string, args ...interface{}) (*AlertEvent, error) {
return
&
obj
,
nil
}
func
AlertEventGetAll
()
([]
*
AlertEvent
,
error
)
{
var
objs
[]
*
AlertEvent
err
:=
DB
.
Find
(
&
objs
)
if
err
!=
nil
{
return
objs
,
err
}
if
len
(
objs
)
==
0
{
return
[]
*
AlertEvent
{},
nil
}
return
objs
,
nil
}
// func AlertEventUpdateEventNote(id int64, hashId string, note string, uid int64) error {
// session := DB.NewSession()
// defer session.Close()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录