daemon: update metrics.go
update error checking and add comments for exported functions/vars
[4.3] Add prometheus service monitor and MCD metrics listener
@@ -8,8 +8,10 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
)
+// DefaultBindAddress is the port for the metrics listener
var DefaultBindAddress = ":8797"
+// StartMetricsListener is metrics listener via http on localhost
func StartMetricsListener(addr string, stopCh chan struct{}) {
if addr == "" {
addr = DefaultBindAddress
@@ -20,12 +22,12 @@ func StartMetricsListener(addr string, stopCh chan struct{}) {
mux.Handle("/metrics", promhttp.Handler())
s := http.Server{Addr: addr, Handler: mux}
go func() {
- if err := s.ListenAndServe(); err != nil {
- glog.Exitf("Unable to start metrics listener: %v", err)
+ if err := s.ListenAndServe(); err != nil && err != http.ErrServerClosed {
+ glog.Errorf("metrics listener exited with error: %v", err)
}
}()
<-stopCh
if err := s.Shutdown(context.Background()); err != http.ErrServerClosed {
- glog.Infof("Error stopping metrics listener: %v", err)
+ glog.Errorf("error stopping metrics listener: %v", err)
}
}
