git » prometheus-expvar-exporter » commit faaa4e6

Add an HTTP handler for /

author Alberto Bertogli
2019-10-31 02:07:02 UTC
committer Alberto Bertogli
2019-10-31 02:07:02 UTC
parent fb8018ec5698e6fd2d33deee67a8c4823cc59c95

Add an HTTP handler for /

To make it easier and more friendly to users, add a simple
static index page.

main.go +25 -0

diff --git a/main.go b/main.go
index 5aef6d1..4c852ae 100644
--- a/main.go
+++ b/main.go
@@ -58,6 +58,7 @@ func main() {
 		prometheus.MustRegister(c)
 	}
 
+	http.HandleFunc("/", indexHandler)
 	http.Handle("/metrics", promhttp.Handler())
 
 	addr := config.Get("listen_addr").(string)
@@ -172,3 +173,27 @@ func valToFloat(v interface{}) float64 {
 	}
 	panic(fmt.Sprintf("unexpected value type: %#v"))
 }
+
+const indexHTML = `<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8">
+    <title>expvar exporter</title>
+  </head>
+  <body>
+    <h1>Prometheus expvar exporter</h1>
+
+    This is a <a href="https://prometheus.io">Prometheus</a>
+    <a href="https://prometheus.io/docs/instrumenting/exporters/">exporter</a>,
+    takes <a href="https://golang.org/pkg/expvar/">expvars</a> and converts
+    them to Prometheus metrics.<p>
+
+    Go to <tt><a href="/metrics">/metrics</a></tt> to see the exported metrics.
+
+  </body>
+</html
+`
+
+func indexHandler(w http.ResponseWriter, r *http.Request) {
+	w.Write([]byte(indexHTML))
+}