examples: Improved GoCollector example. (#1589)

Signed-off-by: bwplotka <bwplotka@gmail.com>
This commit is contained in:
Bartlomiej Plotka 2024-09-02 16:43:16 +02:00 committed by GitHub
parent 30da80dfe1
commit fa4f164b6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 5 deletions

View File

@ -37,11 +37,18 @@ func main() {
// Create a new registry. // Create a new registry.
reg := prometheus.NewRegistry() reg := prometheus.NewRegistry()
// Add Go module build info. // Register metrics from GoCollector collecting statistics from the Go Runtime.
reg.MustRegister(collectors.NewBuildInfoCollector()) // This enabled default, recommended metrics with the additional, recommended metric for
reg.MustRegister(collectors.NewGoCollector( // goroutine scheduling latencies histogram that is currently bit too expensive for default option.
collectors.WithGoCollectorRuntimeMetrics(collectors.GoRuntimeMetricsRule{Matcher: regexp.MustCompile("/.*")}), //
)) // 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. // Expose the registered metrics via HTTP.
http.Handle("/metrics", promhttp.HandlerFor( http.Handle("/metrics", promhttp.HandlerFor(