From 025856a69c647bedbf8f67e862a65e856894c501 Mon Sep 17 00:00:00 2001 From: WilliButz Date: Sun, 6 May 2018 15:12:19 +0200 Subject: [PATCH 1/2] add configurable metrics path and minimal landing page --- dnsmasq.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/dnsmasq.go b/dnsmasq.go index 73d53e8..c784ff9 100644 --- a/dnsmasq.go +++ b/dnsmasq.go @@ -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(` + Dnsmasq Exporter + +

Dnsmasq Exporter

+

Metrics

+ `)) + }) log.Fatal(http.ListenAndServe(*listen, nil)) } From 55f7e71b1e324a01a770b5d9ab7bb63ade3dd7c7 Mon Sep 17 00:00:00 2001 From: WilliButz Date: Sun, 6 May 2018 15:13:33 +0200 Subject: [PATCH 2/2] add log output and use the prometheus log library --- dnsmasq.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dnsmasq.go b/dnsmasq.go index c784ff9..2f74278 100644 --- a/dnsmasq.go +++ b/dnsmasq.go @@ -19,7 +19,6 @@ import ( "bufio" "flag" "fmt" - "log" "net/http" "os" "strconv" @@ -29,6 +28,7 @@ import ( "github.com/miekg/dns" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" + "github.com/prometheus/common/log" ) var ( @@ -163,6 +163,7 @@ func (s *server) metrics(w http.ResponseWriter, r *http.Request) { eg.Go(func() error { f, err := os.Open(s.leasesPath) if err != nil { + log.Warnln("could not open leases file:", err) return err } defer f.Close() @@ -205,5 +206,7 @@ func main() {

Metrics

`)) }) + log.Infoln("Listening on", *listen) + log.Infoln("Serving metrics under", *metricsPath) log.Fatal(http.ListenAndServe(*listen, nil)) }