Skip to content

Commit 85fc176

Browse files
committed
move to internal/controller/metrics
Signed-off-by: dongjiang <[email protected]>
1 parent 3bec486 commit 85fc176

File tree

2 files changed

+12
-26
lines changed

2 files changed

+12
-26
lines changed

pkg/internal/controller/metrics/metrics.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package metrics
1818

1919
import (
20+
"regexp"
21+
2022
"github.com/prometheus/client_golang/prometheus"
2123
"github.com/prometheus/client_golang/prometheus/collectors"
2224
"sigs.k8s.io/controller-runtime/pkg/metrics"
@@ -89,6 +91,13 @@ func init() {
8991
// expose process metrics like CPU, Memory, file descriptor usage etc.
9092
collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
9193
// expose Go runtime metrics like GC stats, memory stats etc.
92-
collectors.NewGoCollector(),
94+
collectors.NewGoCollector(
95+
collectors.WithGoCollectorRuntimeMetrics(
96+
collectors.MetricsGC,
97+
collectors.MetricsScheduler,
98+
collectors.MetricsMemory,
99+
collectors.GoRuntimeMetricsRule{Matcher: regexp.MustCompile(`^/sync/.*`)},
100+
),
101+
),
93102
)
94103
}

pkg/metrics/registry.go

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

1717
package metrics
1818

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

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

3328
// Registry is a prometheus registry for storing metrics within the
3429
// controller-runtime.
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-
}
30+
var Registry RegistererGatherer = prometheus.NewRegistry()

0 commit comments

Comments
 (0)