/
main.go
42 lines (33 loc) 路 1.04 KB
/
main.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
39
40
41
42
package main
import (
"flag"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"log"
"net/http"
)
var (
addr = flag.String("listen-address", ":8080", "The address to listen on for HTTP requests.")
targetServer = flag.String("target.host", "localhost", "The host to monitor.")
targetPort = flag.Int("target.port", 3979, "The port to monitor.")
)
func healthz() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
return
})
}
func main() {
flag.Parse()
reg := prometheus.NewPedanticRegistry()
NewOpenttdCollector(reg)
// Add the standard process and Go metrics to the custom registry.
reg.MustRegister(
prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}),
prometheus.NewGoCollector(),
)
// Expose the registered metrics via HTTP.
http.Handle("/metrics", promhttp.HandlerFor(reg, promhttp.HandlerOpts{}))
http.Handle("/health", healthz())
log.Fatal(http.ListenAndServe(*addr, nil))
}