Merge pull request #2 from WilliButz/add-features
add basic landing page, configurable metrics path and more log output
This commit is contained in:
commit
14cdb8f33e
18
dnsmasq.go
18
dnsmasq.go
@ -19,7 +19,6 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -29,6 +28,7 @@ import (
|
|||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
|
"github.com/prometheus/common/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -43,6 +43,9 @@ var (
|
|||||||
dnsmasqAddr = flag.String("dnsmasq",
|
dnsmasqAddr = flag.String("dnsmasq",
|
||||||
"localhost:53",
|
"localhost:53",
|
||||||
"dnsmasq host:port address")
|
"dnsmasq host:port address")
|
||||||
|
metricsPath = flag.String("metrics_path",
|
||||||
|
"/metrics",
|
||||||
|
"path under which metrics are served")
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -160,6 +163,7 @@ func (s *server) metrics(w http.ResponseWriter, r *http.Request) {
|
|||||||
eg.Go(func() error {
|
eg.Go(func() error {
|
||||||
f, err := os.Open(s.leasesPath)
|
f, err := os.Open(s.leasesPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Warnln("could not open leases file:", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
@ -193,6 +197,16 @@ func main() {
|
|||||||
dnsmasqAddr: *dnsmasqAddr,
|
dnsmasqAddr: *dnsmasqAddr,
|
||||||
leasesPath: *leasesPath,
|
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.Infoln("Listening on", *listen)
|
||||||
|
log.Infoln("Serving metrics under", *metricsPath)
|
||||||
log.Fatal(http.ListenAndServe(*listen, nil))
|
log.Fatal(http.ListenAndServe(*listen, nil))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user