diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxProperties.java index bf8fbc48815..d3ff4f9885d 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxProperties.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxProperties.java @@ -30,11 +30,24 @@ import org.springframework.boot.context.properties.ConfigurationProperties; @ConfigurationProperties(prefix = "management.metrics.export.jmx") public class JmxProperties { + /** + * Metrics JMX domain name. + */ + private String domain = "metrics"; + /** * Step size (i.e. reporting frequency) to use. */ private Duration step = Duration.ofMinutes(1); + public String getDomain() { + return this.domain; + } + + public void setDomain(String domain) { + this.domain = domain; + } + public Duration getStep() { return this.step; } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesConfigAdapter.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesConfigAdapter.java index b42a3f6761b..ba6e03b1d81 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesConfigAdapter.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesConfigAdapter.java @@ -26,6 +26,7 @@ import org.springframework.boot.actuate.autoconfigure.metrics.export.properties. * Adapter to convert {@link JmxProperties} to a {@link JmxConfig}. * * @author Jon Schneider + * @author Stephane Nicoll */ class JmxPropertiesConfigAdapter extends PropertiesConfigAdapter implements JmxConfig { @@ -39,6 +40,11 @@ class JmxPropertiesConfigAdapter extends PropertiesConfigAdapter return null; } + @Override + public String domain() { + return get(JmxProperties::getDomain, JmxConfig.super::domain); + } + @Override public Duration step() { return get(JmxProperties::getStep, JmxConfig.super::step); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesTests.java index 0fc9a32e276..b3a483c2b81 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesTests.java @@ -32,6 +32,7 @@ public class JmxPropertiesTests { public void defaultValuesAreConsistent() { JmxProperties properties = new JmxProperties(); JmxConfig config = JmxConfig.DEFAULT; + assertThat(properties.getDomain()).isEqualTo(config.domain()); assertThat(properties.getStep()).isEqualTo(config.step()); } diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index 702fd07aae3..2ea353067ee 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -1375,6 +1375,7 @@ content into your application. Rather, pick only the properties that you need. management.metrics.export.influx.step=1m # Step size (i.e. reporting frequency) to use. management.metrics.export.influx.uri=http://localhost:8086 # URI of the Influx server. management.metrics.export.influx.user-name= # Login user of the Influx server. + management.metrics.export.jmx.domain=metrics # Metrics JMX domain name. management.metrics.export.jmx.enabled=true # Whether exporting of metrics to JMX is enabled. management.metrics.export.jmx.step=1m # Step size (i.e. reporting frequency) to use. management.metrics.export.newrelic.account-id= # New Relic account ID. diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc index a6fb11b7037..79eadc42571 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc @@ -1470,10 +1470,17 @@ server] to use can be provided using: ==== JMX Micrometer provides a hierarchical mapping to {micrometer-registry-documentation}/jmx[JMX], primarily as a cheap and portable way to -view metrics locally. Micrometer provides a default `HierarchicalNameMapper` that governs -how a dimensional meter id is -{micrometer-registry-documentation}/jmx#_hierarchical_name_mapping[mapped to flat -hierarchical names]. +view metrics locally.By default, metrics are exported to the `metrics` JMX domain. The +domain to use can be provided provided using: + +[source,properties,indent=0] +---- + management.metrics.export.jmx.domain=com.example.app.metrics +---- + +Micrometer provides a default `HierarchicalNameMapper` that governs how a dimensional +meter id is {micrometer-registry-documentation}/jmx#_hierarchical_name_mapping[mapped to +flat hierarchical names]. TIP: To take control over this behaviour, define your `JmxMeterRegistry` and supply your own `HierarchicalNameMapper`. An auto-configured `JmxConfig` and `Clock` beans are