Skip to content

Commit

Permalink
one port per instance
Browse files Browse the repository at this point in the history
  • Loading branch information
dogancanbakir committed Sep 2, 2024
1 parent c2096e4 commit ddc34e7
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions clistats.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ func (s *Statistics) metricsHandler(w http.ResponseWriter, req *http.Request) {

// Start starts the event loop of the stats client.
func (s *Statistics) Start() error {
if s.httpServer != nil {
return errorutil.New("server already started")
}

if s.Options.Web {
mux := http.NewServeMux()
mux.HandleFunc("/metrics", s.metricsHandler)
Expand Down Expand Up @@ -209,6 +213,19 @@ func (s *Statistics) Start() error {
return nil
}

// Stop stops the event loop of the stats client
func (s *Statistics) Stop() error {
defer s.cancel()

if s.httpServer != nil {
if err := s.httpServer.Shutdown(s.ctx); err != nil {
return err
}
}

return nil
}

// GetStatResponse returns '/metrics' response for a given interval
func (s *Statistics) GetStatResponse(interval time.Duration, callback func(string, error) error) {
metricCallback := func(url string) (string, error) {
Expand Down Expand Up @@ -242,16 +259,3 @@ func (s *Statistics) GetStatResponse(interval time.Duration, callback func(strin
}
}()
}

// Stop stops the event loop of the stats client
func (s *Statistics) Stop() error {
defer s.cancel()

if s.httpServer != nil {
if err := s.httpServer.Shutdown(s.ctx); err != nil {
return err
}
}

return nil
}

0 comments on commit ddc34e7

Please sign in to comment.