diff --git a/prometheus.go b/prometheus.go index c3b7ad1..2920d4b 100644 --- a/prometheus.go +++ b/prometheus.go @@ -28,18 +28,18 @@ func newMetrics(hostAndPort string) *metrics { return &m } -func (s *server) startMetrics() error { +func (m *metrics) start() error { //http.Handle("/metrics", promhttp.Handler()) //http.ListenAndServe(":2112", nil) - n, err := net.Listen("tcp", s.metrics.hostAndPort) + n, err := net.Listen("tcp", m.hostAndPort) if err != nil { return fmt.Errorf("error: startMetrics: failed to open prometheus listen port: %v", err) } - m := http.NewServeMux() - m.Handle("/metrics", promhttp.Handler()) + mux := http.NewServeMux() + mux.Handle("/metrics", promhttp.Handler()) - err = http.Serve(n, m) + err = http.Serve(n, mux) if err != nil { return fmt.Errorf("error: startMetrics: failed to start http.Serve: %v", err) } diff --git a/server.go b/server.go index 7f54d27..6f02639 100644 --- a/server.go +++ b/server.go @@ -244,24 +244,22 @@ func (s *server) Start() { s.ctxCancelFunc() log.Printf("info: stopping the main server context with ctxCancelFunc()\n") }() + // Start the error kernel that will do all the error handling // that is not done within a process. - { - s.errorKernel = newErrorKernel(s.ctx) - - go func() { - err := s.errorKernel.start(s.toRingbufferCh) - if err != nil { - log.Printf("%v\n", err) - } - }() - defer s.errorKernel.stop() - } - - // Start collecting the metrics + s.errorKernel = newErrorKernel(s.ctx) go func() { - err := s.startMetrics() + err := s.errorKernel.start(s.toRingbufferCh) + if err != nil { + log.Printf("%v\n", err) + } + }() + defer s.errorKernel.stop() + + // Start collecting the metrics + go func() { + err := s.metrics.start() if err != nil { log.Printf("%v\n", err) os.Exit(1)