fix(server): add server status handling based on last reported time
This commit is contained in:
parent
3e5284c4ec
commit
ca344a1ce9
@ -3,9 +3,6 @@
|
|||||||
<module name="server" />
|
<module name="server" />
|
||||||
<working_directory value="$PROJECT_DIR$" />
|
<working_directory value="$PROJECT_DIR$" />
|
||||||
<parameters value="run --config etc/ppanel-dev.yaml" />
|
<parameters value="run --config etc/ppanel-dev.yaml" />
|
||||||
<envs>
|
|
||||||
<env name="PPANEL_MODE" value="demo" />
|
|
||||||
</envs>
|
|
||||||
<kind value="PACKAGE" />
|
<kind value="PACKAGE" />
|
||||||
<package value="github.com/perfect-panel/server" />
|
<package value="github.com/perfect-panel/server" />
|
||||||
<directory value="$PROJECT_DIR$" />
|
<directory value="$PROJECT_DIR$" />
|
||||||
|
|||||||
@ -29,6 +29,7 @@ type (
|
|||||||
Disk float64 `json:"disk"`
|
Disk float64 `json:"disk"`
|
||||||
Protocol string `json:"protocol"`
|
Protocol string `json:"protocol"`
|
||||||
Online []ServerOnlineUser `json:"online"`
|
Online []ServerOnlineUser `json:"online"`
|
||||||
|
Status string `json:"status"`
|
||||||
}
|
}
|
||||||
Server {
|
Server {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/perfect-panel/server/internal/model/node"
|
"github.com/perfect-panel/server/internal/model/node"
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
@ -68,6 +69,7 @@ func (l *FilterServerListLogic) FilterServerList(req *types.FilterServerListRequ
|
|||||||
Cpu: nodeStatus.Cpu,
|
Cpu: nodeStatus.Cpu,
|
||||||
Disk: nodeStatus.Disk,
|
Disk: nodeStatus.Disk,
|
||||||
Online: l.handlerServerStatus(datum.Id, protocols),
|
Online: l.handlerServerStatus(datum.Id, protocols),
|
||||||
|
Status: l.handlerServerStaus(datum.LastReportedAt),
|
||||||
}
|
}
|
||||||
list = append(list, server)
|
list = append(list, server)
|
||||||
}
|
}
|
||||||
@ -146,3 +148,17 @@ func (l *FilterServerListLogic) handlerServerStatus(id int64, protocols []types.
|
|||||||
}
|
}
|
||||||
return result
|
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"
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@ -1753,6 +1753,7 @@ type ServerStatus struct {
|
|||||||
Disk float64 `json:"disk"`
|
Disk float64 `json:"disk"`
|
||||||
Protocol string `json:"protocol"`
|
Protocol string `json:"protocol"`
|
||||||
Online []ServerOnlineUser `json:"online"`
|
Online []ServerOnlineUser `json:"online"`
|
||||||
|
Status string `json:"status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServerTotalDataResponse struct {
|
type ServerTotalDataResponse struct {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user