@@ -24,16 +24,16 @@ type NotificationHistory struct {
2424 Until time.Time
2525}
2626
27- // 报警规则
27+ // 事件规则
2828var (
2929 AlertsLock sync.RWMutex
3030 Alerts []* model.AlertRule
31- alertsStore map [uint64 ]map [uint64 ][][]interface {} // [alert_id][server_id] -> 对应报警规则的检查结果
32- alertsPrevState map [uint64 ]map [uint64 ]uint // [alert_id][server_id] -> 对应报警规则的上一次报警状态
33- AlertsCycleTransferStatsStore map [uint64 ]* model.CycleTransferStats // [alert_id] -> 对应报警规则的周期流量统计
31+ alertsStore map [uint64 ]map [uint64 ][][]interface {} // [alert_id][server_id] -> 对应事件规则的检查结果
32+ alertsPrevState map [uint64 ]map [uint64 ]uint // [alert_id][server_id] -> 对应事件规则的上一次事件状态
33+ AlertsCycleTransferStatsStore map [uint64 ]* model.CycleTransferStats // [alert_id] -> 对应事件规则的周期流量统计
3434)
3535
36- // addCycleTransferStatsInfo 向AlertsCycleTransferStatsStore中添加周期流量报警统计信息
36+ // addCycleTransferStatsInfo 向AlertsCycleTransferStatsStore中添加周期流量事件统计信息
3737func addCycleTransferStatsInfo (alert * model.AlertRule ) {
3838 if ! alert .Enabled () {
3939 return
@@ -66,7 +66,7 @@ const (
6666 maxHistoryPerServer = 10 // 每个server最多存储10条历史记录
6767)
6868
69- // AlertSentinelStart 报警器启动
69+ // AlertSentinelStart 事件监控器启动
7070func AlertSentinelStart () {
7171 alertsStore = make (map [uint64 ]map [uint64 ][][]interface {})
7272 alertsPrevState = make (map [uint64 ]map [uint64 ]uint )
@@ -85,29 +85,29 @@ func AlertSentinelStart() {
8585
8686 // 根据数据库类型选择不同的加载方式
8787 if Conf .DatabaseType == "badger" {
88- // 使用BadgerDB加载报警规则
88+ // 使用BadgerDB加载事件规则
8989 if db .DB != nil {
9090 // BadgerDB模式,使用AlertRuleOps查询AlertRule
9191 alertOps := db .NewAlertRuleOps (db .DB )
9292 alerts , err := alertOps .GetAllAlertRules ()
9393 if err != nil {
94- log .Printf ("从BadgerDB加载报警规则失败 : %v" , err )
94+ log .Printf ("从BadgerDB加载事件规则失败 : %v" , err )
9595 AlertsLock .Unlock ()
9696 return
9797 }
9898 Alerts = alerts
9999 } else {
100- log .Println ("BadgerDB未初始化,跳过加载报警规则 " )
100+ log .Println ("BadgerDB未初始化,跳过加载事件规则 " )
101101 AlertsLock .Unlock ()
102102 return
103103 }
104104 } else {
105- // 使用SQLite加载报警规则
105+ // 使用SQLite加载事件规则
106106 err := executeWithRetry (func () error {
107107 return DB .Find (& Alerts ).Error
108108 })
109109 if err != nil {
110- log .Printf ("从SQLite加载报警规则失败 : %v" , err )
110+ log .Printf ("从SQLite加载事件规则失败 : %v" , err )
111111 AlertsLock .Unlock ()
112112 return // 不要panic,而是返回并稍后重试
113113 }
@@ -174,24 +174,24 @@ func AlertSentinelStart() {
174174
175175 if lastPrint .Before (startedAt .Add (- 1 * time .Hour )) {
176176 if Conf .Debug {
177- log .Println ("NG>> 报警规则检测每小时 " , checkCount , "次" , startedAt , time .Now ())
177+ log .Println ("NG>> 事件规则检测每小时 " , checkCount , "次" , startedAt , time .Now ())
178178 }
179179 checkCount = 0
180180 lastPrint = startedAt
181181 }
182182
183- // 优化检查间隔:根据报警规则数量动态调整
183+ // 优化检查间隔:根据事件规则数量动态调整
184184 var checkInterval time.Duration
185185 AlertsLock .RLock ()
186186 alertCount := len (Alerts ) // 使用Alerts而不是alertsStore,更准确
187187 AlertsLock .RUnlock ()
188188
189189 if alertCount == 0 {
190- checkInterval = 30 * time .Second // 没有报警规则时30秒检查一次
190+ checkInterval = 30 * time .Second // 没有事件规则时30秒检查一次
191191 } else if alertCount < 10 {
192- checkInterval = 10 * time .Second // 少量报警规则时10秒检查一次
192+ checkInterval = 10 * time .Second // 少量事件规则时10秒检查一次
193193 } else {
194- checkInterval = 5 * time .Second // 大量报警规则时5秒检查一次
194+ checkInterval = 5 * time .Second // 大量事件规则时5秒检查一次
195195 }
196196
197197 // 计算剩余时间并睡眠,避免忙等待
0 commit comments