🐛 Fix Bug

This commit is contained in:
刘嘉伟 committed 2026-03-03 11:34:52 +08:00
1 parent 99032f219b
commit 9df17fa2a8
2 files changed
+47 -6

No files matched your search

+44
View File
@@ -113,6 +113,50 @@ func (s *Service) UpdateSettings(req *UpdateSettingsRequest) error {
return nil
}
// GetMonitoringIntervals reads latencyCheckInterval and locationCheckInterval
// from settings general JSON. Falls back to defaults if not set or on error.
func (s *Service) GetMonitoringIntervals() (latencyInterval, geoInterval time.Duration) {
const defaultLatency = 5 * time.Second
const defaultGeo = 24 * time.Hour
settings, err := s.GetSettings()
if err != nil {
s.app.Logger().Warn("Failed to load settings for monitoring intervals, using defaults", "error", err)
return defaultLatency, defaultGeo
}
latencyInterval = defaultLatency
if v, ok := settings.General["latencyCheckInterval"]; ok {
if secs, ok := toFloat64(v); ok && secs > 0 {
latencyInterval = time.Duration(secs) * time.Second
}
}
geoInterval = defaultGeo
if v, ok := settings.General["locationCheckInterval"]; ok {
if secs, ok := toFloat64(v); ok && secs > 0 {
geoInterval = time.Duration(secs) * time.Second
}
}
return latencyInterval, geoInterval
}
func toFloat64(v interface{}) (float64, bool) {
switch n := v.(type) {
case float64:
return n, true
case int:
return float64(n), true
case int64:
return float64(n), true
case json.Number:
f, err := n.Float64()
return f, err == nil
}
return 0, false
}
// GetAppVersion returns the application version.
func (s *Service) GetAppVersion() string {
return buildinfo.AppVersion
+3 -6
View File
@@ -4,8 +4,6 @@ import (
"embed"
"io/fs"
"log"
"time"
"github.com/spf13/cobra"
"frpc-hub/internal/application/dashboard"
@@ -86,10 +84,9 @@ func main() {
// Auto-start servers with autoConnection enabled (non-blocking)
go frpcService.AutoStartServers()
// Start network monitoring service
// Latency check: every 30 seconds (frequent for real-time monitoring)
// Geolocation check: every 24 hours (only for servers without geo data)
networkMonitorService.Start(5*time.Second, 24*time.Hour)
// Start network monitoring service using intervals from settings
latencyInterval, geoInterval := settingsService.GetMonitoringIntervals()
networkMonitorService.Start(latencyInterval, geoInterval)
// Register routes for each module
//githubHandler.RegisterHandlers(e)