Merge pull request #12017 from jkschneider:micrometer-config

* pr/12017:
  Polish "Remove unnecessary config options for metrics"
  Remove unnecessary config options for JDBC, Rabbit, and Cache metrics
pull/12022/merge
Stephane Nicoll 7 years ago
commit fd13202b69

@ -32,8 +32,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration; import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@ -49,20 +47,14 @@ import org.springframework.util.StringUtils;
SimpleMetricsExportAutoConfiguration.class }) SimpleMetricsExportAutoConfiguration.class })
@ConditionalOnClass({ ConnectionFactory.class, AbstractConnectionFactory.class }) @ConditionalOnClass({ ConnectionFactory.class, AbstractConnectionFactory.class })
@ConditionalOnBean({ AbstractConnectionFactory.class, MeterRegistry.class }) @ConditionalOnBean({ AbstractConnectionFactory.class, MeterRegistry.class })
@ConditionalOnProperty(value = "management.metrics.rabbitmq.instrument", matchIfMissing = true)
@EnableConfigurationProperties(RabbitMetricsProperties.class)
public class RabbitMetricsAutoConfiguration { public class RabbitMetricsAutoConfiguration {
private static final String CONNECTION_FACTORY_SUFFIX = "connectionFactory"; private static final String CONNECTION_FACTORY_SUFFIX = "connectionFactory";
private final MeterRegistry registry; private final MeterRegistry registry;
private final String metricName; public RabbitMetricsAutoConfiguration(MeterRegistry registry) {
public RabbitMetricsAutoConfiguration(MeterRegistry registry,
RabbitMetricsProperties rabbitMetricsProperties) {
this.registry = registry; this.registry = registry;
this.metricName = rabbitMetricsProperties.getMetricName();
} }
@Autowired @Autowired
@ -76,7 +68,7 @@ public class RabbitMetricsAutoConfiguration {
ConnectionFactory rabbitConnectionFactory = connectionFactory ConnectionFactory rabbitConnectionFactory = connectionFactory
.getRabbitConnectionFactory(); .getRabbitConnectionFactory();
String connectionFactoryName = getConnectionFactoryName(beanName); String connectionFactoryName = getConnectionFactoryName(beanName);
new RabbitMetrics(rabbitConnectionFactory, this.metricName, new RabbitMetrics(rabbitConnectionFactory,
Tags.of("name", connectionFactoryName)).bindTo(this.registry); Tags.of("name", connectionFactoryName)).bindTo(this.registry);
} }

@ -1,43 +0,0 @@
/*
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.autoconfigure.metrics.amqp;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Configuration properties for RabbitMQ-based metrics.
*
* @author Stephane Nicoll
* @since 2.0.0
*/
@ConfigurationProperties("management.metrics.rabbitmq")
public class RabbitMetricsProperties {
/**
* Name of the metric for RabbitMQ usage.
*/
private String metricName = "rabbitmq";
public String getMetricName() {
return this.metricName;
}
public void setMetricName(String metricName) {
this.metricName = metricName;
}
}

@ -21,7 +21,6 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration; import org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cache.Cache; import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager; import org.springframework.cache.CacheManager;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -37,7 +36,6 @@ import org.springframework.context.annotation.Import;
@Configuration @Configuration
@AutoConfigureAfter({ MetricsAutoConfiguration.class, CacheAutoConfiguration.class }) @AutoConfigureAfter({ MetricsAutoConfiguration.class, CacheAutoConfiguration.class })
@ConditionalOnBean(CacheManager.class) @ConditionalOnBean(CacheManager.class)
@ConditionalOnProperty(value = "management.metrics.cache.instrument", matchIfMissing = true)
@Import({ CacheMeterBinderProvidersConfiguration.class, @Import({ CacheMeterBinderProvidersConfiguration.class,
CacheMetricsRegistrarConfiguration.class }) CacheMetricsRegistrarConfiguration.class })
public class CacheMetricsAutoConfiguration { public class CacheMetricsAutoConfiguration {

@ -17,12 +17,12 @@
package org.springframework.boot.actuate.autoconfigure.metrics.jdbc; package org.springframework.boot.actuate.autoconfigure.metrics.jdbc;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.Map; import java.util.Map;
import javax.sql.DataSource; import javax.sql.DataSource;
import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tags;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
@ -31,9 +31,7 @@ import org.springframework.boot.actuate.metrics.jdbc.DataSourcePoolMetrics;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.jdbc.metadata.DataSourcePoolMetadataProvider; import org.springframework.boot.jdbc.metadata.DataSourcePoolMetadataProvider;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@ -50,8 +48,6 @@ import org.springframework.util.StringUtils;
SimpleMetricsExportAutoConfiguration.class }) SimpleMetricsExportAutoConfiguration.class })
@ConditionalOnBean({ DataSource.class, DataSourcePoolMetadataProvider.class, @ConditionalOnBean({ DataSource.class, DataSourcePoolMetadataProvider.class,
MeterRegistry.class }) MeterRegistry.class })
@ConditionalOnProperty(value = "management.metrics.jdbc.instrument", matchIfMissing = true)
@EnableConfigurationProperties(JdbcMetricsProperties.class)
public class DataSourcePoolMetricsAutoConfiguration { public class DataSourcePoolMetricsAutoConfiguration {
private static final String DATASOURCE_SUFFIX = "dataSource"; private static final String DATASOURCE_SUFFIX = "dataSource";
@ -60,14 +56,10 @@ public class DataSourcePoolMetricsAutoConfiguration {
private final Collection<DataSourcePoolMetadataProvider> metadataProviders; private final Collection<DataSourcePoolMetadataProvider> metadataProviders;
private final String metricName;
public DataSourcePoolMetricsAutoConfiguration(MeterRegistry registry, public DataSourcePoolMetricsAutoConfiguration(MeterRegistry registry,
Collection<DataSourcePoolMetadataProvider> metadataProviders, Collection<DataSourcePoolMetadataProvider> metadataProviders) {
JdbcMetricsProperties jdbcMetricsProperties) {
this.registry = registry; this.registry = registry;
this.metadataProviders = metadataProviders; this.metadataProviders = metadataProviders;
this.metricName = jdbcMetricsProperties.getMetricName();
} }
@Autowired @Autowired
@ -77,8 +69,8 @@ public class DataSourcePoolMetricsAutoConfiguration {
private void bindDataSourceToRegistry(String beanName, DataSource dataSource) { private void bindDataSourceToRegistry(String beanName, DataSource dataSource) {
String dataSourceName = getDataSourceName(beanName); String dataSourceName = getDataSourceName(beanName);
new DataSourcePoolMetrics(dataSource, this.metadataProviders, this.metricName, new DataSourcePoolMetrics(dataSource, this.metadataProviders,
Tags.of("name", dataSourceName)).bindTo(this.registry); dataSourceName, Collections.emptyList()).bindTo(this.registry);
} }
/** /**

@ -1,43 +0,0 @@
/*
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.autoconfigure.metrics.jdbc;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Configuration properties for JDBC-based metrics.
*
* @author Stephane Nicoll
* @since 2.0.0
*/
@ConfigurationProperties("management.metrics.jdbc")
public class JdbcMetricsProperties {
/**
* Name of the metric for data source usage.
*/
private String metricName = "data.source";
public String getMetricName() {
return this.metricName;
}
public void setMetricName(String metricName) {
this.metricName = metricName;
}
}

@ -209,24 +209,6 @@
"description": "Whether to enable uptime metrics.", "description": "Whether to enable uptime metrics.",
"defaultValue": true "defaultValue": true
}, },
{
"name": "management.metrics.cache.instrument",
"type": "java.lang.Boolean",
"description": "Instrument all available caches.",
"defaultValue": true
},
{
"name": "management.metrics.jdbc.instrument",
"type": "java.lang.Boolean",
"description": "Instrument all available data sources.",
"defaultValue": true
},
{
"name": "management.metrics.rabbitmq.instrument",
"type": "java.lang.Boolean",
"description": "Instrument all available connection factories.",
"defaultValue": true
},
{ {
"name": "management.trace.http.enabled", "name": "management.trace.http.enabled",
"type": "java.lang.Boolean", "type": "java.lang.Boolean",

@ -45,21 +45,10 @@ public class RabbitMetricsAutoConfigurationTests {
}); });
} }
@Test
public void autoConfiguredConnectionFactoryWithCustomMetricName() {
this.contextRunner
.withPropertyValues("management.metrics.rabbitmq.metric-name=custom.name")
.run((context) -> {
MeterRegistry registry = context.getBean(MeterRegistry.class);
registry.get("custom.name.connections").meter();
assertThat(registry.find("rabbitmq.connections").meter()).isNull();
});
}
@Test @Test
public void rabbitmqNativeConnectionFactoryInstrumentationCanBeDisabled() { public void rabbitmqNativeConnectionFactoryInstrumentationCanBeDisabled() {
this.contextRunner this.contextRunner
.withPropertyValues("management.metrics.rabbitmq.instrument=false") .withPropertyValues("management.metrics.enable.rabbitmq=false")
.run((context) -> { .run((context) -> {
MeterRegistry registry = context.getBean(MeterRegistry.class); MeterRegistry registry = context.getBean(MeterRegistry.class);
assertThat(registry.find("rabbitmq.connections").meter()).isNull(); assertThat(registry.find("rabbitmq.connections").meter()).isNull();

@ -66,7 +66,7 @@ public class CacheMetricsAutoConfigurationTests {
@Test @Test
public void cacheInstrumentationCanBeDisabled() { public void cacheInstrumentationCanBeDisabled() {
this.contextRunner this.contextRunner
.withPropertyValues("management.metrics.cache.instrument=false", .withPropertyValues("management.metrics.enable.cache=false",
"spring.cache.type=caffeine", "spring.cache.cache-names=cache1") "spring.cache.type=caffeine", "spring.cache.cache-names=cache1")
.run((context) -> { .run((context) -> {
MeterRegistry registry = context.getBean(MeterRegistry.class); MeterRegistry registry = context.getBean(MeterRegistry.class);

@ -24,6 +24,7 @@ import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry; import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import org.junit.Test; import org.junit.Test;
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.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.boot.jdbc.DataSourceBuilder;
@ -42,6 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class DataSourcePoolMetricsAutoConfigurationTests { public class DataSourcePoolMetricsAutoConfigurationTests {
private ApplicationContextRunner contextRunner = new ApplicationContextRunner() private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.with(MetricsRun.simple())
.withConfiguration( .withConfiguration(
AutoConfigurations.of(DataSourcePoolMetricsAutoConfiguration.class)) AutoConfigurations.of(DataSourcePoolMetricsAutoConfiguration.class))
.withUserConfiguration(BaseConfiguration.class); .withUserConfiguration(BaseConfiguration.class);
@ -55,22 +57,7 @@ public class DataSourcePoolMetricsAutoConfigurationTests {
.run((context) -> { .run((context) -> {
context.getBean(DataSource.class).getConnection().getMetaData(); context.getBean(DataSource.class).getConnection().getMetaData();
MeterRegistry registry = context.getBean(MeterRegistry.class); MeterRegistry registry = context.getBean(MeterRegistry.class);
registry.get("data.source.max.connections").tags("name", "dataSource") registry.get("jdbc.max.connections").tags("name", "dataSource")
.meter();
});
}
@Test
public void autoConfiguredDataSourceWithCustomMetricName() {
this.contextRunner
.withConfiguration(
AutoConfigurations.of(DataSourceAutoConfiguration.class))
.withPropertyValues("spring.datasource.generate-unique-name=true",
"management.metrics.jdbc.metric-name=custom.name")
.run((context) -> {
context.getBean(DataSource.class).getConnection().getMetaData();
MeterRegistry registry = context.getBean(MeterRegistry.class);
registry.get("custom.name.max.connections").tags("name", "dataSource")
.meter(); .meter();
}); });
} }
@ -81,11 +68,11 @@ public class DataSourcePoolMetricsAutoConfigurationTests {
.withConfiguration( .withConfiguration(
AutoConfigurations.of(DataSourceAutoConfiguration.class)) AutoConfigurations.of(DataSourceAutoConfiguration.class))
.withPropertyValues("spring.datasource.generate-unique-name=true", .withPropertyValues("spring.datasource.generate-unique-name=true",
"management.metrics.jdbc.instrument=false") "management.metrics.enable.jdbc=false")
.run((context) -> { .run((context) -> {
context.getBean(DataSource.class).getConnection().getMetaData(); context.getBean(DataSource.class).getConnection().getMetaData();
MeterRegistry registry = context.getBean(MeterRegistry.class); MeterRegistry registry = context.getBean(MeterRegistry.class);
assertThat(registry.find("data.source.max.connections") assertThat(registry.find("jdbc.max.connections")
.tags("name", "dataSource").meter()).isNull(); .tags("name", "dataSource").meter()).isNull();
}); });
} }
@ -101,9 +88,9 @@ public class DataSourcePoolMetricsAutoConfigurationTests {
context.getBean("secondOne", DataSource.class).getConnection() context.getBean("secondOne", DataSource.class).getConnection()
.getMetaData(); .getMetaData();
MeterRegistry registry = context.getBean(MeterRegistry.class); MeterRegistry registry = context.getBean(MeterRegistry.class);
registry.get("data.source.max.connections").tags("name", "first") registry.get("jdbc.max.connections").tags("name", "first")
.meter(); .meter();
registry.get("data.source.max.connections").tags("name", "secondOne") registry.get("jdbc.max.connections").tags("name", "secondOne")
.meter(); .meter();
}); });
} }

@ -37,29 +37,23 @@ public class RabbitMetrics implements MeterBinder {
private final Iterable<Tag> tags; private final Iterable<Tag> tags;
private final String name;
private final ConnectionFactory connectionFactory; private final ConnectionFactory connectionFactory;
/** /**
* Create a new meter binder recording the specified {@link ConnectionFactory}. * Create a new meter binder recording the specified {@link ConnectionFactory}.
* @param connectionFactory the {@link ConnectionFactory} to instrument * @param connectionFactory the {@link ConnectionFactory} to instrument
* @param name the name prefix of the metrics
* @param tags tags to apply to all recorded metrics * @param tags tags to apply to all recorded metrics
*/ */
public RabbitMetrics(ConnectionFactory connectionFactory, String name, public RabbitMetrics(ConnectionFactory connectionFactory, Iterable<Tag> tags) {
Iterable<Tag> tags) {
Assert.notNull(connectionFactory, "ConnectionFactory must not be null"); Assert.notNull(connectionFactory, "ConnectionFactory must not be null");
Assert.notNull(name, "Name must not be null");
this.connectionFactory = connectionFactory; this.connectionFactory = connectionFactory;
this.name = name;
this.tags = (tags != null ? tags : Collections.emptyList()); this.tags = (tags != null ? tags : Collections.emptyList());
} }
@Override @Override
public void bindTo(MeterRegistry registry) { public void bindTo(MeterRegistry registry) {
this.connectionFactory.setMetricsCollector( this.connectionFactory.setMetricsCollector(
new MicrometerMetricsCollector(registry, this.name, this.tags)); new MicrometerMetricsCollector(registry, "rabbitmq", this.tags));
} }
} }

@ -24,6 +24,7 @@ import javax.sql.DataSource;
import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tag; import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.Tags;
import io.micrometer.core.instrument.binder.MeterBinder; import io.micrometer.core.instrument.binder.MeterBinder;
import org.springframework.boot.jdbc.metadata.CompositeDataSourcePoolMetadataProvider; import org.springframework.boot.jdbc.metadata.CompositeDataSourcePoolMetadataProvider;
@ -45,15 +46,13 @@ public class DataSourcePoolMetrics implements MeterBinder {
private final CachingDataSourcePoolMetadataProvider metadataProvider; private final CachingDataSourcePoolMetadataProvider metadataProvider;
private final String name;
private final Iterable<Tag> tags; private final Iterable<Tag> tags;
public DataSourcePoolMetrics(DataSource dataSource, public DataSourcePoolMetrics(DataSource dataSource,
Collection<DataSourcePoolMetadataProvider> metadataProviders, String name, Collection<DataSourcePoolMetadataProvider> metadataProviders, String dataSourceName,
Iterable<Tag> tags) { Iterable<Tag> tags) {
this(dataSource, new CompositeDataSourcePoolMetadataProvider(metadataProviders), this(dataSource, new CompositeDataSourcePoolMetadataProvider(metadataProviders),
name, tags); dataSourceName, tags);
} }
public DataSourcePoolMetrics(DataSource dataSource, public DataSourcePoolMetrics(DataSource dataSource,
@ -64,8 +63,7 @@ public class DataSourcePoolMetrics implements MeterBinder {
this.dataSource = dataSource; this.dataSource = dataSource;
this.metadataProvider = new CachingDataSourcePoolMetadataProvider( this.metadataProvider = new CachingDataSourcePoolMetadataProvider(
metadataProvider); metadataProvider);
this.name = name; this.tags = Tags.concat(tags, "name", name);
this.tags = tags;
} }
@Override @Override
@ -77,15 +75,15 @@ public class DataSourcePoolMetrics implements MeterBinder {
} }
} }
private <N extends Number> void bindPoolMetadata(MeterRegistry registry, String name, private <N extends Number> void bindPoolMetadata(MeterRegistry registry, String metricName,
Function<DataSourcePoolMetadata, N> function) { Function<DataSourcePoolMetadata, N> function) {
bindDataSource(registry, name, this.metadataProvider.getValueFunction(function)); bindDataSource(registry, metricName, this.metadataProvider.getValueFunction(function));
} }
private <N extends Number> void bindDataSource(MeterRegistry registry, String name, private <N extends Number> void bindDataSource(MeterRegistry registry,
Function<DataSource, N> function) { String metricName, Function<DataSource, N> function) {
if (function.apply(this.dataSource) != null) { if (function.apply(this.dataSource) != null) {
registry.gauge(this.name + "." + name + ".connections", this.tags, registry.gauge("jdbc." + metricName + ".connections", this.tags,
this.dataSource, (m) -> function.apply(m).doubleValue()); this.dataSource, (m) -> function.apply(m).doubleValue());
} }
} }

@ -35,19 +35,20 @@ public class RabbitMetricsTests {
public void connectionFactoryIsInstrumented() { public void connectionFactoryIsInstrumented() {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class); ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
SimpleMeterRegistry registry = new SimpleMeterRegistry(); SimpleMeterRegistry registry = new SimpleMeterRegistry();
new RabbitMetrics(connectionFactory, "rabbit", null).bindTo(registry); new RabbitMetrics(connectionFactory, null).bindTo(registry);
registry.get("rabbit.connections"); registry.get("rabbitmq.connections");
} }
@Test @Test
public void connectionFactoryWithTagsIsInstrumented() { public void connectionFactoryWithTagsIsInstrumented() {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class); ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
SimpleMeterRegistry registry = new SimpleMeterRegistry(); SimpleMeterRegistry registry = new SimpleMeterRegistry();
new RabbitMetrics(connectionFactory, "test", Tags.of("env", "prod")) new RabbitMetrics(connectionFactory, Tags.of("env", "prod"))
.bindTo(registry); .bindTo(registry);
assertThat(registry.get("test.connections").tags("env", "prod").meter()) assertThat(registry.get("rabbitmq.connections").tags("env", "prod").meter())
.isNotNull(); .isNotNull();
assertThat(registry.find("test.connections").tags("env", "dev").meter()).isNull(); assertThat(registry.find("rabbitmq.connections").tags("env", "dev").meter())
.isNull();
} }
} }

@ -51,7 +51,7 @@ public class DataSourcePoolMetricsTests {
.run((context) -> { .run((context) -> {
context.getBean(DataSource.class).getConnection().getMetaData(); context.getBean(DataSource.class).getConnection().getMetaData();
context.getBean(MeterRegistry.class) context.getBean(MeterRegistry.class)
.get("data.source.max.connections").meter(); .get("jdbc.max.connections").meter();
}); });
} }

@ -1300,7 +1300,6 @@ content into your application. Rather, pick only the properties that you need.
management.metrics.binders.logback.enabled=true # Whether to enable Logback metrics. management.metrics.binders.logback.enabled=true # Whether to enable Logback metrics.
management.metrics.binders.processor.enabled=true # Whether to enable processor metrics. management.metrics.binders.processor.enabled=true # Whether to enable processor metrics.
management.metrics.binders.uptime.enabled=true # Whether to enable uptime metrics. management.metrics.binders.uptime.enabled=true # Whether to enable uptime metrics.
management.metrics.cache.instrument=true # Instrument all available caches.
management.metrics.distribution.percentiles-histogram.*= # Whether meter IDs starting-with the specified name should be publish percentile histograms. management.metrics.distribution.percentiles-histogram.*= # Whether meter IDs starting-with the specified name should be publish percentile histograms.
management.metrics.distribution.percentiles.*= # Specific computed non-aggregable percentiles to ship to the backend for meter IDs starting-with the specified name. management.metrics.distribution.percentiles.*= # Specific computed non-aggregable percentiles to ship to the backend for meter IDs starting-with the specified name.
management.metrics.distribution.sla.*= Specific SLA boundaries for meter IDs starting-with the specified name. The longest match wins, the key `all` can also be used to configure all meters. management.metrics.distribution.sla.*= Specific SLA boundaries for meter IDs starting-with the specified name. The longest match wins, the key `all` can also be used to configure all meters.
@ -1391,10 +1390,6 @@ content into your application. Rather, pick only the properties that you need.
management.metrics.export.statsd.polling-frequency=10s # How often gauges will be polled. When a gauge is polled, its value is recalculated and if the value has changed, it is sent to the StatsD server. management.metrics.export.statsd.polling-frequency=10s # How often gauges will be polled. When a gauge is polled, its value is recalculated and if the value has changed, it is sent to the StatsD server.
management.metrics.export.statsd.port=8125 # Port of the StatsD server to receive exported metrics. management.metrics.export.statsd.port=8125 # Port of the StatsD server to receive exported metrics.
management.metrics.export.statsd.queue-size=2147483647 # Maximum size of the queue of items waiting to be sent to the StatsD server. management.metrics.export.statsd.queue-size=2147483647 # Maximum size of the queue of items waiting to be sent to the StatsD server.
management.metrics.jdbc.instrument=true # Instrument all available data sources.
management.metrics.jdbc.metric-name=data.source # Name of the metric for data source usage.
management.metrics.rabbitmq.instrument=true # Instrument all available connection factories.
management.metrics.rabbitmq.metric-name=rabbitmq # Name of the metric for RabbitMQ usage.
management.metrics.use-global-registry=true # Whether auto-configured MeterRegistry implementations should be bound to the global static registry on Metrics. management.metrics.use-global-registry=true # Whether auto-configured MeterRegistry implementations should be bound to the global static registry on Metrics.
management.metrics.web.client.max-uri-tags=100 # Maximum number of unique URI tag values allowed. After the max number of tag values is reached, metrics with additional tag values are denied by filter. management.metrics.web.client.max-uri-tags=100 # Maximum number of unique URI tag values allowed. After the max number of tag values is reached, metrics with additional tag values are denied by filter.
management.metrics.web.client.record-request-percentiles=false # Whether instrumented requests record percentiles histogram buckets by default. management.metrics.web.client.record-request-percentiles=false # Whether instrumented requests record percentiles histogram buckets by default.

@ -1243,11 +1243,9 @@ is required. A `CacheMetricsRegistrar` bean is made available to make that proce
[[production-ready-metrics-jdbc]] [[production-ready-metrics-jdbc]]
=== DataSource Metrics === DataSource Metrics
Auto-configuration enables the instrumentation of all available ``DataSource`` objects Auto-configuration enables the instrumentation of all available ``DataSource`` objects
with a metric named `data.source`. Data source instrumentation results in gauges with a metric named `jdbc`. Data source instrumentation results in gauges representing the
representing the currently active, maximum allowed, and minimum allowed connections in the currently active, maximum allowed, and minimum allowed connections in the pool. Each of
pool. Each of these gauges has a name that is prefixed by `data.source` by default. The these gauges has a name that is prefixed by `jdbc`.
prefix can be customized by setting the `management.metrics.jdbc.metric-name`
property.
Metrics are also tagged by the name of the `DataSource` computed based on the bean name. Metrics are also tagged by the name of the `DataSource` computed based on the bean name.
@ -1256,8 +1254,7 @@ Metrics are also tagged by the name of the `DataSource` computed based on the be
[[production-ready-metrics-rabbitmq]] [[production-ready-metrics-rabbitmq]]
=== RabbitMQ metrics === RabbitMQ metrics
Auto-configuration will enable the instrumentation of all available RabbitMQ connection Auto-configuration will enable the instrumentation of all available RabbitMQ connection
factories with a metric named `rabbitmq`. The prefix can be customized by using the factories with a metric named `rabbitmq`.
`management.metrics.rabbitmq.metric-name` property.

Loading…
Cancel
Save