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)) }