mirror of
https://github.com/postmannen/ctrl.git
synced 2025-03-05 06:46:48 +00:00
restructured the start of metrics
This commit is contained in:
parent
95e2984c86
commit
09f28a79a7
2 changed files with 17 additions and 19 deletions
|
@ -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)
|
||||
}
|
||||
|
|
26
server.go
26
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)
|
||||
|
|
Loading…
Add table
Reference in a new issue