|
|
|
|
@ -16,8 +16,6 @@
@@ -16,8 +16,6 @@
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.actuate.autoconfigure.metrics; |
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
import io.micrometer.core.annotation.Timed; |
|
|
|
|
import io.micrometer.core.instrument.Clock; |
|
|
|
|
import io.micrometer.core.instrument.MeterRegistry; |
|
|
|
|
@ -42,6 +40,7 @@ import org.springframework.core.annotation.Order;
@@ -42,6 +40,7 @@ import org.springframework.core.annotation.Order;
|
|
|
|
|
* @author Jon Schneider |
|
|
|
|
* @author Stephane Nicoll |
|
|
|
|
* @author Moritz Halbritter |
|
|
|
|
* @author Michael Berry |
|
|
|
|
* @since 2.0.0 |
|
|
|
|
*/ |
|
|
|
|
@AutoConfiguration(before = CompositeMeterRegistryAutoConfiguration.class) |
|
|
|
|
@ -71,8 +70,8 @@ public class MetricsAutoConfiguration {
@@ -71,8 +70,8 @@ public class MetricsAutoConfiguration {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
|
MeterRegistryCloser meterRegistryCloser(ObjectProvider<MeterRegistry> meterRegistries) { |
|
|
|
|
return new MeterRegistryCloser(meterRegistries.orderedStream().toList()); |
|
|
|
|
MeterRegistryCloser meterRegistryCloser(ApplicationContext context) { |
|
|
|
|
return new MeterRegistryCloser(context); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -81,17 +80,22 @@ public class MetricsAutoConfiguration {
@@ -81,17 +80,22 @@ public class MetricsAutoConfiguration {
|
|
|
|
|
*/ |
|
|
|
|
static class MeterRegistryCloser implements ApplicationListener<ContextClosedEvent> { |
|
|
|
|
|
|
|
|
|
private final List<MeterRegistry> meterRegistries; |
|
|
|
|
private final ApplicationContext context; |
|
|
|
|
|
|
|
|
|
private final Iterable<MeterRegistry> meterRegistries; |
|
|
|
|
|
|
|
|
|
MeterRegistryCloser(List<MeterRegistry> meterRegistries) { |
|
|
|
|
this.meterRegistries = meterRegistries; |
|
|
|
|
MeterRegistryCloser(ApplicationContext context) { |
|
|
|
|
this.meterRegistries = context.getBeansOfType(MeterRegistry.class).values(); |
|
|
|
|
this.context = context; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onApplicationEvent(ContextClosedEvent event) { |
|
|
|
|
for (MeterRegistry meterRegistry : this.meterRegistries) { |
|
|
|
|
if (!meterRegistry.isClosed()) { |
|
|
|
|
meterRegistry.close(); |
|
|
|
|
if (this.context.equals(event.getApplicationContext())) { |
|
|
|
|
for (MeterRegistry meterRegistry : this.meterRegistries) { |
|
|
|
|
if (!meterRegistry.isClosed()) { |
|
|
|
|
meterRegistry.close(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|