Replace logic with PublishJson

This commit is contained in:
Dane Everitt 2020-09-12 20:13:48 -07:00
parent b779c98717
commit 53bd0d57ad
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53

View File

@ -1,7 +1,6 @@
package server package server
import ( import (
"encoding/json"
"github.com/pterodactyl/wings/environment" "github.com/pterodactyl/wings/environment"
"sync" "sync"
) )
@ -37,14 +36,10 @@ func (s *Server) Proc() *ResourceUsage {
func (s *Server) emitProcUsage() { func (s *Server) emitProcUsage() {
s.resources.mu.RLock() s.resources.mu.RLock()
defer s.resources.mu.RUnlock() if err := s.Events().PublishJson(StatsEvent, s.resources); err != nil {
s.Log().WithField("error", err).Warn("error while emitting server resource usage to listeners")
b, err := json.Marshal(s.resources)
if err == nil {
s.Events().Publish(StatsEvent, string(b))
} }
s.resources.mu.RUnlock()
// TODO: This might be a good place to add a debug log if stats are not sending.
} }
// Returns the servers current state. // Returns the servers current state.