Make JMX metrics domain configurable

Closes gh-13356
pull/13388/head
Stephane Nicoll 7 years ago
parent 571c50e43f
commit b4f8361989

@ -30,11 +30,24 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "management.metrics.export.jmx") @ConfigurationProperties(prefix = "management.metrics.export.jmx")
public class JmxProperties { public class JmxProperties {
/**
* Metrics JMX domain name.
*/
private String domain = "metrics";
/** /**
* Step size (i.e. reporting frequency) to use. * Step size (i.e. reporting frequency) to use.
*/ */
private Duration step = Duration.ofMinutes(1); private Duration step = Duration.ofMinutes(1);
public String getDomain() {
return this.domain;
}
public void setDomain(String domain) {
this.domain = domain;
}
public Duration getStep() { public Duration getStep() {
return this.step; return this.step;
} }

@ -26,6 +26,7 @@ import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.
* Adapter to convert {@link JmxProperties} to a {@link JmxConfig}. * Adapter to convert {@link JmxProperties} to a {@link JmxConfig}.
* *
* @author Jon Schneider * @author Jon Schneider
* @author Stephane Nicoll
*/ */
class JmxPropertiesConfigAdapter extends PropertiesConfigAdapter<JmxProperties> class JmxPropertiesConfigAdapter extends PropertiesConfigAdapter<JmxProperties>
implements JmxConfig { implements JmxConfig {
@ -39,6 +40,11 @@ class JmxPropertiesConfigAdapter extends PropertiesConfigAdapter<JmxProperties>
return null; return null;
} }
@Override
public String domain() {
return get(JmxProperties::getDomain, JmxConfig.super::domain);
}
@Override @Override
public Duration step() { public Duration step() {
return get(JmxProperties::getStep, JmxConfig.super::step); return get(JmxProperties::getStep, JmxConfig.super::step);

@ -32,6 +32,7 @@ public class JmxPropertiesTests {
public void defaultValuesAreConsistent() { public void defaultValuesAreConsistent() {
JmxProperties properties = new JmxProperties(); JmxProperties properties = new JmxProperties();
JmxConfig config = JmxConfig.DEFAULT; JmxConfig config = JmxConfig.DEFAULT;
assertThat(properties.getDomain()).isEqualTo(config.domain());
assertThat(properties.getStep()).isEqualTo(config.step()); assertThat(properties.getStep()).isEqualTo(config.step());
} }

@ -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.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.uri=http://localhost:8086 # URI of the Influx server.
management.metrics.export.influx.user-name= # Login user 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.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.jmx.step=1m # Step size (i.e. reporting frequency) to use.
management.metrics.export.newrelic.account-id= # New Relic account ID. management.metrics.export.newrelic.account-id= # New Relic account ID.

@ -1470,10 +1470,17 @@ server] to use can be provided using:
==== JMX ==== JMX
Micrometer provides a hierarchical mapping to Micrometer provides a hierarchical mapping to
{micrometer-registry-documentation}/jmx[JMX], primarily as a cheap and portable way to {micrometer-registry-documentation}/jmx[JMX], primarily as a cheap and portable way to
view metrics locally. Micrometer provides a default `HierarchicalNameMapper` that governs view metrics locally.By default, metrics are exported to the `metrics` JMX domain. The
how a dimensional meter id is domain to use can be provided provided using:
{micrometer-registry-documentation}/jmx#_hierarchical_name_mapping[mapped to flat
hierarchical names]. [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 TIP: To take control over this behaviour, define your `JmxMeterRegistry` and supply your
own `HierarchicalNameMapper`. An auto-configured `JmxConfig` and `Clock` beans are own `HierarchicalNameMapper`. An auto-configured `JmxConfig` and `Clock` beans are

Loading…
Cancel
Save