mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-03-31 02:26:20 +00:00
metric-api: http server error handling
This commit is contained in:
parent
3c6173d7f2
commit
7363f49ae3
1 changed files with 10 additions and 5 deletions
|
@ -1,6 +1,8 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
|
@ -53,12 +55,15 @@ func (s *metricServer) Start() error {
|
|||
if !s.opts.Enabled() {
|
||||
return nil
|
||||
}
|
||||
listener, err := net.Listen("tcp", s.opts.Listen)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.logger.Info("metrics api listening at ", s.http.Addr, s.opts.Path)
|
||||
go func() {
|
||||
err := s.http.ListenAndServe()
|
||||
if err != nil {
|
||||
s.logger.Error("metrics api listen error", err)
|
||||
} else {
|
||||
s.logger.Info("metrics api listening at ", s.http.Addr, s.opts.Path)
|
||||
err := s.http.Serve(listener)
|
||||
if err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||
s.logger.Error("metrics api serve error: ", err)
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
|
|
Loading…
Add table
Reference in a new issue