Skip to content

Commit

Permalink
Use Prometheus exporter-toolkit to generate landing page
Browse files Browse the repository at this point in the history
This is now the de facto method for exporters to display a landing page.

Signed-off-by: Daniel Swarbrick <[email protected]>
  • Loading branch information
dswarbrick committed Feb 4, 2024
1 parent 27cb001 commit 6835d16
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions apache_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,24 @@ func main() {
}()

http.Handle(*metricsEndpoint, promhttp.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(`<html>
<head><title>Apache Exporter</title></head>
<body>
<h1>Apache Exporter</h1>
<p><a href='` + *metricsEndpoint + `'>Metrics</a></p>
</body>
</html>`))
})

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 {
Expand Down

0 comments on commit 6835d16

Please sign in to comment.