From c13f8086194f55b1204c3165836a809f2c9aaabe Mon Sep 17 00:00:00 2001 From: LamGC Date: Thu, 9 Mar 2023 00:15:39 +0800 Subject: [PATCH] Allow root path as metrics path. (#2590) Signed-off-by: LamGC --- node_exporter.go | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/node_exporter.go b/node_exporter.go index a68af050..709810a4 100644 --- a/node_exporter.go +++ b/node_exporter.go @@ -186,23 +186,25 @@ func main() { level.Debug(logger).Log("msg", "Go MAXPROCS", "procs", runtime.GOMAXPROCS(0)) http.Handle(*metricsPath, newHandler(!*disableExporterMetrics, *maxRequests, logger)) - landingConfig := web.LandingConfig{ - Name: "Node Exporter", - Description: "Prometheus Node Exporter", - Version: version.Info(), - Links: []web.LandingLinks{ - { - Address: *metricsPath, - Text: "Metrics", + if *metricsPath != "/" { + landingConfig := web.LandingConfig{ + Name: "Node Exporter", + Description: "Prometheus Node Exporter", + Version: version.Info(), + Links: []web.LandingLinks{ + { + Address: *metricsPath, + Text: "Metrics", + }, }, - }, + } + landingPage, err := web.NewLandingPage(landingConfig) + if err != nil { + level.Error(logger).Log("err", err) + os.Exit(1) + } + http.Handle("/", landingPage) } - landingPage, err := web.NewLandingPage(landingConfig) - if err != nil { - level.Error(logger).Log("err", err) - os.Exit(1) - } - http.Handle("/", landingPage) server := &http.Server{} if err := web.ListenAndServe(server, toolkitFlags, logger); err != nil {