Skip to content

Commit b4f8361

Browse files
committed
Make JMX metrics domain configurable
Closes gh-13356
1 parent 571c50e commit b4f8361

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxProperties.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,24 @@
3030
@ConfigurationProperties(prefix = "management.metrics.export.jmx")
3131
public class JmxProperties {
3232

33+
/**
34+
* Metrics JMX domain name.
35+
*/
36+
private String domain = "metrics";
37+
3338
/**
3439
* Step size (i.e. reporting frequency) to use.
3540
*/
3641
private Duration step = Duration.ofMinutes(1);
3742

43+
public String getDomain() {
44+
return this.domain;
45+
}
46+
47+
public void setDomain(String domain) {
48+
this.domain = domain;
49+
}
50+
3851
public Duration getStep() {
3952
return this.step;
4053
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesConfigAdapter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* Adapter to convert {@link JmxProperties} to a {@link JmxConfig}.
2727
*
2828
* @author Jon Schneider
29+
* @author Stephane Nicoll
2930
*/
3031
class JmxPropertiesConfigAdapter extends PropertiesConfigAdapter<JmxProperties>
3132
implements JmxConfig {
@@ -39,6 +40,11 @@ public String get(String key) {
3940
return null;
4041
}
4142

43+
@Override
44+
public String domain() {
45+
return get(JmxProperties::getDomain, JmxConfig.super::domain);
46+
}
47+
4248
@Override
4349
public Duration step() {
4450
return get(JmxProperties::getStep, JmxConfig.super::step);

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class JmxPropertiesTests {
3232
public void defaultValuesAreConsistent() {
3333
JmxProperties properties = new JmxProperties();
3434
JmxConfig config = JmxConfig.DEFAULT;
35+
assertThat(properties.getDomain()).isEqualTo(config.domain());
3536
assertThat(properties.getStep()).isEqualTo(config.step());
3637
}
3738

spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,7 @@ content into your application. Rather, pick only the properties that you need.
13751375
management.metrics.export.influx.step=1m # Step size (i.e. reporting frequency) to use.
13761376
management.metrics.export.influx.uri=http://localhost:8086 # URI of the Influx server.
13771377
management.metrics.export.influx.user-name= # Login user of the Influx server.
1378+
management.metrics.export.jmx.domain=metrics # Metrics JMX domain name.
13781379
management.metrics.export.jmx.enabled=true # Whether exporting of metrics to JMX is enabled.
13791380
management.metrics.export.jmx.step=1m # Step size (i.e. reporting frequency) to use.
13801381
management.metrics.export.newrelic.account-id= # New Relic account ID.

spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,10 +1470,17 @@ server] to use can be provided using:
14701470
==== JMX
14711471
Micrometer provides a hierarchical mapping to
14721472
{micrometer-registry-documentation}/jmx[JMX], primarily as a cheap and portable way to
1473-
view metrics locally. Micrometer provides a default `HierarchicalNameMapper` that governs
1474-
how a dimensional meter id is
1475-
{micrometer-registry-documentation}/jmx#_hierarchical_name_mapping[mapped to flat
1476-
hierarchical names].
1473+
view metrics locally.By default, metrics are exported to the `metrics` JMX domain. The
1474+
domain to use can be provided provided using:
1475+
1476+
[source,properties,indent=0]
1477+
----
1478+
management.metrics.export.jmx.domain=com.example.app.metrics
1479+
----
1480+
1481+
Micrometer provides a default `HierarchicalNameMapper` that governs how a dimensional
1482+
meter id is {micrometer-registry-documentation}/jmx#_hierarchical_name_mapping[mapped to
1483+
flat hierarchical names].
14771484

14781485
TIP: To take control over this behaviour, define your `JmxMeterRegistry` and supply your
14791486
own `HierarchicalNameMapper`. An auto-configured `JmxConfig` and `Clock` beans are

0 commit comments

Comments
 (0)