Skip to content

examples: Improved GoCollector example. #1589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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