add configurable metrics path and minimal landing page

This commit is contained in:
WilliButz 2018-05-06 15:12:19 +02:00
parent e1f281b435
commit 025856a69c
No known key found for this signature in database
GPG key ID: 92582A10F1179CB2

View file

@ -43,6 +43,9 @@ var (
dnsmasqAddr = flag.String("dnsmasq",
"localhost:53",
"dnsmasq host:port address")
metricsPath = flag.String("metrics_path",
"/metrics",
"path under which metrics are served")
)
var (
@ -193,6 +196,14 @@ func main() {
dnsmasqAddr: *dnsmasqAddr,
leasesPath: *leasesPath,
}
http.HandleFunc("/metrics", s.metrics)
http.HandleFunc(*metricsPath, s.metrics)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>Dnsmasq Exporter</title></head>
<body>
<h1>Dnsmasq Exporter</h1>
<p><a href="` + *metricsPath + `">Metrics</a></p>
</body></html>`))
})
log.Fatal(http.ListenAndServe(*listen, nil))
}