Skip to content

Commit

Permalink
Allow root path as metrics path.
Browse files Browse the repository at this point in the history
Signed-off-by: LamGC <lam827@lamgc.net>
  • Loading branch information
LamGC committed Feb 1, 2023
1 parent 6a0598e commit d94c3a2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions node_exporter.go
Expand Up @@ -186,15 +186,17 @@ func main() {
level.Debug(logger).Log("msg", "Go MAXPROCS", "procs", runtime.GOMAXPROCS(0))

http.Handle(*metricsPath, newHandler(!*disableExporterMetrics, *maxRequests, logger))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
if *metricsPath != "/" {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>Node Exporter</title></head>
<body>
<h1>Node Exporter</h1>
<p><a href="` + *metricsPath + `">Metrics</a></p>
</body>
</html>`))
})
})
}

server := &http.Server{}
if err := web.ListenAndServe(server, toolkitFlags, logger); err != nil {
Expand Down

0 comments on commit d94c3a2

Please sign in to comment.