/
utils.go
38 lines (29 loc) · 1.05 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package monitoring
import (
"fmt"
"net/http"
"github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/bygui86/go-traces/http-server/commons"
"github.com/bygui86/go-traces/http-server/logging"
)
func (s *Server) newRouter() {
logging.SugaredLog.Debugf("Setup new monitoring router")
s.router = mux.NewRouter().StrictSlash(true)
s.router.Handle("/metrics", promhttp.Handler())
}
func (s *Server) newHTTPServer() {
logging.SugaredLog.Debugf("Setup new monitoring HTTP server on port %d...", s.config.restPort)
if s.config != nil {
s.httpServer = &http.Server{
Addr: fmt.Sprintf(commons.HttpServerHostFormat, s.config.restHost, s.config.restPort),
Handler: s.router,
// Good practice to set timeouts to avoid Slowloris attacks.
WriteTimeout: commons.HttpServerWriteTimeoutDefault,
ReadTimeout: commons.HttpServerReadTimeoutDefault,
IdleTimeout: commons.HttpServerIdelTimeoutDefault,
}
return
}
logging.Log.Error("Monitoring HTTP server creation failed: monitoring configurations not loaded")
}