File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed
extensions/micrometer/runtime/src/main/java/io/quarkus/micrometer/runtime Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -107,15 +107,21 @@ public void configureRegistries(MicrometerConfig config,
107107 }
108108 }
109109
110+ List <AutoCloseable > autoCloseables = new ArrayList <>();
111+
110112 // Base JVM Metrics
111113 if (config .checkBinderEnabledWithDefault (() -> config .binder .jvm )) {
112114 new ClassLoaderMetrics ().bindTo (Metrics .globalRegistry );
113- new JvmHeapPressureMetrics ().bindTo (Metrics .globalRegistry );
115+ JvmHeapPressureMetrics jvmHeapPressureMetrics = new JvmHeapPressureMetrics ();
116+ jvmHeapPressureMetrics .bindTo (Metrics .globalRegistry );
117+ autoCloseables .add (jvmHeapPressureMetrics );
114118 new JvmMemoryMetrics ().bindTo (Metrics .globalRegistry );
115119 new JvmThreadMetrics ().bindTo (Metrics .globalRegistry );
116120 new JVMInfoBinder ().bindTo (Metrics .globalRegistry );
117121 if (ImageMode .current () == ImageMode .JVM ) {
118- new JvmGcMetrics ().bindTo (Metrics .globalRegistry );
122+ JvmGcMetrics jvmGcMetrics = new JvmGcMetrics ();
123+ jvmGcMetrics .bindTo (Metrics .globalRegistry );
124+ autoCloseables .add (jvmGcMetrics );
119125 }
120126 }
121127
@@ -149,6 +155,14 @@ public void run() {
149155 meterRegistry .close ();
150156 Metrics .removeRegistry (meterRegistry );
151157 }
158+ // iterate over the auto-closeables and close them
159+ for (AutoCloseable autoCloseable : autoCloseables ) {
160+ try {
161+ autoCloseable .close ();
162+ } catch (Exception e ) {
163+ log .error ("Error closing" , e );
164+ }
165+ }
152166 }
153167 });
154168 }
You can’t perform that action at this time.
0 commit comments