🐛 fix: 旧采样点清理及报警策略优化
This commit is contained in:
		
							parent
							
								
									4e85e40550
								
							
						
					
					
						commit
						35766e590d
					
				@ -54,12 +54,15 @@ func (u *Rule) Snapshot(server *Server) interface{} {
 | 
				
			|||||||
	case "transfer_all":
 | 
						case "transfer_all":
 | 
				
			||||||
		src = server.State.NetOutTransfer + server.State.NetInTransfer
 | 
							src = server.State.NetOutTransfer + server.State.NetInTransfer
 | 
				
			||||||
	case "offline":
 | 
						case "offline":
 | 
				
			||||||
		src = uint64(server.LastActive.Unix())
 | 
							if server.LastActive.IsZero() {
 | 
				
			||||||
	}
 | 
								src = 0
 | 
				
			||||||
	if u.Type == "offline" {
 | 
							} else {
 | 
				
			||||||
		if uint64(time.Now().Unix())-src > 6 {
 | 
								src = uint64(server.LastActive.Unix())
 | 
				
			||||||
			return struct{}{}
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if u.Type == "offline" && uint64(time.Now().Unix())-src > 6 {
 | 
				
			||||||
 | 
							return struct{}{}
 | 
				
			||||||
	} else if (u.Max > 0 && src > u.Max) || (u.Min > 0 && src < u.Min) {
 | 
						} else if (u.Max > 0 && src > u.Max) || (u.Min > 0 && src < u.Min) {
 | 
				
			||||||
		return struct{}{}
 | 
							return struct{}{}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -109,7 +112,7 @@ func (r *AlertRule) Check(points [][]interface{}) (int, string) {
 | 
				
			|||||||
		if len(points) < num {
 | 
							if len(points) < num {
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		for j := len(points) - 1; j >= 0; j-- {
 | 
							for j := len(points) - 1; j >= 0 && len(points)-num <= j; j-- {
 | 
				
			||||||
			total++
 | 
								total++
 | 
				
			||||||
			if points[j][i] != nil {
 | 
								if points[j][i] != nil {
 | 
				
			||||||
				fail++
 | 
									fail++
 | 
				
			||||||
 | 
				
			|||||||
@ -84,6 +84,7 @@ func OnDeleteAlert(id uint64) {
 | 
				
			|||||||
	for i := 0; i < len(alerts); i++ {
 | 
						for i := 0; i < len(alerts); i++ {
 | 
				
			||||||
		if alerts[i].ID == id {
 | 
							if alerts[i].ID == id {
 | 
				
			||||||
			alerts = append(alerts[:i], alerts[i+1:]...)
 | 
								alerts = append(alerts[:i], alerts[i+1:]...)
 | 
				
			||||||
 | 
								i--
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -109,6 +110,7 @@ func OnDeleteNotification(id uint64) {
 | 
				
			|||||||
	for i := 0; i < len(notifications); i++ {
 | 
						for i := 0; i < len(notifications); i++ {
 | 
				
			||||||
		if notifications[i].ID == id {
 | 
							if notifications[i].ID == id {
 | 
				
			||||||
			notifications = append(notifications[:i], notifications[i+1:]...)
 | 
								notifications = append(notifications[:i], notifications[i+1:]...)
 | 
				
			||||||
 | 
								i--
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -155,17 +157,13 @@ func checkStatus() {
 | 
				
			|||||||
					}, firstNotificationDelay+time.Minute*10)
 | 
										}, firstNotificationDelay+time.Minute*10)
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				if flag {
 | 
									if flag {
 | 
				
			||||||
					message := fmt.Sprintf("逮到咯,快去看看!服务器:%s(%s),报警规则:%s,%s", server.Name, server.Host.IP, alert.Name, desc)
 | 
										message := fmt.Sprintf("报警规则:%s,服务器:%s(%s),%s,逮到咯,快去看看!", alert.Name, server.Name, server.Host.IP, desc)
 | 
				
			||||||
					go sendNotification(message)
 | 
										go sendNotification(message)
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			// 清理旧数据
 | 
								// 清理旧数据
 | 
				
			||||||
			if max > 0 {
 | 
								if max > 0 && max < len(alertsStore[alert.ID][server.ID]) {
 | 
				
			||||||
				for k := 0; k < len(alertsStore[alert.ID][server.ID]); k++ {
 | 
									alertsStore[alert.ID][server.ID] = alertsStore[alert.ID][server.ID][len(alertsStore[alert.ID][server.ID])-max:]
 | 
				
			||||||
					if max < len(alertsStore[alert.ID][server.ID][k]) {
 | 
					 | 
				
			||||||
						alertsStore[alert.ID][server.ID][k] = alertsStore[alert.ID][server.ID][k][len(alertsStore[alert.ID][server.ID][k])-max:]
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user