Skip to content

Commit

Permalink
examples: Improved GoCollector example.
Browse files Browse the repository at this point in the history
Signed-off-by: bwplotka <bwplotka@gmail.com>
  • Loading branch information
bwplotka committed Aug 20, 2024
1 parent 7ce5089 commit 2ae15e1
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions examples/gocollector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,18 @@ func main() {
// Create a new registry.
reg := prometheus.NewRegistry()

// Add Go module build info.
reg.MustRegister(collectors.NewBuildInfoCollector())
reg.MustRegister(collectors.NewGoCollector(
collectors.WithGoCollectorRuntimeMetrics(collectors.GoRuntimeMetricsRule{Matcher: regexp.MustCompile("/.*")}),
))
// Register metrics from GoCollector collecting statistics from the Go Runtime.
// This enabled default, recommended metrics with the additional, recommended metric for
// goroutine scheduling latencies histogram that is currently bit too expensive for default option.
//
// See the related GopherConUK talk to learn more: https://www.youtube.com/watch?v=18dyI_8VFa0
reg.MustRegister(
collectors.NewGoCollector(
collectors.WithGoCollectorRuntimeMetrics(
collectors.GoRuntimeMetricsRule{Matcher: regexp.MustCompile("/sched/latencies:seconds")},
),
),
)

// Expose the registered metrics via HTTP.
http.Handle("/metrics", promhttp.HandlerFor(
Expand Down

0 comments on commit 2ae15e1

Please sign in to comment.