forked from kuskoman/logstash-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
32 lines (26 loc) · 939 Bytes
/
server.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
package server
import (
"fmt"
"net/http"
"github.com/kuskoman/logstash-exporter/config"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
// NewAppServer creates a new http server with the given host and port
// and registers the prometheus handler and the healthcheck handler
// to the server's mux. The prometheus handler is managed under the
// hood by the prometheus client library.
func NewAppServer(host, port string) *http.Server {
mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.Handler())
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/metrics", http.StatusMovedPermanently)
})
mux.HandleFunc("/healthcheck", getHealthCheck(config.LogstashUrl))
mux.HandleFunc("/version", getVersionInfoHandler(config.GetVersionInfo()))
listenUrl := fmt.Sprintf("%s:%s", host, port)
server := &http.Server{
Addr: listenUrl,
Handler: mux,
}
return server
}