Update simple example to use custom registry

Signed-off-by: Jéssica Lins <jessicaalins@gmail.com>
This commit is contained in:
Jéssica Lins 2022-10-21 16:21:19 +02:00
parent 9b5c5b8a47
commit 0b7f4888b0
No known key found for this signature in database
GPG Key ID: D81F1550FA3B93C0
1 changed files with 8 additions and 2 deletions

View File

@ -19,6 +19,7 @@ import (
"log" "log"
"net/http" "net/http"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp" "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() { func main() {
flag.Parse() 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)) log.Fatal(http.ListenAndServe(*addr, nil))
} }