diff --git a/.run/go build github.com_perfect-panel_server.run.xml b/.run/go build github.com_perfect-panel_server.run.xml index 454ba95..608afe7 100644 --- a/.run/go build github.com_perfect-panel_server.run.xml +++ b/.run/go build github.com_perfect-panel_server.run.xml @@ -3,9 +3,6 @@ - - - diff --git a/apis/admin/server.api b/apis/admin/server.api index 34d36bd..e4b4618 100644 --- a/apis/admin/server.api +++ b/apis/admin/server.api @@ -29,6 +29,7 @@ type ( Disk float64 `json:"disk"` Protocol string `json:"protocol"` Online []ServerOnlineUser `json:"online"` + Status string `json:"status"` } Server { Id int64 `json:"id"` diff --git a/internal/logic/admin/server/filterServerListLogic.go b/internal/logic/admin/server/filterServerListLogic.go index 2e4aa04..fb47ffa 100644 --- a/internal/logic/admin/server/filterServerListLogic.go +++ b/internal/logic/admin/server/filterServerListLogic.go @@ -2,6 +2,7 @@ package server import ( "context" + "time" "github.com/perfect-panel/server/internal/model/node" "github.com/perfect-panel/server/internal/svc" @@ -68,6 +69,7 @@ func (l *FilterServerListLogic) FilterServerList(req *types.FilterServerListRequ Cpu: nodeStatus.Cpu, Disk: nodeStatus.Disk, Online: l.handlerServerStatus(datum.Id, protocols), + Status: l.handlerServerStaus(datum.LastReportedAt), } list = append(list, server) } @@ -146,3 +148,17 @@ func (l *FilterServerListLogic) handlerServerStatus(id int64, protocols []types. } return result } + +func (l *FilterServerListLogic) handlerServerStaus(last *time.Time) string { + if last == nil { + return "offline" + } + if time.Since(*last) > time.Minute*5 { + return "offline" + } + if time.Since(*last) > time.Minute*3 { + return "warning" + } + return "online" + +} diff --git a/internal/types/types.go b/internal/types/types.go index 141e903..d54b9aa 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -1753,6 +1753,7 @@ type ServerStatus struct { Disk float64 `json:"disk"` Protocol string `json:"protocol"` Online []ServerOnlineUser `json:"online"` + Status string `json:"status"` } type ServerTotalDataResponse struct {