3232import org .jooby .Env ;
3333import org .jooby .Jooby ;
3434import org .jooby .Router ;
35- import org .jooby .internal .metrics .HealthCheckRegistryProvider ;
35+ import org .jooby .internal .metrics .HealthCheckRegistryInitializer ;
3636import org .jooby .internal .metrics .MetricRegistryInitializer ;
3737
3838import com .codahale .metrics .Metric ;
@@ -160,19 +160,33 @@ static interface Bindings {
160160
161161 private Set <BiFunction <MetricRegistry , Config , Reporter >> reporters = new LinkedHashSet <>();
162162
163- private MetricRegistry registry ;
163+ private MetricRegistry metricRegistry ;
164+ private HealthCheckRegistry healthCheckRegistry ;
164165
165166 /**
166167 * Creates a new {@link Metric} module.
167168 *
168- * @param registry Use the given registry.
169+ * @param metricRegistry Use the given metricRegistry.
170+ * @param healthCheckRegistry Use the given healthCheckRegistry.
169171 * @param pattern A root pattern where to publish all the services. Default is: <code>/sys</code>.
170172 */
171- public Metrics (final MetricRegistry registry , final String pattern ) {
172- this .registry = requireNonNull (registry , "Registry is required." );
173+ public Metrics (final MetricRegistry metricRegistry ,
174+ final HealthCheckRegistry healthCheckRegistry , final String pattern ) {
175+ this .metricRegistry = requireNonNull (metricRegistry , "Metric registry is required." );
176+ this .healthCheckRegistry = requireNonNull (healthCheckRegistry , "Health check registry is required." );
173177 this .pattern = requireNonNull (pattern , "A pattern is required." );
174178 }
175179
180+ /**
181+ * Creates a new {@link Metric} module.
182+ *
183+ * @param metricRegistry Use the given metricRegistry.
184+ * @param pattern A root pattern where to publish all the services. Default is: <code>/sys</code>.
185+ */
186+ public Metrics (final MetricRegistry metricRegistry , final String pattern ) {
187+ this (metricRegistry , new HealthCheckRegistry (), pattern );
188+ }
189+
176190 /**
177191 * Creates a new {@link Metric} module.
178192 *
@@ -185,10 +199,19 @@ public Metrics(final String pattern) {
185199 /**
186200 * Creates a new {@link Metric} module. Services will be available at: <code>/sys</code>.
187201 *
188- * @param registry Use the given registry .
202+ * @param healthCheckRegistry Use the given healthCheckRegistry .
189203 */
190- public Metrics (final MetricRegistry registry ) {
191- this (registry , "/sys" );
204+ public Metrics (final HealthCheckRegistry healthCheckRegistry ) {
205+ this (new MetricRegistry (), healthCheckRegistry , "/sys" );
206+ }
207+
208+ /**
209+ * Creates a new {@link Metric} module. Services will be available at: <code>/sys</code>.
210+ *
211+ * @param metricRegistry Use the given metricRegistry.
212+ */
213+ public Metrics (final MetricRegistry metricRegistry ) {
214+ this (metricRegistry , "/sys" );
192215 }
193216
194217 /**
@@ -217,7 +240,7 @@ public Metrics request(final String method, final String pattern) {
217240 * @return This metrics module.
218241 */
219242 public Metrics request (final String pattern ) {
220- return request ("GET" , "*" );
243+ return request ("GET" , pattern );
221244 }
222245
223246 /**
@@ -358,17 +381,17 @@ public void configure(final Env env, final Config conf, final Binder binder) {
358381
359382 Multibinder <Reporter > reporters = Multibinder .newSetBinder (binder , Reporter .class );
360383
361- binder .bind (MetricRegistry .class ).toInstance (registry );
384+ binder .bind (MetricRegistry .class ).toInstance (metricRegistry );
362385
363- this .reporters .forEach (it -> reporters .addBinding ().toInstance (it .apply (registry , conf )));
386+ this .reporters .forEach (it -> reporters .addBinding ().toInstance (it .apply (metricRegistry , conf )));
364387
365388 binder .bind (MetricRegistryInitializer .class ).asEagerSingleton ();
366389
367390 env .onStop (app -> app .require (MetricRegistryInitializer .class ).close ());
368391
369- binder .bind (HealthCheckRegistry .class )
370- . toProvider ( HealthCheckRegistryProvider . class )
371- .asEagerSingleton ();
392+ binder .bind (HealthCheckRegistry .class ). toInstance ( healthCheckRegistry );
393+
394+ binder . bind ( HealthCheckRegistryInitializer . class ) .asEagerSingleton ();
372395
373396 bindings .forEach (it -> it .bind (binder , routes , conf ));
374397
0 commit comments