|
|
@ -1,5 +1,5 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright 2012-2019 the original author or authors.
|
|
|
|
* Copyright 2012-2021 the original author or authors.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
@ -16,7 +16,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.actuate.autoconfigure.metrics;
|
|
|
|
package org.springframework.boot.actuate.autoconfigure.metrics;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
|
|
|
|
import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics;
|
|
|
|
import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics;
|
|
|
|
|
|
|
|
import io.micrometer.core.instrument.binder.jvm.DiskSpaceMetrics;
|
|
|
|
import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics;
|
|
|
|
import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics;
|
|
|
|
import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics;
|
|
|
|
import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics;
|
|
|
|
import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics;
|
|
|
|
import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics;
|
|
|
@ -24,7 +27,9 @@ import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun;
|
|
|
|
import org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun;
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
|
|
|
|
|
|
|
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
|
|
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
|
|
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
|
|
|
|
|
|
|
import org.springframework.boot.test.context.runner.ContextConsumer;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
|
|
|
|
|
|
@ -35,6 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author Andy Wilkinson
|
|
|
|
* @author Andy Wilkinson
|
|
|
|
* @author Stephane Nicoll
|
|
|
|
* @author Stephane Nicoll
|
|
|
|
|
|
|
|
* @author Chris Bono
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
class JvmMetricsAutoConfigurationTests {
|
|
|
|
class JvmMetricsAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
@ -43,41 +49,43 @@ class JvmMetricsAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void autoConfiguresJvmMetrics() {
|
|
|
|
void autoConfiguresJvmMetrics() {
|
|
|
|
this.contextRunner.run(
|
|
|
|
this.contextRunner.run(assertMetricsBeans());
|
|
|
|
(context) -> assertThat(context).hasSingleBean(JvmGcMetrics.class).hasSingleBean(JvmMemoryMetrics.class)
|
|
|
|
|
|
|
|
.hasSingleBean(JvmThreadMetrics.class).hasSingleBean(ClassLoaderMetrics.class));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void allowsCustomJvmGcMetricsToBeUsed() {
|
|
|
|
void allowsCustomJvmGcMetricsToBeUsed() {
|
|
|
|
this.contextRunner.withUserConfiguration(CustomJvmGcMetricsConfiguration.class)
|
|
|
|
this.contextRunner.withUserConfiguration(CustomJvmGcMetricsConfiguration.class)
|
|
|
|
.run((context) -> assertThat(context).hasSingleBean(JvmGcMetrics.class).hasBean("customJvmGcMetrics")
|
|
|
|
.run(assertMetricsBeans().andThen((context) -> assertThat(context).hasBean("customJvmGcMetrics")));
|
|
|
|
.hasSingleBean(JvmMemoryMetrics.class).hasSingleBean(JvmThreadMetrics.class)
|
|
|
|
|
|
|
|
.hasSingleBean(ClassLoaderMetrics.class));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void allowsCustomJvmMemoryMetricsToBeUsed() {
|
|
|
|
void allowsCustomJvmMemoryMetricsToBeUsed() {
|
|
|
|
this.contextRunner.withUserConfiguration(CustomJvmMemoryMetricsConfiguration.class)
|
|
|
|
this.contextRunner.withUserConfiguration(CustomJvmMemoryMetricsConfiguration.class)
|
|
|
|
.run((context) -> assertThat(context).hasSingleBean(JvmGcMetrics.class)
|
|
|
|
.run(assertMetricsBeans().andThen((context) -> assertThat(context).hasBean("customJvmMemoryMetrics")));
|
|
|
|
.hasSingleBean(JvmMemoryMetrics.class).hasBean("customJvmMemoryMetrics")
|
|
|
|
|
|
|
|
.hasSingleBean(JvmThreadMetrics.class).hasSingleBean(ClassLoaderMetrics.class));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void allowsCustomJvmThreadMetricsToBeUsed() {
|
|
|
|
void allowsCustomJvmThreadMetricsToBeUsed() {
|
|
|
|
this.contextRunner.withUserConfiguration(CustomJvmThreadMetricsConfiguration.class)
|
|
|
|
this.contextRunner.withUserConfiguration(CustomJvmThreadMetricsConfiguration.class)
|
|
|
|
.run((context) -> assertThat(context).hasSingleBean(JvmGcMetrics.class)
|
|
|
|
.run(assertMetricsBeans().andThen((context) -> assertThat(context).hasBean("customJvmThreadMetrics")));
|
|
|
|
.hasSingleBean(JvmMemoryMetrics.class).hasSingleBean(JvmThreadMetrics.class)
|
|
|
|
|
|
|
|
.hasSingleBean(ClassLoaderMetrics.class).hasBean("customJvmThreadMetrics"));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void allowsCustomClassLoaderMetricsToBeUsed() {
|
|
|
|
void allowsCustomClassLoaderMetricsToBeUsed() {
|
|
|
|
this.contextRunner.withUserConfiguration(CustomClassLoaderMetricsConfiguration.class)
|
|
|
|
this.contextRunner.withUserConfiguration(CustomClassLoaderMetricsConfiguration.class).run(
|
|
|
|
.run((context) -> assertThat(context).hasSingleBean(JvmGcMetrics.class)
|
|
|
|
assertMetricsBeans().andThen((context) -> assertThat(context).hasBean("customClassLoaderMetrics")));
|
|
|
|
.hasSingleBean(JvmMemoryMetrics.class).hasSingleBean(JvmThreadMetrics.class)
|
|
|
|
}
|
|
|
|
.hasSingleBean(ClassLoaderMetrics.class).hasBean("customClassLoaderMetrics"));
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void allowsCustomDiskSpaceMetricsToBeUsed() {
|
|
|
|
|
|
|
|
this.contextRunner.withUserConfiguration(CustomDiskSpaceMetricsConfiguration.class)
|
|
|
|
|
|
|
|
.run(assertMetricsBeans().andThen((context) -> assertThat(context).hasBean("customDiskSpaceMetrics")));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ContextConsumer<AssertableApplicationContext> assertMetricsBeans() {
|
|
|
|
|
|
|
|
return (context) -> assertThat(context).hasSingleBean(JvmGcMetrics.class).hasSingleBean(JvmMemoryMetrics.class)
|
|
|
|
|
|
|
|
.hasSingleBean(JvmThreadMetrics.class).hasSingleBean(ClassLoaderMetrics.class)
|
|
|
|
|
|
|
|
.hasSingleBean(DiskSpaceMetrics.class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
@ -120,4 +128,14 @@ class JvmMetricsAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
|
|
|
|
static class CustomDiskSpaceMetricsConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
|
|
|
DiskSpaceMetrics customDiskSpaceMetrics() {
|
|
|
|
|
|
|
|
return new DiskSpaceMetrics(new File(System.getProperty("user.dir")));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|