feat: Implement a new monitoring system with auto-add capabilities and a dedicated management UI.
This commit is contained in:
@@ -14,6 +14,7 @@ type MonitorSettings struct {
|
||||
Target int `json:"target"`
|
||||
AutoAdd bool `json:"auto_add"`
|
||||
MinInterval int `json:"min_interval"`
|
||||
CheckInterval int `json:"check_interval"` // 自动补号检查间隔(秒)
|
||||
PollingEnabled bool `json:"polling_enabled"`
|
||||
PollingInterval int `json:"polling_interval"`
|
||||
}
|
||||
@@ -34,6 +35,7 @@ func HandleGetMonitorSettings(w http.ResponseWriter, r *http.Request) {
|
||||
Target: 50,
|
||||
AutoAdd: false,
|
||||
MinInterval: 300,
|
||||
CheckInterval: 60,
|
||||
PollingEnabled: false,
|
||||
PollingInterval: 60,
|
||||
}
|
||||
@@ -51,6 +53,11 @@ func HandleGetMonitorSettings(w http.ResponseWriter, r *http.Request) {
|
||||
settings.MinInterval = v
|
||||
}
|
||||
}
|
||||
if val, _ := database.Instance.GetConfig("monitor_check_interval"); val != "" {
|
||||
if v, err := strconv.Atoi(val); err == nil {
|
||||
settings.CheckInterval = v
|
||||
}
|
||||
}
|
||||
if val, _ := database.Instance.GetConfig("monitor_polling_enabled"); val == "true" {
|
||||
settings.PollingEnabled = true
|
||||
}
|
||||
@@ -85,6 +92,7 @@ func HandleSaveMonitorSettings(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
logger.Info("收到保存监控设置请求: target="+strconv.Itoa(settings.Target)+
|
||||
", auto_add="+strconv.FormatBool(settings.AutoAdd)+
|
||||
", check_interval="+strconv.Itoa(settings.CheckInterval)+
|
||||
", polling="+strconv.FormatBool(settings.PollingEnabled), "", "monitor")
|
||||
|
||||
// 保存到数据库
|
||||
@@ -98,6 +106,14 @@ func HandleSaveMonitorSettings(w http.ResponseWriter, r *http.Request) {
|
||||
if err := database.Instance.SetConfig("monitor_min_interval", strconv.Itoa(settings.MinInterval)); err != nil {
|
||||
saveErrors = append(saveErrors, "min_interval: "+err.Error())
|
||||
}
|
||||
// 检查间隔最小10秒
|
||||
checkInterval := settings.CheckInterval
|
||||
if checkInterval < 10 {
|
||||
checkInterval = 10
|
||||
}
|
||||
if err := database.Instance.SetConfig("monitor_check_interval", strconv.Itoa(checkInterval)); err != nil {
|
||||
saveErrors = append(saveErrors, "check_interval: "+err.Error())
|
||||
}
|
||||
if err := database.Instance.SetConfig("monitor_polling_enabled", strconv.FormatBool(settings.PollingEnabled)); err != nil {
|
||||
saveErrors = append(saveErrors, "polling_enabled: "+err.Error())
|
||||
}
|
||||
@@ -115,8 +131,9 @@ func HandleSaveMonitorSettings(w http.ResponseWriter, r *http.Request) {
|
||||
// 输出日志
|
||||
logger.Success("监控设置已保存: target="+strconv.Itoa(settings.Target)+
|
||||
", auto_add="+strconv.FormatBool(settings.AutoAdd)+
|
||||
", check_interval="+strconv.Itoa(checkInterval)+"s"+
|
||||
", polling="+strconv.FormatBool(settings.PollingEnabled)+
|
||||
", interval="+strconv.Itoa(settings.PollingInterval)+"s", "", "monitor")
|
||||
", polling_interval="+strconv.Itoa(settings.PollingInterval)+"s", "", "monitor")
|
||||
|
||||
Success(w, map[string]interface{}{
|
||||
"message": "设置已保存",
|
||||
|
||||
Reference in New Issue
Block a user