diff --git a/prometheus/registry.go b/prometheus/registry.go index c6fd2f58b..ee31da5f7 100644 --- a/prometheus/registry.go +++ b/prometheus/registry.go @@ -52,16 +52,11 @@ const ( // consequences. Users who want to avoid global state altogether should not use // the convenience functions and act on custom instances instead. var ( - defaultRegistry = NewRegistry() + defaultRegistry = NewDefaultRegistry() DefaultRegisterer Registerer = defaultRegistry DefaultGatherer Gatherer = defaultRegistry ) -func init() { - MustRegister(NewProcessCollector(ProcessCollectorOpts{})) - MustRegister(NewGoCollector()) -} - // NewRegistry creates a new vanilla Registry without any Collectors // pre-registered. func NewRegistry() *Registry { @@ -72,6 +67,15 @@ func NewRegistry() *Registry { } } +func NewDefaultRegistry() *Registry { + reg := NewRegistry() + reg.MustRegister( + NewProcessCollector(ProcessCollectorOpts{}), + NewGoCollector(), + ) + return reg +} + // NewPedanticRegistry returns a registry that checks during collection if each // collected Metric is consistent with its reported Desc, and if the Desc has // actually been registered with the registry. Unchecked Collectors (those whose