Merge pull request #32 from pterodactyl/issue/1796
Send disk usage when server is offline
This commit is contained in:
commit
62e5547c6d
|
@ -1,6 +1,7 @@
|
||||||
package websocket
|
package websocket
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gbrlsnchs/jwt/v3"
|
"github.com/gbrlsnchs/jwt/v3"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
@ -221,15 +222,40 @@ func (h *Handler) HandleInbound(m Message) error {
|
||||||
h.setJwt(token)
|
h.setJwt(token)
|
||||||
}
|
}
|
||||||
|
|
||||||
// On every authentication event, send the current server status back
|
|
||||||
// to the client. :)
|
|
||||||
h.server.Events().Publish(server.StatusEvent, h.server.GetState())
|
|
||||||
|
|
||||||
h.unsafeSendJson(Message{
|
h.unsafeSendJson(Message{
|
||||||
Event: AuthenticationSuccessEvent,
|
Event: AuthenticationSuccessEvent,
|
||||||
Args: []string{},
|
Args: []string{},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// On every authentication event, send the current server status back
|
||||||
|
// to the client. :)
|
||||||
|
state := h.server.GetState()
|
||||||
|
h.SendJson(&Message{
|
||||||
|
Event: server.StatusEvent,
|
||||||
|
Args: []string{state},
|
||||||
|
})
|
||||||
|
|
||||||
|
// Only send the current disk usage if the server is offline, if docker container is running,
|
||||||
|
// Environment#EnableResourcePolling() will send this data to all clients.
|
||||||
|
if state == server.ProcessOfflineState {
|
||||||
|
_ = h.server.Filesystem.HasSpaceAvailable()
|
||||||
|
|
||||||
|
resources := server.ResourceUsage{
|
||||||
|
Memory: 0,
|
||||||
|
MemoryLimit: 0,
|
||||||
|
CpuAbsolute: 0.0,
|
||||||
|
Disk: h.server.Resources.Disk,
|
||||||
|
}
|
||||||
|
resources.Network.RxBytes = 0
|
||||||
|
resources.Network.TxBytes = 0
|
||||||
|
|
||||||
|
b, _ := json.Marshal(resources)
|
||||||
|
h.SendJson(&Message{
|
||||||
|
Event: server.StatsEvent,
|
||||||
|
Args: []string{string(b)},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
case SetStateEvent:
|
case SetStateEvent:
|
||||||
|
|
|
@ -247,6 +247,10 @@ func FromConfiguration(data *api.ServerConfigurationResponse) (*Server, error) {
|
||||||
}
|
}
|
||||||
s.Resources = ResourceUsage{}
|
s.Resources = ResourceUsage{}
|
||||||
|
|
||||||
|
// Force the disk usage to become cached to return in a resources response
|
||||||
|
// or when connecting to the websocket of an offline server.
|
||||||
|
go s.Filesystem.HasSpaceAvailable()
|
||||||
|
|
||||||
// Forces the configuration to be synced with the panel.
|
// Forces the configuration to be synced with the panel.
|
||||||
if err := s.SyncWithConfiguration(data); err != nil {
|
if err := s.SyncWithConfiguration(data); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in New Issue
Block a user