-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.go
59 lines (47 loc) · 1.39 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"flag"
"log"
"net"
"net/http"
"os"
"path/filepath"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/gen2brain/keepalived_exporter/collector"
)
var version, commit, date string
func main() {
listenAddr := flag.String("web.listen-address", ":9650", "Address to listen on for web interface and telemetry.")
metricsPath := flag.String("web.telemetry-path", "/metrics", "A path under which to expose metrics.")
appVersion := flag.Bool("version", false, "Display version information.")
flag.Parse()
if *appVersion {
println(filepath.Base(os.Args[0]), version, commit, date)
os.Exit(0)
}
c, err := collector.New()
if err != nil {
log.Fatal(err)
}
defer c.Close()
registry := prometheus.NewRegistry()
registry.MustRegister(c)
http.Handle(*metricsPath, promhttp.HandlerFor(registry, promhttp.HandlerOpts{}))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(`<html>
<head><title>Keepalived Exporter</title></head>
<body>
<h1>Keepalived Exporter</h1>
<p><a href='` + *metricsPath + `'>Metrics</a></p>
</body>
</html>`))
})
srv := &http.Server{}
listener, err := net.Listen("tcp4", *listenAddr)
if err != nil {
log.Fatal(err)
}
log.Printf("Providing metrics at %s%s", *listenAddr, *metricsPath)
log.Fatal(srv.Serve(listener))
}