Send server stat updates over the websocket
This commit is contained in:
parent
923a9fbcab
commit
64f477f423
|
@ -317,6 +317,9 @@ func (d *DockerEnvironment) EnableResourcePolling() error {
|
|||
s.Resources.Network.RxBytes += nw.RxBytes
|
||||
s.Resources.Network.TxBytes += nw.TxBytes
|
||||
}
|
||||
|
||||
b, _ := json.Marshal(s.Resources)
|
||||
s.Emit(StatsEvent, string(b))
|
||||
}
|
||||
}(d.Server)
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ type EventListenerFunction *func(string)
|
|||
const (
|
||||
ConsoleOutputEvent = "console output"
|
||||
StatusEvent = "status"
|
||||
StatsEvent = "stats"
|
||||
)
|
||||
|
||||
// Adds an event listener for the server instance.
|
||||
|
|
10
websocket.go
10
websocket.go
|
@ -71,12 +71,22 @@ func (rt *Router) routeWebsocket(w http.ResponseWriter, r *http.Request, ps http
|
|||
})
|
||||
}
|
||||
|
||||
handleResourceUse := func(data string) {
|
||||
handler.SendJson(&WebsocketMessage{
|
||||
Event: server.StatsEvent,
|
||||
Args: []string{data},
|
||||
})
|
||||
}
|
||||
|
||||
s.AddListener(server.StatusEvent, &handleServerStatus)
|
||||
defer s.RemoveListener(server.StatusEvent, &handleServerStatus)
|
||||
|
||||
s.AddListener(server.ConsoleOutputEvent, &handleOutput)
|
||||
defer s.RemoveListener(server.ConsoleOutputEvent, &handleOutput)
|
||||
|
||||
s.AddListener(server.StatsEvent, &handleResourceUse)
|
||||
defer s.RemoveListener(server.StatsEvent, &handleResourceUse)
|
||||
|
||||
s.Emit(server.StatusEvent, s.State)
|
||||
|
||||
for {
|
||||
|
|
Loading…
Reference in New Issue
Block a user