Skip to content

Commit 0b7f488

Browse files
committed
Update simple example to use custom registry
Signed-off-by: Jéssica Lins <[email protected]>
1 parent 9b5c5b8 commit 0b7f488

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

examples/simple/main.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,20 @@ import (
1818
"flag"
1919
"log"
2020
"net/http"
21-
21+
22+
"github.com/prometheus/client_golang/prometheus"
2223
"github.com/prometheus/client_golang/prometheus/promhttp"
2324
)
2425

2526
var addr = flag.String("listen-address", ":8080", "The address to listen on for HTTP requests.")
2627

2728
func main() {
2829
flag.Parse()
29-
http.Handle("/metrics", promhttp.Handler())
30+
31+
// Create non-global registry.
32+
reg := prometheus.NewRegistry()
33+
34+
// Expose /metrics HTTP endpoint using the created custom registry.
35+
http.Handle("/metrics", promhttp.HandlerFor(reg, promhttp.HandlerOpts{Registry: reg}))
3036
log.Fatal(http.ListenAndServe(*addr, nil))
3137
}

0 commit comments

Comments
 (0)