From 0b7f4888b0e336ae1d2dbfc1b499888d764a3124 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9ssica=20Lins?= Date: Fri, 21 Oct 2022 16:21:19 +0200 Subject: [PATCH] Update simple example to use custom registry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jéssica Lins --- examples/simple/main.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/simple/main.go b/examples/simple/main.go index 1fc2324..e2c0310 100644 --- a/examples/simple/main.go +++ b/examples/simple/main.go @@ -18,7 +18,8 @@ import ( "flag" "log" "net/http" - + + "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" ) @@ -26,6 +27,11 @@ var addr = flag.String("listen-address", ":8080", "The address to listen on for func main() { flag.Parse() - http.Handle("/metrics", promhttp.Handler()) + + // Create non-global registry. + reg := prometheus.NewRegistry() + + // Expose /metrics HTTP endpoint using the created custom registry. + http.Handle("/metrics", promhttp.HandlerFor(reg, promhttp.HandlerOpts{Registry: reg})) log.Fatal(http.ListenAndServe(*addr, nil)) }