Skip to content

Commit a1949ba

Browse files
rickbijkerkRick Bijkerk
andauthored
add additional goroutine metrics (#158)
Co-authored-by: Rick Bijkerk <[email protected]>
1 parent e48988b commit a1949ba

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

cmd/serve.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"github.com/ldebruijn/graphql-protect/internal/app/config"
7+
_ "github.com/ldebruijn/graphql-protect/internal/app/metrics"
78
"github.com/ldebruijn/graphql-protect/internal/app/otel"
89
"github.com/ldebruijn/graphql-protect/internal/business/protect"
910
"github.com/ldebruijn/graphql-protect/internal/business/rules/block_field_suggestions"

internal/app/metrics/metrics.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package metrics
2+
3+
import (
4+
"github.com/prometheus/client_golang/prometheus"
5+
"github.com/prometheus/client_golang/prometheus/collectors"
6+
"regexp"
7+
)
8+
9+
func init() {
10+
// Register metrics from GoCollector collecting statistics from the Go Runtime.
11+
// This enabled default, recommended metrics with the additional, recommended metric for
12+
// goroutine scheduling latencies histogram that is currently bit too expensive for the default option.
13+
//
14+
// See the related GopherConUK talk to learn more: https://www.youtube.com/watch?v=18dyI_8VFa0
15+
16+
// Unregister the default GoCollector.
17+
prometheus.Unregister(collectors.NewGoCollector())
18+
19+
// Register the default GoCollector with a custom config.
20+
prometheus.MustRegister(
21+
collectors.NewGoCollector(
22+
collectors.WithGoCollectorRuntimeMetrics(
23+
collectors.GoRuntimeMetricsRule{Matcher: regexp.MustCompile("/sched/latencies:seconds")},
24+
),
25+
),
26+
)
27+
}

0 commit comments

Comments
 (0)