Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
Nightingale
提交
98fe1e01
N
Nightingale
项目概览
jobily
/
Nightingale
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
Nightingale
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
98fe1e01
编写于
8月 22, 2021
作者:
U
Ulric Qin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: add timer: CleanStalePoints
上级
de99077b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
29 addition
and
7 deletion
+29
-7
judge/handler.go
judge/handler.go
+1
-4
judge/history.go
judge/history.go
+17
-3
judge/judge.go
judge/judge.go
+11
-0
未找到文件。
judge/handler.go
浏览文件 @
98fe1e01
...
...
@@ -49,6 +49,7 @@ func Send(points []*vos.MetricPoint) {
// 这个监控数据没有关联任何告警策略,省事了不用处理
continue
}
logger
.
Debugf
(
"[point_match_alertRules][point:%+v][alertRuleNum:%+v]"
,
points
[
i
],
rulesCount
)
// 不同的告警规则,alert_duration字段大小不同,找到最大的,按照最大的值来缓存历史数据
var
maxAliveDuration
=
0
...
...
@@ -57,10 +58,6 @@ func Send(points []*vos.MetricPoint) {
maxAliveDuration
=
alertRules
[
j
]
.
AlertDuration
}
}
if
len
(
points
[
i
]
.
PK
)
<
2
{
logger
.
Debugf
(
"[point:%+v] len(pk)<2"
,
points
[
i
])
continue
}
ll
:=
PointCaches
[
points
[
i
]
.
PK
[
0
:
2
]]
.
PutPoint
(
points
[
i
],
int64
(
maxAliveDuration
))
...
...
judge/history.go
浏览文件 @
98fe1e01
...
...
@@ -17,6 +17,7 @@ package judge
import
(
"container/list"
"sync"
"time"
"github.com/didi/nightingale/v5/vos"
)
...
...
@@ -50,7 +51,7 @@ func (pc *PointCache) Len() int {
}
func
(
pc
*
PointCache
)
CleanStale
(
before
int64
)
{
keys
:=
[]
string
{}
var
keys
[]
string
pc
.
RLock
()
for
key
,
L
:=
range
pc
.
M
{
...
...
@@ -97,12 +98,25 @@ func (pc *PointCache) PutPoint(p *vos.MetricPoint, maxAliveDuration int64) *Safe
// 这是个线程不安全的大Map,需要提前初始化好
var
PointCaches
=
make
(
map
[
string
]
*
PointCache
)
var
pointChars
=
[]
string
{
"0"
,
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"a"
,
"b"
,
"c"
,
"d"
,
"e"
,
"f"
}
var
pointHeadKeys
=
make
([]
string
,
0
,
256
)
func
initPointCaches
()
{
arr
:=
[]
string
{
"0"
,
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"a"
,
"b"
,
"c"
,
"d"
,
"e"
,
"f"
}
for
i
:=
0
;
i
<
16
;
i
++
{
for
j
:=
0
;
j
<
16
;
j
++
{
PointCaches
[
arr
[
i
]
+
arr
[
j
]]
=
NewPointCache
(
)
pointHeadKeys
=
append
(
pointHeadKeys
,
pointChars
[
i
]
+
pointChars
[
j
]
)
}
}
for
i
:=
0
;
i
<
256
;
i
++
{
PointCaches
[
pointHeadKeys
[
i
]]
=
NewPointCache
()
}
}
func
CleanStalePoints
()
{
// 监控数据2天都没关联到任何告警策略,说明对应的告警策略已经删除了
before
:=
time
.
Now
()
.
Unix
()
-
3600
*
24
*
2
for
i
:=
0
;
i
<
256
;
i
++
{
PointCaches
[
pointHeadKeys
[
i
]]
.
CleanStale
(
before
)
}
}
judge/judge.go
浏览文件 @
98fe1e01
...
...
@@ -38,10 +38,14 @@ func Start(ctx context.Context) {
os
.
Exit
(
1
)
}
// 启动心跳goroutinue,如果挂了,trans可以及时感知
go
loopHeartbeat
()
// PULL型的策略不着急,等一段时间(等哈希环是稳态的)再开始周期性干活
go
syncPullRules
(
ctx
)
// 告警策略删除之后,针对这些告警策略缓存的监控数据要被清理
go
loopCleanStalePoints
()
}
func
syncPullRules
(
ctx
context
.
Context
)
{
...
...
@@ -102,3 +106,10 @@ func heartbeat(endpoint string) error {
}
return
nil
}
func
loopCleanStalePoints
()
{
for
{
time
.
Sleep
(
time
.
Hour
)
CleanStalePoints
()
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录