fix26.2: полная UI-полировка peer/dashboard и завершение i18n

This commit is contained in:
2026-05-09 01:38:57 +05:00
parent c13841b61a
commit db3c88c58a
42 changed files with 421 additions and 198 deletions
+36 -6
View File
@@ -9,6 +9,8 @@ import (
"time"
)
const hysteriaVersionCacheTTL = 15 * time.Minute
type metricsSnapshot struct {
CollectedAt int64
System vo.DashboardSystemVo
@@ -23,12 +25,41 @@ var metricsStore = struct {
sync.RWMutex
snapshot metricsSnapshot
lastSuccessAt int64
version string
versionAt time.Time
}{}
func getCachedHysteriaVersion(now time.Time) string {
metricsStore.RLock()
if metricsStore.version != "" && now.Sub(metricsStore.versionAt) < hysteriaVersionCacheTTL {
v := metricsStore.version
metricsStore.RUnlock()
return v
}
metricsStore.RUnlock()
content, err := util.Exec(util.GetHysteria2BinPath() + " version")
if err != nil {
metricsStore.RLock()
v := metricsStore.version
metricsStore.RUnlock()
if v != "" {
return v
}
return "-"
}
metricsStore.Lock()
metricsStore.version = content
metricsStore.versionAt = now
metricsStore.Unlock()
return content
}
func CollectMetricsSnapshot() {
nowMs := time.Now().UnixMilli()
s := metricsSnapshot{
CollectedAt: nowMs,
CollectedAt: nowMs,
CollectorState: vo.DataHealthVo{Status: "ok", LastSuccessAt: nowMs},
HysteriaState: vo.DataHealthVo{Status: "ok", LastSuccessAt: nowMs},
}
@@ -52,10 +83,7 @@ func CollectMetricsSnapshot() {
}
s.Hysteria.Running = Hysteria2IsRunning()
s.Hysteria.Version = "-"
if content, err := util.Exec(util.GetHysteria2BinPath() + " version"); err == nil {
s.Hysteria.Version = content
}
s.Hysteria.Version = getCachedHysteriaVersion(time.Now())
if onlineMap, err := Hysteria2Online(); err == nil {
s.Hysteria.ApiReachable = true
@@ -80,6 +108,9 @@ func CollectMetricsSnapshot() {
running = 1
}
diskPath := "/"
if configured := util.GetEnvDiskPath(); configured != "" {
diskPath = configured
}
metric := entity.MetricSample{
SampledAt: &nowMs,
CpuPercent: &s.System.CpuPercent,
@@ -108,4 +139,3 @@ func DashboardSnapshot() metricsSnapshot {
defer metricsStore.RUnlock()
return metricsStore.snapshot
}