From 92a7bd97b32d981c1ef1d17cbc9b49ec779cff19 Mon Sep 17 00:00:00 2001 From: Daniel Swarbrick Date: Mon, 5 Feb 2024 19:35:40 +0100 Subject: [PATCH] Use Prometheus exporter-toolkit to generate landing page (#189) This is now the de facto method for exporters to display a landing page. Signed-off-by: Daniel Swarbrick --- apache_exporter.go | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/apache_exporter.go b/apache_exporter.go index f1a42ad..30fca32 100644 --- a/apache_exporter.go +++ b/apache_exporter.go @@ -76,15 +76,24 @@ func main() { }() http.Handle(*metricsEndpoint, promhttp.Handler()) - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - _, _ = w.Write([]byte(` - Apache Exporter - -

Apache Exporter

-

Metrics

- - `)) - }) + + landingConfig := web.LandingConfig{ + Name: "Apache Exporter", + Description: "Prometheus exporter for Apache HTTP server metrics", + Version: version.Info(), + Links: []web.LandingLinks{ + { + Address: *metricsEndpoint, + Text: "Metrics", + }, + }, + } + 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 {