Replace logic with PublishJson
This commit is contained in:
		
							parent
							
								
									b779c98717
								
							
						
					
					
						commit
						53bd0d57ad
					
				| 
						 | 
					@ -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.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user