fix: полный продакшен-фикс dashboard/peer/hysteria по fix35
This commit is contained in:
@@ -44,19 +44,33 @@ func DashboardSummary() (vo.DashboardSummaryVo, error) {
|
||||
func DashboardTimeseries(rangeKey string) (vo.DashboardTimeseriesVo, error) {
|
||||
nowMs := time.Now().UnixMilli()
|
||||
fromMs := nowMs - int64(24*time.Hour/time.Millisecond)
|
||||
bucketMs := int64(5 * time.Minute / time.Millisecond)
|
||||
source := "sample"
|
||||
r := strings.TrimSpace(rangeKey)
|
||||
if r == "1h" {
|
||||
fromMs = nowMs - int64(time.Hour/time.Millisecond)
|
||||
bucketMs = int64(time.Minute / time.Millisecond)
|
||||
source = "sample"
|
||||
} else if r == "7d" {
|
||||
fromMs = nowMs - int64(7*24*time.Hour/time.Millisecond)
|
||||
bucketMs = int64(time.Hour / time.Millisecond)
|
||||
source = "hourly"
|
||||
} else if r == "30d" {
|
||||
fromMs = nowMs - int64(30*24*time.Hour/time.Millisecond)
|
||||
bucketMs = int64(24 * time.Hour / time.Millisecond)
|
||||
source = "daily"
|
||||
r = "30d"
|
||||
} else if r == "" {
|
||||
r = "24h"
|
||||
bucketMs = int64(5 * time.Minute / time.Millisecond)
|
||||
source = "sample"
|
||||
} else {
|
||||
r = "24h"
|
||||
bucketMs = int64(5 * time.Minute / time.Millisecond)
|
||||
source = "sample"
|
||||
}
|
||||
|
||||
traffic, err := dao.DashboardTrafficTimeseries(fromMs, nowMs)
|
||||
traffic, err := dao.DashboardTrafficTimeseries(fromMs, nowMs, bucketMs, source)
|
||||
if err != nil {
|
||||
return vo.DashboardTimeseriesVo{}, err
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"hy2xs-admin/dao"
|
||||
"hy2xs-admin/model/entity"
|
||||
"hy2xs-admin/model/vo"
|
||||
@@ -11,6 +15,19 @@ import (
|
||||
|
||||
const hysteriaVersionCacheTTL = 15 * time.Minute
|
||||
|
||||
var ansiRe = regexp.MustCompile(`\x1b\[[0-9;]*[A-Za-z]`)
|
||||
var hysteriaVersionRe = regexp.MustCompile(`(?i)v?\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?`)
|
||||
|
||||
func normalizeHysteriaVersion(raw string) string {
|
||||
cleaned := strings.TrimSpace(raw)
|
||||
cleaned = ansiRe.ReplaceAllString(cleaned, "")
|
||||
match := hysteriaVersionRe.FindString(cleaned)
|
||||
if match == "" {
|
||||
return "-"
|
||||
}
|
||||
return strings.TrimSpace(match)
|
||||
}
|
||||
|
||||
type metricsSnapshot struct {
|
||||
CollectedAt int64
|
||||
System vo.DashboardSystemVo
|
||||
@@ -48,12 +65,16 @@ func getCachedHysteriaVersion(now time.Time) string {
|
||||
}
|
||||
return "-"
|
||||
}
|
||||
normalized := normalizeHysteriaVersion(content)
|
||||
if normalized == "-" {
|
||||
logrus.Debugf("hysteria version parse failed, raw output: %q", strings.TrimSpace(content))
|
||||
}
|
||||
|
||||
metricsStore.Lock()
|
||||
metricsStore.version = content
|
||||
metricsStore.version = normalized
|
||||
metricsStore.versionAt = now
|
||||
metricsStore.Unlock()
|
||||
return content
|
||||
return normalized
|
||||
}
|
||||
|
||||
func CollectMetricsSnapshot() {
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/skip2/go-qrcode"
|
||||
"hy2xs-admin/dao"
|
||||
"hy2xs-admin/model/bo"
|
||||
"hy2xs-admin/model/constant"
|
||||
@@ -171,11 +170,7 @@ func BuildPeerClientConfig(id int64) (vo.PeerClientConfigVo, error) {
|
||||
if err != nil {
|
||||
return vo.PeerClientConfigVo{}, err
|
||||
}
|
||||
qrCode, err := qrcode.Encode(url, qrcode.Medium, 300)
|
||||
if err != nil {
|
||||
return vo.PeerClientConfigVo{}, err
|
||||
}
|
||||
return vo.PeerClientConfigVo{Url: url, QrCode: qrCode}, nil
|
||||
return vo.PeerClientConfigVo{Url: url}, nil
|
||||
}
|
||||
|
||||
func ListExportPeer(includeSecrets bool) ([]bo.PeerExport, error) {
|
||||
|
||||
Reference in New Issue
Block a user