From 53bd0d57ad9d7b7fbca49f8306c1e080997ae17a Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 12 Sep 2020 20:13:48 -0700 Subject: [PATCH] Replace logic with PublishJson --- server/resources.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/server/resources.go b/server/resources.go index bd77f9b..db7bea8 100644 --- a/server/resources.go +++ b/server/resources.go @@ -1,7 +1,6 @@ package server import ( - "encoding/json" "github.com/pterodactyl/wings/environment" "sync" ) @@ -37,14 +36,10 @@ func (s *Server) Proc() *ResourceUsage { func (s *Server) emitProcUsage() { s.resources.mu.RLock() - defer s.resources.mu.RUnlock() - - b, err := json.Marshal(s.resources) - if err == nil { - s.Events().Publish(StatsEvent, string(b)) + if err := s.Events().PublishJson(StatsEvent, s.resources); err != nil { + s.Log().WithField("error", err).Warn("error while emitting server resource usage to listeners") } - - // TODO: This might be a good place to add a debug log if stats are not sending. + s.resources.mu.RUnlock() } // Returns the servers current state.