feat: 自动备份与保留策略、健康持续化与状态页、指标历史与趋势图,并修隧道判定误报与仪表盘布局(v1.2.11)
- 自动备份:每日一份(按最新备份是否在 24h 内判定,重启不重复)、保留份数可配、列表/下载/恢复/删除,恢复前先校验归档;顺手修 writeArchive 逐个检查 tar/gzip/文件 Close()(审查报告 §二) - 健康持续化:只存状态变更(up/down/unknown)并推导可用率与不可用区间;公开状态页默认关闭、访问码存 SHA-256、按 IP 限流、只暴露域名与可用率 - 隧道判定修复:RouteHealthCandidate 新增 tunnel_known,frps 管理接口不可用时不再把「判不出来」当成「不通」(此前会误报「隧道连续不通」);汇总与徽标同样区分「无法判定」 - 指标历史:metrics_samples 纵向点表(本机 CPU/内存/磁盘 + 每规则上下行,30 天保留、查询按桶平均、不做降采样表);仪表盘趋势卡支持 1h/24h/7d - 仪表盘布局:运行状态并入顶部统计区(运行时长补进「服务」卡);性能并入系统资源那一行,整行 4 列 - 测试:backup/metrics/frp/api/app 新增用例;gofmt、go build/vet/test、vue-tsc、vite build 全绿 - agent 无改动,AgentVersion 保持 0.12.2
This commit is contained in:
@@ -7,13 +7,15 @@ import (
|
||||
|
||||
"github.com/fonu/fonu/internal/frp"
|
||||
"github.com/fonu/fonu/internal/monitor"
|
||||
"github.com/fonu/fonu/internal/traffic"
|
||||
)
|
||||
|
||||
// monitorSource 把 frp 服务适配成 monitor.Source:monitor 只关心「状态快照」,
|
||||
// 怎么从 frp / agent 取是这里的事,两边因此互不依赖。
|
||||
type monitorSource struct {
|
||||
frp *frp.Service
|
||||
logger *slog.Logger
|
||||
frp *frp.Service
|
||||
logger *slog.Logger
|
||||
traffic *traffic.Collector
|
||||
}
|
||||
|
||||
func (s monitorSource) Routes(ctx context.Context) ([]monitor.RouteStatus, error) {
|
||||
@@ -30,7 +32,15 @@ func (s monitorSource) Routes(ctx context.Context) ([]monitor.RouteStatus, error
|
||||
continue
|
||||
}
|
||||
for _, item := range health {
|
||||
routes = append(routes, monitor.RouteStatus{Domain: item.Domain, TunnelOK: item.TunnelOK, Detail: item.TunnelDetail})
|
||||
routes = append(routes, monitor.RouteStatus{
|
||||
ServerID: server.ID,
|
||||
Domain: item.Domain,
|
||||
TunnelOK: item.TunnelOK,
|
||||
DNSOK: item.DNSOK,
|
||||
ServiceOK: item.ServiceOK,
|
||||
Known: item.TunnelKnown,
|
||||
Detail: item.TunnelDetail,
|
||||
})
|
||||
}
|
||||
}
|
||||
return routes, nil
|
||||
@@ -98,6 +108,19 @@ func (s monitorSource) Drift(ctx context.Context) ([]monitor.DriftStatus, error)
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Traffic 返回若干域名的当前上下行速率:流量采集器内部按 host:port 累计,这里按域名合并。
|
||||
func (s monitorSource) Traffic(ctx context.Context, domains []string) (map[string]monitor.TrafficRate, error) {
|
||||
if s.traffic == nil {
|
||||
return nil, nil
|
||||
}
|
||||
snapshot := s.traffic.SnapshotByHost(domains)
|
||||
rates := make(map[string]monitor.TrafficRate, len(snapshot))
|
||||
for host, item := range snapshot {
|
||||
rates[host] = monitor.TrafficRate{Upload: item.UploadRate, Download: item.DownloadRate}
|
||||
}
|
||||
return rates, nil
|
||||
}
|
||||
|
||||
func (s monitorSource) enabledServers(ctx context.Context) ([]frp.Server, error) {
|
||||
servers, err := s.frp.ListServers(ctx)
|
||||
if err != nil {
|
||||
@@ -128,3 +151,40 @@ func driftKindText(kind string) string {
|
||||
return kind
|
||||
}
|
||||
}
|
||||
|
||||
// healthRecorder 把 monitor 的健康结论翻成 frp 侧样本并落库(
|
||||
// 两侧的状态字面量由 healthStateValue 显式翻译,改动一侧会在这里编译期报错)。
|
||||
type healthRecorder struct {
|
||||
frp *frp.Service
|
||||
}
|
||||
|
||||
func (r healthRecorder) RecordRouteHealth(ctx context.Context, samples []monitor.HealthSample) error {
|
||||
converted := make([]frp.RouteHealthSample, 0, len(samples))
|
||||
for _, sample := range samples {
|
||||
converted = append(converted, frp.RouteHealthSample{
|
||||
ServerID: sample.ServerID,
|
||||
Domain: sample.Domain,
|
||||
State: healthStateValue(sample.State),
|
||||
Reason: sample.Reason,
|
||||
Detail: sample.Detail,
|
||||
})
|
||||
}
|
||||
_, err := r.frp.RecordRouteHealth(ctx, converted)
|
||||
return err
|
||||
}
|
||||
|
||||
func (r healthRecorder) PruneRouteHealth(ctx context.Context) error {
|
||||
_, err := r.frp.PruneRouteHealth(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
func healthStateValue(state string) string {
|
||||
switch state {
|
||||
case monitor.HealthUp:
|
||||
return frp.RouteHealthUp
|
||||
case monitor.HealthDown:
|
||||
return frp.RouteHealthDown
|
||||
default:
|
||||
return frp.RouteHealthUnknown
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user