Skip to content

Commit 3f15eda

Browse files
dongjiang1989k8s-infra-cherrypick-robot
authored andcommitted
add GoCollector and rocessCollector
Signed-off-by: dongjiang <[email protected]>
1 parent 626b2f3 commit 3f15eda

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

pkg/metrics/registry.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ limitations under the License.
1616

1717
package metrics
1818

19-
import "github.com/prometheus/client_golang/prometheus"
19+
import (
20+
"regexp"
21+
22+
"github.com/prometheus/client_golang/prometheus"
23+
"github.com/prometheus/client_golang/prometheus/collectors"
24+
)
2025

2126
// RegistererGatherer combines both parts of the API of a Prometheus
2227
// registry, both the Registerer and the Gatherer interfaces.
@@ -27,4 +32,22 @@ type RegistererGatherer interface {
2732

2833
// Registry is a prometheus registry for storing metrics within the
2934
// controller-runtime.
30-
var Registry RegistererGatherer = prometheus.NewRegistry()
35+
var Registry RegistererGatherer = NewRegistry()
36+
37+
func NewRegistry() *prometheus.Registry {
38+
r := prometheus.NewRegistry()
39+
40+
// default registers
41+
r.MustRegister(
42+
collectors.NewGoCollector(
43+
collectors.WithGoCollectorRuntimeMetrics(
44+
collectors.MetricsGC,
45+
collectors.MetricsScheduler,
46+
collectors.MetricsMemory,
47+
collectors.GoRuntimeMetricsRule{Matcher: regexp.MustCompile(`^/sync/.*`)},
48+
),
49+
),
50+
collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
51+
)
52+
return r
53+
}

0 commit comments

Comments
 (0)