Skip to content

Commit 1f73d16

Browse files
committed
Update.
1 parent 93de7ea commit 1f73d16

3 files changed

Lines changed: 6 additions & 8 deletions

File tree

model/rule.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ func (u *Rule) Snapshot(cycleTransferStats *CycleTransferStats, server *Server,
300300
// 使用用户配置的 Duration(秒)作为离线阈值,如果未设置则默认 60 秒
301301
offlineThreshold := float64(u.Duration)
302302
if offlineThreshold <= 0 {
303-
offlineThreshold = 60 // 默认 60 秒
303+
offlineThreshold = 10 // 默认 10 秒,加快离线告警响应
304304
}
305305
offlineSeconds := float64(time.Now().Unix()) - src
306306
if !server.LastActive.IsZero() && !server.IsOnline && offlineSeconds > offlineThreshold {

service/singleton/alertsentinel.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,9 @@ func AlertSentinelStart() {
190190
AlertsLock.RUnlock()
191191

192192
if alertCount == 0 {
193-
checkInterval = 30 * time.Second // 没有事件规则时30秒检查一次
194-
} else if alertCount < 10 {
195-
checkInterval = 10 * time.Second // 少量事件规则时10秒检查一次
193+
checkInterval = 15 * time.Second // 没有事件规则时15秒检查一次
196194
} else {
197-
checkInterval = 5 * time.Second // 大量事件规则时5秒检查一次
195+
checkInterval = 5 * time.Second // 有事件规则时5秒检查一次
198196
}
199197

200198
// 计算剩余时间并睡眠,避免忙等待

service/singleton/singleton.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,8 @@ func LoadSingleton() {
350350

351351
log.Println("正在添加定时任务...")
352352

353-
// 添加定时检查在线状态的任务,每分钟检查一次
354-
Cron.AddFunc("0 */1 * * * *", CheckServerOnlineStatus)
353+
// 添加定时检查在线状态的任务,每15秒检查一次(加快离线检测响应速度)
354+
Cron.AddFunc("*/15 * * * * *", CheckServerOnlineStatus)
355355

356356
// 添加定时验证流量数据一致性的任务,每5分钟检查一次
357357
Cron.AddFunc("0 */5 * * * *", VerifyTrafficDataConsistency)
@@ -955,7 +955,7 @@ func IPDesensitize(ip string) string {
955955
// CheckServerOnlineStatus 检查服务器在线状态,将超时未上报的服务器标记为离线
956956
func CheckServerOnlineStatus() {
957957
now := time.Now()
958-
offlineTimeout := time.Minute * 2 // 调整为2分钟无心跳视为离线,平衡稳定性和响应速度
958+
offlineTimeout := time.Second * 40 // 40秒无心跳视为离线,兼顾响应速度与短暂网络波动容忍
959959

960960
// 数据收集阶段(持锁)
961961
type serverUpdate struct {

0 commit comments

Comments
 (0)