counterSubmissions) {
- this.counterSubmissions = counterSubmissions;
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricRepositoryAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricRepositoryAutoConfiguration.java
deleted file mode 100644
index c237ccf6ef10..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricRepositoryAutoConfiguration.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright 2012-2017 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;
-
-import com.codahale.metrics.MetricRegistry;
-
-import org.springframework.boot.actuate.metrics.CounterService;
-import org.springframework.boot.actuate.metrics.GaugeService;
-import org.springframework.boot.actuate.metrics.buffer.BufferCounterService;
-import org.springframework.boot.actuate.metrics.buffer.BufferGaugeService;
-import org.springframework.boot.actuate.metrics.buffer.BufferMetricReader;
-import org.springframework.boot.actuate.metrics.buffer.CounterBuffers;
-import org.springframework.boot.actuate.metrics.buffer.GaugeBuffers;
-import org.springframework.boot.actuate.metrics.export.Exporter;
-import org.springframework.boot.actuate.metrics.export.MetricCopyExporter;
-import org.springframework.boot.actuate.metrics.repository.InMemoryMetricRepository;
-import org.springframework.boot.actuate.metrics.writer.MetricWriter;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.messaging.MessageChannel;
-
-/**
- * {@link EnableAutoConfiguration Auto-configuration} for metrics services. Creates
- * user-facing {@link GaugeService} and {@link CounterService} instances, and also back
- * end repositories to catch the data pumped into them.
- *
- * In general, even if metric data needs to be stored and analysed remotely, it is
- * recommended to use in-memory storage to buffer metric updates locally as is done by the
- * default {@link CounterBuffers} and {@link GaugeBuffers}. The values can be exported
- * (e.g. on a periodic basis) using an {@link Exporter}, most implementations of which
- * have optimizations for sending data to remote repositories.
- *
- * If Spring Messaging is on the classpath and a {@link MessageChannel} called
- * "metricsChannel" is also available, all metric update events are published additionally
- * as messages on that channel. Additional analysis or actions can be taken by clients
- * subscribing to that channel.
- *
- * In addition if Dropwizard's metrics library is on the classpath a
- * {@link MetricRegistry} will be created and the default counter and gauge services will
- * switch to using it instead of the default repository. Users can create "special"
- * Dropwizard metrics by prefixing their metric names with the appropriate type (e.g.
- * "histogram.*", "meter.*". "timer.*") and sending them to the {@code GaugeService} or
- * {@code CounterService}.
- *
- * By default all metric updates go to all {@link MetricWriter} instances in the
- * application context via a {@link MetricCopyExporter} firing every 5 seconds (disable
- * this by setting {@code spring.metrics.export.enabled=false}).
- *
- * @see GaugeService
- * @see CounterService
- * @see MetricWriter
- * @see InMemoryMetricRepository
- * @see Exporter
- * @author Dave Syer
- * @since 2.0.0
- */
-@Configuration
-public class MetricRepositoryAutoConfiguration {
-
- @Configuration
- @ConditionalOnMissingBean(GaugeService.class)
- static class FastMetricServicesConfiguration {
-
- @Bean
- @ConditionalOnMissingBean
- public CounterBuffers counterBuffers() {
- return new CounterBuffers();
- }
-
- @Bean
- @ConditionalOnMissingBean
- public GaugeBuffers gaugeBuffers() {
- return new GaugeBuffers();
- }
-
- @Bean
- @ExportMetricReader
- @ConditionalOnMissingBean
- public BufferMetricReader actuatorMetricReader(CounterBuffers counters,
- GaugeBuffers gauges) {
- return new BufferMetricReader(counters, gauges);
- }
-
- @Bean
- @ConditionalOnMissingBean(CounterService.class)
- public BufferCounterService counterService(CounterBuffers writer) {
- return new BufferCounterService(writer);
- }
-
- @Bean
- @ConditionalOnMissingBean(GaugeService.class)
- public BufferGaugeService gaugeService(GaugeBuffers writer) {
- return new BufferGaugeService(writer);
- }
-
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsDropwizardAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsDropwizardAutoConfiguration.java
deleted file mode 100644
index 48a9656e3c55..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsDropwizardAutoConfiguration.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright 2012-2017 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;
-
-import com.codahale.metrics.MetricRegistry;
-
-import org.springframework.beans.factory.ObjectProvider;
-import org.springframework.boot.actuate.endpoint.MetricReaderPublicMetrics;
-import org.springframework.boot.actuate.metrics.CounterService;
-import org.springframework.boot.actuate.metrics.GaugeService;
-import org.springframework.boot.actuate.metrics.dropwizard.DropwizardMetricServices;
-import org.springframework.boot.actuate.metrics.dropwizard.ReservoirFactory;
-import org.springframework.boot.actuate.metrics.reader.MetricRegistryMetricReader;
-import org.springframework.boot.autoconfigure.AutoConfigureBefore;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * {@link EnableAutoConfiguration Auto-configuration} for Dropwizard-based metrics.
- *
- * @author Dave Syer
- * @since 2.0.0
- */
-@Configuration
-@ConditionalOnClass(MetricRegistry.class)
-@AutoConfigureBefore(MetricRepositoryAutoConfiguration.class)
-public class MetricsDropwizardAutoConfiguration {
-
- private final ReservoirFactory reservoirFactory;
-
- public MetricsDropwizardAutoConfiguration(
- ObjectProvider reservoirFactory) {
- this.reservoirFactory = reservoirFactory.getIfAvailable();
- }
-
- @Bean
- @ConditionalOnMissingBean
- public MetricRegistry metricRegistry() {
- return new MetricRegistry();
- }
-
- @Bean
- @ConditionalOnMissingBean({ DropwizardMetricServices.class, CounterService.class,
- GaugeService.class })
- public DropwizardMetricServices dropwizardMetricServices(
- MetricRegistry metricRegistry) {
- if (this.reservoirFactory == null) {
- return new DropwizardMetricServices(metricRegistry);
- }
- else {
- return new DropwizardMetricServices(metricRegistry, this.reservoirFactory);
- }
- }
-
- @Bean
- public MetricReaderPublicMetrics dropwizardPublicMetrics(
- MetricRegistry metricRegistry) {
- MetricRegistryMetricReader reader = new MetricRegistryMetricReader(
- metricRegistry);
- return new MetricReaderPublicMetrics(reader);
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/PublicMetricsAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/PublicMetricsAutoConfiguration.java
deleted file mode 100644
index 7aefe9d18426..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/PublicMetricsAutoConfiguration.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Copyright 2012-2017 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;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.Servlet;
-import javax.sql.DataSource;
-
-import org.apache.catalina.startup.Tomcat;
-
-import org.springframework.beans.factory.ObjectProvider;
-import org.springframework.boot.actuate.autoconfigure.cache.CacheStatisticsAutoConfiguration;
-import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration;
-import org.springframework.boot.actuate.cache.CacheStatisticsProvider;
-import org.springframework.boot.actuate.endpoint.CachePublicMetrics;
-import org.springframework.boot.actuate.endpoint.DataSourcePublicMetrics;
-import org.springframework.boot.actuate.endpoint.MetricReaderPublicMetrics;
-import org.springframework.boot.actuate.endpoint.PublicMetrics;
-import org.springframework.boot.actuate.endpoint.RichGaugeReaderPublicMetrics;
-import org.springframework.boot.actuate.endpoint.SystemPublicMetrics;
-import org.springframework.boot.actuate.endpoint.TomcatPublicMetrics;
-import org.springframework.boot.actuate.metrics.integration.SpringIntegrationMetricReader;
-import org.springframework.boot.actuate.metrics.reader.CompositeMetricReader;
-import org.springframework.boot.actuate.metrics.reader.MetricReader;
-import org.springframework.boot.actuate.metrics.rich.RichGaugeReader;
-import org.springframework.boot.autoconfigure.AutoConfigureAfter;
-import org.springframework.boot.autoconfigure.AutoConfigureBefore;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
-import org.springframework.boot.autoconfigure.condition.SearchStrategy;
-import org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration;
-import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
-import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvider;
-import org.springframework.cache.CacheManager;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.integration.config.EnableIntegrationManagement;
-import org.springframework.integration.support.management.IntegrationManagementConfigurer;
-
-/**
- * {@link EnableAutoConfiguration Auto-configuration} for {@link PublicMetrics}.
- *
- * @author Stephane Nicoll
- * @author Phillip Webb
- * @author Johannes Edmeier
- * @author Artem Bilan
- * @since 2.0.0
- */
-@Configuration
-@AutoConfigureBefore(EndpointAutoConfiguration.class)
-@AutoConfigureAfter({ DataSourceAutoConfiguration.class, CacheAutoConfiguration.class,
- MetricRepositoryAutoConfiguration.class, CacheStatisticsAutoConfiguration.class,
- IntegrationAutoConfiguration.class })
-public class PublicMetricsAutoConfiguration {
-
- private final List metricReaders;
-
- public PublicMetricsAutoConfiguration(
- @ExportMetricReader ObjectProvider> metricReaders) {
- this.metricReaders = metricReaders.getIfAvailable();
- }
-
- @Bean
- public SystemPublicMetrics systemPublicMetrics() {
- return new SystemPublicMetrics();
- }
-
- @Bean
- public MetricReaderPublicMetrics metricReaderPublicMetrics() {
- return new MetricReaderPublicMetrics(
- new CompositeMetricReader(this.metricReaders == null ? new MetricReader[0]
- : this.metricReaders
- .toArray(new MetricReader[this.metricReaders.size()])));
- }
-
- @Bean
- @ConditionalOnBean(RichGaugeReader.class)
- public RichGaugeReaderPublicMetrics richGaugePublicMetrics(
- RichGaugeReader richGaugeReader) {
- return new RichGaugeReaderPublicMetrics(richGaugeReader);
- }
-
- @Configuration
- @ConditionalOnClass(DataSource.class)
- @ConditionalOnBean(DataSource.class)
- static class DataSourceMetricsConfiguration {
-
- @Bean
- @ConditionalOnMissingBean
- @ConditionalOnBean(DataSourcePoolMetadataProvider.class)
- public DataSourcePublicMetrics dataSourcePublicMetrics() {
- return new DataSourcePublicMetrics();
- }
-
- }
-
- @Configuration
- @ConditionalOnClass({ Servlet.class, Tomcat.class })
- @ConditionalOnWebApplication
- static class TomcatMetricsConfiguration {
-
- @Bean
- @ConditionalOnMissingBean
- public TomcatPublicMetrics tomcatPublicMetrics() {
- return new TomcatPublicMetrics();
- }
-
- }
-
- @Configuration
- @ConditionalOnClass(CacheManager.class)
- @ConditionalOnBean(CacheManager.class)
- static class CacheStatisticsConfiguration {
-
- @Bean
- @ConditionalOnMissingBean
- @ConditionalOnBean(CacheStatisticsProvider.class)
- public CachePublicMetrics cachePublicMetrics(
- Map cacheManagers,
- Collection> statisticsProviders) {
- return new CachePublicMetrics(cacheManagers, statisticsProviders);
- }
-
- }
-
- @Configuration
- @ConditionalOnClass(EnableIntegrationManagement.class)
- static class IntegrationMetricsConfiguration {
-
- @Bean(name = IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME)
- @ConditionalOnMissingBean(value = IntegrationManagementConfigurer.class, name = IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME, search = SearchStrategy.CURRENT)
- public IntegrationManagementConfigurer managementConfigurer() {
- IntegrationManagementConfigurer configurer = new IntegrationManagementConfigurer();
- configurer.setDefaultCountsEnabled(true);
- configurer.setDefaultStatsEnabled(true);
- return configurer;
- }
-
- @Bean
- @ConditionalOnMissingBean(name = "springIntegrationPublicMetrics")
- public MetricReaderPublicMetrics springIntegrationPublicMetrics(
- IntegrationManagementConfigurer managementConfigurer) {
- return new MetricReaderPublicMetrics(
- new SpringIntegrationMetricReader(managementConfigurer));
- }
-
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/package-info.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/package-info.java
deleted file mode 100644
index d6fe8ba5c84d..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2012-2017 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.
- */
-
-/**
- * Auto-configuration for metrics.
- */
-package org.springframework.boot.actuate.autoconfigure.metrics;
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/AbstractJmxCacheStatisticsProvider.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/AbstractJmxCacheStatisticsProvider.java
deleted file mode 100644
index d922a8ef1121..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/AbstractJmxCacheStatisticsProvider.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Copyright 2012-2017 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.cache;
-
-import java.lang.management.ManagementFactory;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import javax.management.AttributeNotFoundException;
-import javax.management.InstanceNotFoundException;
-import javax.management.MBeanException;
-import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-import javax.management.ReflectionException;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.springframework.cache.Cache;
-import org.springframework.cache.CacheManager;
-
-/**
- * Base {@link CacheStatisticsProvider} implementation that uses JMX to retrieve the cache
- * statistics.
- *
- * @param The cache type
- * @author Stephane Nicoll
- * @since 1.3.0
- */
-public abstract class AbstractJmxCacheStatisticsProvider
- implements CacheStatisticsProvider {
-
- private static final Logger logger = LoggerFactory
- .getLogger(AbstractJmxCacheStatisticsProvider.class);
-
- private MBeanServer mBeanServer;
-
- private final Map caches = new ConcurrentHashMap<>();
-
- @Override
- public CacheStatistics getCacheStatistics(CacheManager cacheManager, C cache) {
- try {
- ObjectName objectName = internalGetObjectName(cache);
- return (objectName == null ? null : getCacheStatistics(objectName));
- }
- catch (MalformedObjectNameException ex) {
- throw new IllegalStateException(ex);
- }
- }
-
- /**
- * Return the {@link ObjectName} of the MBean that is managing the specified cache or
- * {@code null} if none is found.
- * @param cache the cache to handle
- * @return the object name of the cache statistics MBean
- * @throws MalformedObjectNameException if the {@link ObjectName} for that cache is
- * invalid
- */
- protected abstract ObjectName getObjectName(C cache)
- throws MalformedObjectNameException;
-
- /**
- * Return the current {@link CacheStatistics} snapshot from the MBean identified by
- * the specified {@link ObjectName}.
- * @param objectName the object name of the cache statistics MBean
- * @return the current cache statistics
- */
- protected abstract CacheStatistics getCacheStatistics(ObjectName objectName);
-
- private ObjectName internalGetObjectName(C cache)
- throws MalformedObjectNameException {
- String cacheName = cache.getName();
- ObjectNameWrapper value = this.caches.get(cacheName);
- if (value != null) {
- return value.objectName;
- }
- ObjectName objectName = getObjectName(cache);
- this.caches.put(cacheName, new ObjectNameWrapper(objectName));
- return objectName;
- }
-
- protected MBeanServer getMBeanServer() {
- if (this.mBeanServer == null) {
- this.mBeanServer = ManagementFactory.getPlatformMBeanServer();
- }
- return this.mBeanServer;
- }
-
- protected T getAttribute(ObjectName objectName, String attributeName,
- Class type) {
- try {
- Object attribute = getMBeanServer().getAttribute(objectName, attributeName);
- return type.cast(attribute);
- }
- catch (MBeanException | ReflectionException ex) {
- throw new IllegalStateException(ex);
- }
- catch (AttributeNotFoundException ex) {
- throw new IllegalStateException("Unexpected: MBean with name '" + objectName
- + "' " + "does not expose attribute with name " + attributeName, ex);
- }
- catch (InstanceNotFoundException ex) {
- logger.warn("Cache statistics are no longer available", ex);
- return null;
- }
- }
-
- private static class ObjectNameWrapper {
-
- private final ObjectName objectName;
-
- ObjectNameWrapper(ObjectName objectName) {
- this.objectName = objectName;
- }
-
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/CacheStatistics.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/CacheStatistics.java
deleted file mode 100644
index f6cc96e1f988..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/CacheStatistics.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2012-2015 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.cache;
-
-import java.util.Collection;
-
-import org.springframework.boot.actuate.metrics.Metric;
-
-/**
- * Snapshot of the statistics of a given cache. {@code CacheStatistics} instances have a
- * very short life as it represents the statistics of a cache at one particular point in
- * time.
- *
- * @author Stephane Nicoll
- * @since 1.3.0
- */
-public interface CacheStatistics {
-
- /**
- * Generate the relevant {@link Metric} instances based on the specified prefix.
- * @param prefix the metrics prefix (ends with '.')
- * @return the metrics corresponding to this instance
- */
- Collection> toMetrics(String prefix);
-
- /**
- * Return the size of the cache or {@code null} if that information is not available.
- * @return the size of the cache or {@code null}
- */
- Long getSize();
-
- /**
- * Return the ratio of cache requests which were hits as a value between 0 and 1 where
- * 0 means that the hit ratio is 0% and 1 means it is 100%.
- *
- * This may also return {@code null} if the cache-specifics statistics does not
- * provide the necessary information
- * @return the hit ratio or {@code null}
- */
- Double getHitRatio();
-
- /**
- * Return the ratio of cache requests which were misses as value between 0 and 1 where
- * 0 means that the miss ratio is 0% and 1 means it is 100%.
- *
- * This may also return {@code null} if the cache-specifics statistics does not
- * provide the necessary information
- * @return the miss ratio or {@code null}
- */
- Double getMissRatio();
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/CacheStatisticsProvider.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/CacheStatisticsProvider.java
deleted file mode 100644
index 2aebddea6c92..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/CacheStatisticsProvider.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2012-2017 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.cache;
-
-import org.springframework.cache.Cache;
-import org.springframework.cache.CacheManager;
-
-/**
- * Provide a {@link CacheStatistics} based on a {@link Cache}.
- *
- * @param The {@link Cache} type
- * @author Stephane Nicoll
- * @author Phillip Webb
- * @since 1.3.0
- */
-@FunctionalInterface
-public interface CacheStatisticsProvider {
-
- /**
- * Return the current {@link CacheStatistics} snapshot for the specified {@link Cache}
- * or {@code null} if the given cache could not be handled.
- * @param cacheManager the {@link CacheManager} handling this cache
- * @param cache the cache to handle
- * @return the current cache statistics or {@code null}
- */
- CacheStatistics getCacheStatistics(CacheManager cacheManager, C cache);
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/CaffeineCacheStatisticsProvider.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/CaffeineCacheStatisticsProvider.java
deleted file mode 100644
index dc6e77ffe8e3..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/CaffeineCacheStatisticsProvider.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright 2012-2016 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.cache;
-
-import com.github.benmanes.caffeine.cache.stats.CacheStats;
-
-import org.springframework.cache.CacheManager;
-import org.springframework.cache.caffeine.CaffeineCache;
-
-/**
- * {@link CacheStatisticsProvider} implementation for Caffeine.
- *
- * @author Eddú Meléndez
- * @since 1.4.0
- */
-public class CaffeineCacheStatisticsProvider
- implements CacheStatisticsProvider {
-
- @Override
- public CacheStatistics getCacheStatistics(CacheManager cacheManager,
- CaffeineCache cache) {
- DefaultCacheStatistics statistics = new DefaultCacheStatistics();
- statistics.setSize(cache.getNativeCache().estimatedSize());
- CacheStats caffeineStatistics = cache.getNativeCache().stats();
- if (caffeineStatistics.requestCount() > 0) {
- statistics.setHitRatio(caffeineStatistics.hitRate());
- statistics.setMissRatio(caffeineStatistics.missRate());
- }
- return statistics;
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/ConcurrentMapCacheStatisticsProvider.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/ConcurrentMapCacheStatisticsProvider.java
deleted file mode 100644
index 7adee9999fa5..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/ConcurrentMapCacheStatisticsProvider.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright 2012-2015 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.cache;
-
-import org.springframework.cache.CacheManager;
-import org.springframework.cache.concurrent.ConcurrentMapCache;
-
-/**
- * {@link CacheStatisticsProvider} implementation for {@link ConcurrentMapCache}.
- *
- * @author Stephane Nicoll
- * @since 1.3.0
- */
-public class ConcurrentMapCacheStatisticsProvider
- implements CacheStatisticsProvider {
-
- @Override
- public CacheStatistics getCacheStatistics(CacheManager cacheManager,
- ConcurrentMapCache cache) {
- DefaultCacheStatistics statistics = new DefaultCacheStatistics();
- statistics.setSize((long) cache.getNativeCache().size());
- return statistics;
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/DefaultCacheStatistics.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/DefaultCacheStatistics.java
deleted file mode 100644
index 091ab34ccb55..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/DefaultCacheStatistics.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright 2012-2017 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.cache;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.springframework.boot.actuate.metrics.Metric;
-
-/**
- * A default {@link CacheStatistics} implementation.
- *
- * @author Stephane Nicoll
- * @since 1.3.0
- */
-public class DefaultCacheStatistics implements CacheStatistics {
-
- private Long size;
-
- private Double hitRatio;
-
- private Double missRatio;
-
- @Override
- public Collection> toMetrics(String prefix) {
- Collection> result = new ArrayList<>();
- addMetric(result, prefix + "size", getSize());
- addMetric(result, prefix + "hit.ratio", getHitRatio());
- addMetric(result, prefix + "miss.ratio", getMissRatio());
- return result;
- }
-
- public void setGetCacheCounts(long hitCount, long missCount) {
- long total = hitCount + missCount;
- if (total > 0) {
- double hitRatio = hitCount / (double) total;
- setHitRatio(hitRatio);
- setMissRatio(1 - hitRatio);
- }
- }
-
- @Override
- public Long getSize() {
- return this.size;
- }
-
- public void setSize(Long size) {
- this.size = size;
- }
-
- @Override
- public Double getHitRatio() {
- return this.hitRatio;
- }
-
- public void setHitRatio(Double hitRatio) {
- this.hitRatio = hitRatio;
- }
-
- @Override
- public Double getMissRatio() {
- return this.missRatio;
- }
-
- public void setMissRatio(Double missRatio) {
- this.missRatio = missRatio;
- }
-
- private void addMetric(Collection> metrics, String name,
- T value) {
- if (value != null) {
- metrics.add(new Metric<>(name, value));
- }
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/EhCacheStatisticsProvider.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/EhCacheStatisticsProvider.java
deleted file mode 100644
index 98eae49faed1..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/EhCacheStatisticsProvider.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2012-2016 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.cache;
-
-import net.sf.ehcache.statistics.StatisticsGateway;
-
-import org.springframework.cache.CacheManager;
-import org.springframework.cache.ehcache.EhCacheCache;
-
-/**
- * {@link CacheStatisticsProvider} implementation for EhCache.
- *
- * @author Stephane Nicoll
- * @since 1.3.0
- */
-public class EhCacheStatisticsProvider implements CacheStatisticsProvider {
-
- @Override
- public CacheStatistics getCacheStatistics(CacheManager cacheManager,
- EhCacheCache cache) {
- DefaultCacheStatistics statistics = new DefaultCacheStatistics();
- StatisticsGateway ehCacheStatistics = cache.getNativeCache().getStatistics();
- statistics.setSize(ehCacheStatistics.getSize());
- double hitRatio = cacheHitRatio(ehCacheStatistics);
- if (!Double.isNaN(hitRatio)) {
- // ratio is calculated 'racily' and can drift marginally above unity,
- // so we cap it here
- double sanitizedHitRatio = (hitRatio > 1 ? 1 : hitRatio);
- statistics.setHitRatio(sanitizedHitRatio);
- statistics.setMissRatio(1 - sanitizedHitRatio);
- }
- return statistics;
- }
-
- private double cacheHitRatio(StatisticsGateway stats) {
- long hitCount = stats.cacheHitCount();
- long missCount = stats.cacheMissCount();
- return ((double) hitCount) / (hitCount + missCount);
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/HazelcastCacheStatisticsProvider.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/HazelcastCacheStatisticsProvider.java
deleted file mode 100644
index d445f9d6bdf9..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/HazelcastCacheStatisticsProvider.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright 2012-2015 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.cache;
-
-import com.hazelcast.core.IMap;
-import com.hazelcast.monitor.LocalMapStats;
-import com.hazelcast.spring.cache.HazelcastCache;
-
-import org.springframework.cache.CacheManager;
-
-/**
- * {@link CacheStatisticsProvider} implementation for Hazelcast.
- *
- * @author Stephane Nicoll
- * @since 1.3.0
- */
-public class HazelcastCacheStatisticsProvider
- implements CacheStatisticsProvider {
-
- @Override
- public CacheStatistics getCacheStatistics(CacheManager cacheManager,
- HazelcastCache cache) {
- DefaultCacheStatistics statistics = new DefaultCacheStatistics();
- LocalMapStats mapStatistics = ((IMap, ?>) cache.getNativeCache())
- .getLocalMapStats();
- statistics.setSize(mapStatistics.getOwnedEntryCount());
- statistics.setGetCacheCounts(mapStatistics.getHits(),
- mapStatistics.getGetOperationCount() - mapStatistics.getHits());
- return statistics;
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/InfinispanCacheStatisticsProvider.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/InfinispanCacheStatisticsProvider.java
deleted file mode 100644
index 2a424ae2b522..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/InfinispanCacheStatisticsProvider.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright 2012-2015 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.cache;
-
-import java.util.Set;
-
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectInstance;
-import javax.management.ObjectName;
-
-import org.infinispan.spring.provider.SpringCache;
-
-/**
- * {@link CacheStatisticsProvider} implementation for Infinispan.
- *
- * @author Stephane Nicoll
- * @since 1.3.0
- */
-public class InfinispanCacheStatisticsProvider
- extends AbstractJmxCacheStatisticsProvider {
-
- @Override
- protected ObjectName getObjectName(SpringCache cache)
- throws MalformedObjectNameException {
- ObjectName name = new ObjectName(
- "org.infinispan:component=Statistics,type=Cache,name=\"" + cache.getName()
- + "(local)\",*");
- Set instances = getMBeanServer().queryMBeans(name, null);
- if (instances.size() == 1) {
- return instances.iterator().next().getObjectName();
- }
- // None or more than one
- return null;
- }
-
- @Override
- protected CacheStatistics getCacheStatistics(ObjectName objectName) {
- DefaultCacheStatistics statistics = new DefaultCacheStatistics();
- Integer size = getAttribute(objectName, "numberOfEntries", Integer.class);
- if (size != null) {
- statistics.setSize((long) size);
- if (size > 0) {
- // Let's initialize the stats if we have some data
- initializeStats(objectName, statistics);
- }
- }
- return statistics;
- }
-
- private void initializeStats(ObjectName objectName,
- DefaultCacheStatistics statistics) {
- Double hitRatio = getAttribute(objectName, "hitRatio", Double.class);
- if ((hitRatio != null)) {
- statistics.setHitRatio(hitRatio);
- statistics.setMissRatio(1 - hitRatio);
- }
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/JCacheCacheStatisticsProvider.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/JCacheCacheStatisticsProvider.java
deleted file mode 100644
index 02cc62ae1738..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/JCacheCacheStatisticsProvider.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright 2012-2015 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.cache;
-
-import java.util.Set;
-
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectInstance;
-import javax.management.ObjectName;
-
-import org.springframework.cache.jcache.JCacheCache;
-
-/**
- * {@link CacheStatisticsProvider} implementation for a JSR-107 compliant cache.
- *
- * @author Stephane Nicoll
- * @since 1.3.0
- */
-public class JCacheCacheStatisticsProvider
- extends AbstractJmxCacheStatisticsProvider {
-
- @Override
- protected ObjectName getObjectName(JCacheCache cache)
- throws MalformedObjectNameException {
- ObjectName name = new ObjectName(
- "javax.cache:type=CacheStatistics,Cache=" + cache.getName() + ",*");
- Set instances = getMBeanServer().queryMBeans(name, null);
- if (instances.size() == 1) {
- return instances.iterator().next().getObjectName();
- }
- // None or more than one
- return null;
- }
-
- @Override
- protected CacheStatistics getCacheStatistics(ObjectName objectName) {
- DefaultCacheStatistics statistics = new DefaultCacheStatistics();
- Float hitPercentage = getAttribute(objectName, "CacheHitPercentage", Float.class);
- Float missPercentage = getAttribute(objectName, "CacheMissPercentage",
- Float.class);
- if ((hitPercentage != null && missPercentage != null)
- && (hitPercentage > 0 || missPercentage > 0)) {
- statistics.setHitRatio(hitPercentage / (double) 100);
- statistics.setMissRatio(missPercentage / (double) 100);
- }
- return statistics;
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/package-info.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/package-info.java
deleted file mode 100644
index 3fb8898be2cb..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2012-2017 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.
- */
-
-/**
- * Classes for cache statistics.
- */
-package org.springframework.boot.actuate.cache;
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/CachePublicMetrics.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/CachePublicMetrics.java
deleted file mode 100644
index 94193f2c31c5..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/CachePublicMetrics.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * Copyright 2012-2017 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.endpoint;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-
-import org.springframework.boot.actuate.cache.CacheStatistics;
-import org.springframework.boot.actuate.cache.CacheStatisticsProvider;
-import org.springframework.boot.actuate.metrics.Metric;
-import org.springframework.cache.Cache;
-import org.springframework.cache.CacheManager;
-import org.springframework.cache.transaction.TransactionAwareCacheDecorator;
-import org.springframework.core.ResolvableType;
-import org.springframework.util.ClassUtils;
-import org.springframework.util.LinkedMultiValueMap;
-import org.springframework.util.MultiValueMap;
-
-/**
- * A {@link PublicMetrics} implementation that provides cache statistics.
- *
- * @author Stephane Nicoll
- * @since 1.3.0
- */
-public class CachePublicMetrics implements PublicMetrics {
-
- private final Map cacheManagers;
-
- private final Collection> statisticsProviders;
-
- /**
- * Create a new {@link CachePublicMetrics} instance.
- * @param cacheManagers the cache managers
- * @param statisticsProviders the statistics providers
- */
- public CachePublicMetrics(Map cacheManagers,
- Collection> statisticsProviders) {
- this.cacheManagers = cacheManagers;
- this.statisticsProviders = statisticsProviders;
- }
-
- @Override
- public Collection> metrics() {
- Collection> metrics = new HashSet<>();
- for (Map.Entry> entry : getCacheManagerBeans()
- .entrySet()) {
- addMetrics(metrics, entry.getKey(), entry.getValue());
- }
- return metrics;
- }
-
- private MultiValueMap getCacheManagerBeans() {
- MultiValueMap cacheManagerNamesByCacheName = new LinkedMultiValueMap<>();
- for (Map.Entry entry : this.cacheManagers.entrySet()) {
- for (String cacheName : entry.getValue().getCacheNames()) {
- cacheManagerNamesByCacheName.add(cacheName,
- new CacheManagerBean(entry.getKey(), entry.getValue()));
- }
- }
- return cacheManagerNamesByCacheName;
- }
-
- private void addMetrics(Collection> metrics, String cacheName,
- List cacheManagerBeans) {
- for (CacheManagerBean cacheManagerBean : cacheManagerBeans) {
- CacheManager cacheManager = cacheManagerBean.getCacheManager();
- Cache cache = unwrapIfNecessary(cacheManager.getCache(cacheName));
- CacheStatistics statistics = getCacheStatistics(cache, cacheManager);
- if (statistics != null) {
- String prefix = cacheName;
- if (cacheManagerBeans.size() > 1) {
- prefix = cacheManagerBean.getBeanName() + "_" + prefix;
- }
- prefix = "cache." + prefix + (prefix.endsWith(".") ? "" : ".");
- metrics.addAll(statistics.toMetrics(prefix));
- }
- }
- }
-
- private Cache unwrapIfNecessary(Cache cache) {
- if (ClassUtils.isPresent(
- "org.springframework.cache.transaction.TransactionAwareCacheDecorator",
- getClass().getClassLoader())) {
- return TransactionAwareCacheDecoratorHandler.unwrapIfNecessary(cache);
- }
- return cache;
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- private CacheStatistics getCacheStatistics(Cache cache, CacheManager cacheManager) {
- if (this.statisticsProviders != null) {
- for (CacheStatisticsProvider provider : this.statisticsProviders) {
- Class> cacheType = ResolvableType
- .forClass(CacheStatisticsProvider.class, provider.getClass())
- .resolveGeneric();
- if (cacheType.isInstance(cache)) {
- CacheStatistics statistics = provider.getCacheStatistics(cacheManager,
- cache);
- if (statistics != null) {
- return statistics;
- }
- }
- }
- }
- return null;
- }
-
- private static class CacheManagerBean {
-
- private final String beanName;
-
- private final CacheManager cacheManager;
-
- CacheManagerBean(String beanName, CacheManager cacheManager) {
- this.beanName = beanName;
- this.cacheManager = cacheManager;
- }
-
- public String getBeanName() {
- return this.beanName;
- }
-
- public CacheManager getCacheManager() {
- return this.cacheManager;
- }
-
- }
-
- private static class TransactionAwareCacheDecoratorHandler {
-
- private static Cache unwrapIfNecessary(Cache cache) {
- try {
- if (cache instanceof TransactionAwareCacheDecorator) {
- return ((TransactionAwareCacheDecorator) cache).getTargetCache();
- }
- }
- catch (NoClassDefFoundError ex) {
- // Ignore
- }
- return cache;
- }
-
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/DataSourcePublicMetrics.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/DataSourcePublicMetrics.java
deleted file mode 100644
index 29b03e968631..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/DataSourcePublicMetrics.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright 2012-2017 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.endpoint;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Set;
-
-import javax.annotation.PostConstruct;
-import javax.sql.DataSource;
-
-import org.springframework.beans.factory.NoSuchBeanDefinitionException;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.actuate.metrics.Metric;
-import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadata;
-import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvider;
-import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProviders;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.annotation.Primary;
-
-/**
- * A {@link PublicMetrics} implementation that provides data source usage statistics.
- *
- * @author Stephane Nicoll
- * @since 1.2.0
- */
-public class DataSourcePublicMetrics implements PublicMetrics {
-
- private static final String DATASOURCE_SUFFIX = "dataSource";
-
- @Autowired
- private ApplicationContext applicationContext;
-
- @Autowired
- private Collection providers;
-
- private final Map metadataByPrefix = new HashMap<>();
-
- @PostConstruct
- public void initialize() {
- DataSource primaryDataSource = getPrimaryDataSource();
- DataSourcePoolMetadataProvider provider = new DataSourcePoolMetadataProviders(
- this.providers);
- for (Map.Entry entry : this.applicationContext
- .getBeansOfType(DataSource.class).entrySet()) {
- String beanName = entry.getKey();
- DataSource bean = entry.getValue();
- String prefix = createPrefix(beanName, bean, bean.equals(primaryDataSource));
- DataSourcePoolMetadata poolMetadata = provider
- .getDataSourcePoolMetadata(bean);
- if (poolMetadata != null) {
- this.metadataByPrefix.put(prefix, poolMetadata);
- }
- }
- }
-
- @Override
- public Collection> metrics() {
- Set> metrics = new LinkedHashSet<>();
- for (Map.Entry entry : this.metadataByPrefix
- .entrySet()) {
- String prefix = entry.getKey();
- prefix = (prefix.endsWith(".") ? prefix : prefix + ".");
- DataSourcePoolMetadata metadata = entry.getValue();
- addMetric(metrics, prefix + "active", metadata.getActive());
- addMetric(metrics, prefix + "usage", metadata.getUsage());
- }
- return metrics;
- }
-
- private void addMetric(Set> metrics, String name,
- T value) {
- if (value != null) {
- metrics.add(new Metric<>(name, value));
- }
- }
-
- /**
- * Create the prefix to use for the metrics to associate with the given
- * {@link DataSource}.
- * @param name the name of the data source bean
- * @param dataSource the data source to configure
- * @param primary if this data source is the primary data source
- * @return a prefix for the given data source
- */
- protected String createPrefix(String name, DataSource dataSource, boolean primary) {
- if (primary) {
- return "datasource.primary";
- }
- if (name.length() > DATASOURCE_SUFFIX.length()
- && name.toLowerCase().endsWith(DATASOURCE_SUFFIX.toLowerCase())) {
- name = name.substring(0, name.length() - DATASOURCE_SUFFIX.length());
- }
- return "datasource." + name;
- }
-
- /**
- * Attempt to locate the primary {@link DataSource} (i.e. either the only data source
- * available or the one amongst the candidates marked as {@link Primary}). Return
- * {@code null} if there no primary data source could be found.
- * @return the primary datasource
- */
- private DataSource getPrimaryDataSource() {
- try {
- return this.applicationContext.getBean(DataSource.class);
- }
- catch (NoSuchBeanDefinitionException ex) {
- return null;
- }
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/MetricReaderPublicMetrics.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/MetricReaderPublicMetrics.java
deleted file mode 100644
index b68784d1c8ca..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/MetricReaderPublicMetrics.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 2012-2017 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.endpoint;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.springframework.boot.actuate.metrics.Metric;
-import org.springframework.boot.actuate.metrics.reader.MetricReader;
-import org.springframework.util.Assert;
-
-/**
- * {@link PublicMetrics} exposed from a {@link MetricReader}.
- *
- * @author Dave Syer
- * @author Christian Dupuis
- * @author Stephane Nicoll
- * @author Phillip Webb
- */
-public class MetricReaderPublicMetrics implements PublicMetrics {
-
- private final MetricReader metricReader;
-
- public MetricReaderPublicMetrics(MetricReader metricReader) {
- Assert.notNull(metricReader, "MetricReader must not be null");
- this.metricReader = metricReader;
- }
-
- @Override
- public Collection> metrics() {
- List> result = new ArrayList<>();
- for (Metric> metric : this.metricReader.findAll()) {
- result.add(metric);
- }
- return result;
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/MetricsEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/MetricsEndpoint.java
deleted file mode 100644
index 06316797153e..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/MetricsEndpoint.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright 2012-2017 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.endpoint;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.function.Predicate;
-import java.util.regex.Pattern;
-
-import org.springframework.boot.actuate.metrics.Metric;
-import org.springframework.boot.endpoint.Endpoint;
-import org.springframework.boot.endpoint.ReadOperation;
-import org.springframework.boot.endpoint.Selector;
-import org.springframework.core.annotation.AnnotationAwareOrderComparator;
-import org.springframework.util.Assert;
-import org.springframework.util.StringUtils;
-
-/**
- * {@link Endpoint} to expose a collection of {@link PublicMetrics}.
- *
- * @author Dave Syer
- */
-@Endpoint(id = "metrics")
-public class MetricsEndpoint {
-
- private final List publicMetrics;
-
- /**
- * Create a new {@link MetricsEndpoint} instance.
- * @param publicMetrics the metrics to expose
- */
- public MetricsEndpoint(PublicMetrics publicMetrics) {
- this(Collections.singleton(publicMetrics));
- }
-
- /**
- * Create a new {@link MetricsEndpoint} instance.
- * @param publicMetrics the metrics to expose. The collection will be sorted using the
- * {@link AnnotationAwareOrderComparator}.
- */
- public MetricsEndpoint(Collection publicMetrics) {
- Assert.notNull(publicMetrics, "PublicMetrics must not be null");
- this.publicMetrics = new ArrayList<>(publicMetrics);
- AnnotationAwareOrderComparator.sort(this.publicMetrics);
- }
-
- public void registerPublicMetrics(PublicMetrics metrics) {
- this.publicMetrics.add(metrics);
- AnnotationAwareOrderComparator.sort(this.publicMetrics);
- }
-
- public void unregisterPublicMetrics(PublicMetrics metrics) {
- this.publicMetrics.remove(metrics);
- }
-
- @ReadOperation
- public Map metrics(String pattern) {
- return metrics(StringUtils.hasText(pattern)
- ? Pattern.compile(pattern).asPredicate() : (name) -> true);
- }
-
- @ReadOperation
- public Map metricNamed(@Selector String requiredName) {
- Map metrics = metrics((name) -> name.equals(requiredName));
- if (metrics.isEmpty()) {
- return null;
- }
- return metrics;
- }
-
- private Map metrics(Predicate namePredicate) {
- Map result = new LinkedHashMap<>();
- List metrics = new ArrayList<>(this.publicMetrics);
- for (PublicMetrics publicMetric : metrics) {
- try {
- for (Metric> metric : publicMetric.metrics()) {
- if (namePredicate.test(metric.getName())
- && metric.getValue() != null) {
- result.put(metric.getName(), metric.getValue());
- }
- }
- }
- catch (Exception ex) {
- // Could not evaluate metrics
- }
- }
- return result;
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/MetricsEndpointMetricReader.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/MetricsEndpointMetricReader.java
deleted file mode 100644
index 381956290fcb..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/MetricsEndpointMetricReader.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2012-2017 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.endpoint;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.springframework.boot.actuate.metrics.Metric;
-import org.springframework.boot.actuate.metrics.reader.MetricReader;
-
-/**
- * {@link MetricReader} that pulls all current values out of the {@link MetricsEndpoint}.
- * No timestamp information is available, so there is no way to check if the values are
- * recent, and they all come out with the default (current time).
- *
- * @author Dave Syer
- * @since 1.3.0
- */
-public class MetricsEndpointMetricReader implements MetricReader {
-
- private final MetricsEndpoint endpoint;
-
- public MetricsEndpointMetricReader(MetricsEndpoint endpoint) {
- this.endpoint = endpoint;
- }
-
- @Override
- public Metric> findOne(String metricName) {
- Metric metric = null;
- Object value = this.endpoint.metrics(null).get(metricName);
- if (value != null) {
- metric = new Metric<>(metricName, (Number) value);
- }
- return metric;
- }
-
- @Override
- public Iterable> findAll() {
- List> metrics = new ArrayList<>();
- Map values = this.endpoint.metrics(null);
- Date timestamp = new Date();
- for (Entry entry : values.entrySet()) {
- String name = entry.getKey();
- Object value = entry.getValue();
- metrics.add(new Metric<>(name, (Number) value, timestamp));
- }
- return metrics;
- }
-
- @Override
- public long count() {
- return this.endpoint.metrics(null).size();
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/PublicMetrics.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/PublicMetrics.java
deleted file mode 100644
index dca14978c36d..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/PublicMetrics.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2012-2017 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.endpoint;
-
-import java.util.Collection;
-
-import org.springframework.boot.actuate.metrics.Metric;
-
-/**
- * Interface to expose specific {@link Metric}s via a {@link MetricsEndpoint}.
- * Implementations should take care that the metrics they provide have unique names in the
- * application context, but they shouldn't have to care about global uniqueness in the JVM
- * or across a distributed system.
- *
- * @author Dave Syer
- * @see SystemPublicMetrics SystemPublicMetrics for an example implementation
- */
-@FunctionalInterface
-public interface PublicMetrics {
-
- /**
- * Return an indication of current state through metrics.
- * @return the public metrics
- */
- Collection> metrics();
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/RichGaugeReaderPublicMetrics.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/RichGaugeReaderPublicMetrics.java
deleted file mode 100644
index 970cec57d077..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/RichGaugeReaderPublicMetrics.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright 2012-2017 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.endpoint;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.springframework.boot.actuate.metrics.Metric;
-import org.springframework.boot.actuate.metrics.rich.RichGauge;
-import org.springframework.boot.actuate.metrics.rich.RichGaugeReader;
-import org.springframework.util.Assert;
-
-/**
- * {@link PublicMetrics} exposed from a {@link RichGaugeReader}.
- *
- * @author Johannes Edmeier
- * @since 1.2
- */
-public class RichGaugeReaderPublicMetrics implements PublicMetrics {
-
- private final RichGaugeReader richGaugeReader;
-
- public RichGaugeReaderPublicMetrics(RichGaugeReader richGaugeReader) {
- Assert.notNull(richGaugeReader, "RichGaugeReader must not be null");
- this.richGaugeReader = richGaugeReader;
- }
-
- @Override
- public Collection> metrics() {
- List> result = new ArrayList<>();
- for (RichGauge richGauge : this.richGaugeReader.findAll()) {
- result.addAll(convert(richGauge));
- }
- return result;
- }
-
- private List> convert(RichGauge gauge) {
- List> result = new ArrayList<>(6);
- result.add(new Metric<>(gauge.getName() + RichGauge.AVG, gauge.getAverage()));
- result.add(new Metric<>(gauge.getName() + RichGauge.VAL, gauge.getValue()));
- result.add(new Metric<>(gauge.getName() + RichGauge.MIN, gauge.getMin()));
- result.add(new Metric<>(gauge.getName() + RichGauge.MAX, gauge.getMax()));
- result.add(new Metric<>(gauge.getName() + RichGauge.ALPHA, gauge.getAlpha()));
- result.add(new Metric<>(gauge.getName() + RichGauge.COUNT, gauge.getCount()));
- return result;
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/SystemPublicMetrics.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/SystemPublicMetrics.java
deleted file mode 100644
index 6a0a97ecb40b..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/SystemPublicMetrics.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Copyright 2012-2017 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.endpoint;
-
-import java.lang.management.ClassLoadingMXBean;
-import java.lang.management.GarbageCollectorMXBean;
-import java.lang.management.ManagementFactory;
-import java.lang.management.MemoryUsage;
-import java.lang.management.ThreadMXBean;
-import java.util.Collection;
-import java.util.LinkedHashSet;
-import java.util.List;
-
-import org.springframework.boot.actuate.metrics.Metric;
-import org.springframework.core.Ordered;
-import org.springframework.util.StringUtils;
-
-/**
- * A {@link PublicMetrics} implementation that provides various system-related metrics.
- *
- * @author Dave Syer
- * @author Christian Dupuis
- * @author Stephane Nicoll
- * @author Johannes Edmeier
- * @since 1.2.0
- */
-public class SystemPublicMetrics implements PublicMetrics, Ordered {
-
- private long timestamp;
-
- public SystemPublicMetrics() {
- this.timestamp = System.currentTimeMillis();
- }
-
- @Override
- public int getOrder() {
- return Ordered.HIGHEST_PRECEDENCE + 10;
- }
-
- @Override
- public Collection> metrics() {
- Collection> result = new LinkedHashSet<>();
- addBasicMetrics(result);
- addManagementMetrics(result);
- return result;
- }
-
- /**
- * Add basic system metrics.
- * @param result the result
- */
- protected void addBasicMetrics(Collection> result) {
- // NOTE: ManagementFactory must not be used here since it fails on GAE
- Runtime runtime = Runtime.getRuntime();
- result.add(newMemoryMetric("mem",
- runtime.totalMemory() + getTotalNonHeapMemoryIfPossible()));
- result.add(newMemoryMetric("mem.free", runtime.freeMemory()));
- result.add(new Metric<>("processors", runtime.availableProcessors()));
- result.add(new Metric<>("instance.uptime",
- System.currentTimeMillis() - this.timestamp));
- }
-
- private long getTotalNonHeapMemoryIfPossible() {
- try {
- return ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage().getUsed();
- }
- catch (Throwable ex) {
- return 0;
- }
- }
-
- /**
- * Add metrics from ManagementFactory if possible. Note that ManagementFactory is not
- * available on Google App Engine.
- * @param result the result
- */
- private void addManagementMetrics(Collection> result) {
- try {
- // Add JVM up time in ms
- result.add(new Metric<>("uptime",
- ManagementFactory.getRuntimeMXBean().getUptime()));
- result.add(new Metric<>("systemload.average",
- ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage()));
- addHeapMetrics(result);
- addNonHeapMetrics(result);
- addThreadMetrics(result);
- addClassLoadingMetrics(result);
- addGarbageCollectionMetrics(result);
- }
- catch (NoClassDefFoundError ex) {
- // Expected on Google App Engine
- }
- }
-
- /**
- * Add JVM heap metrics.
- * @param result the result
- */
- protected void addHeapMetrics(Collection> result) {
- MemoryUsage memoryUsage = ManagementFactory.getMemoryMXBean()
- .getHeapMemoryUsage();
- result.add(newMemoryMetric("heap.committed", memoryUsage.getCommitted()));
- result.add(newMemoryMetric("heap.init", memoryUsage.getInit()));
- result.add(newMemoryMetric("heap.used", memoryUsage.getUsed()));
- result.add(newMemoryMetric("heap", memoryUsage.getMax()));
- }
-
- /**
- * Add JVM non-heap metrics.
- * @param result the result
- */
- private void addNonHeapMetrics(Collection> result) {
- MemoryUsage memoryUsage = ManagementFactory.getMemoryMXBean()
- .getNonHeapMemoryUsage();
- result.add(newMemoryMetric("nonheap.committed", memoryUsage.getCommitted()));
- result.add(newMemoryMetric("nonheap.init", memoryUsage.getInit()));
- result.add(newMemoryMetric("nonheap.used", memoryUsage.getUsed()));
- result.add(newMemoryMetric("nonheap", memoryUsage.getMax()));
- }
-
- private Metric newMemoryMetric(String name, long bytes) {
- return new Metric<>(name, bytes / 1024);
- }
-
- /**
- * Add thread metrics.
- * @param result the result
- */
- protected void addThreadMetrics(Collection> result) {
- ThreadMXBean threadMxBean = ManagementFactory.getThreadMXBean();
- result.add(
- new Metric<>("threads.peak", (long) threadMxBean.getPeakThreadCount()));
- result.add(new Metric<>("threads.daemon",
- (long) threadMxBean.getDaemonThreadCount()));
- result.add(new Metric<>("threads.totalStarted",
- threadMxBean.getTotalStartedThreadCount()));
- result.add(new Metric<>("threads", (long) threadMxBean.getThreadCount()));
- }
-
- /**
- * Add class loading metrics.
- * @param result the result
- */
- protected void addClassLoadingMetrics(Collection> result) {
- ClassLoadingMXBean classLoadingMxBean = ManagementFactory.getClassLoadingMXBean();
- result.add(
- new Metric<>("classes", (long) classLoadingMxBean.getLoadedClassCount()));
- result.add(new Metric<>("classes.loaded",
- classLoadingMxBean.getTotalLoadedClassCount()));
- result.add(new Metric<>("classes.unloaded",
- classLoadingMxBean.getUnloadedClassCount()));
- }
-
- /**
- * Add garbage collection metrics.
- * @param result the result
- */
- protected void addGarbageCollectionMetrics(Collection> result) {
- List garbageCollectorMxBeans = ManagementFactory
- .getGarbageCollectorMXBeans();
- for (GarbageCollectorMXBean garbageCollectorMXBean : garbageCollectorMxBeans) {
- String name = beautifyGcName(garbageCollectorMXBean.getName());
- result.add(new Metric<>("gc." + name + ".count",
- garbageCollectorMXBean.getCollectionCount()));
- result.add(new Metric<>("gc." + name + ".time",
- garbageCollectorMXBean.getCollectionTime()));
- }
- }
-
- /**
- * Turn GC names like 'PS Scavenge' or 'PS MarkSweep' into something that is more
- * metrics friendly.
- * @param name the source name
- * @return a metric friendly name
- */
- private String beautifyGcName(String name) {
- return StringUtils.replace(name, " ", "_").toLowerCase();
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/TomcatPublicMetrics.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/TomcatPublicMetrics.java
deleted file mode 100644
index a27af6ef6d96..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/TomcatPublicMetrics.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright 2012-2017 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.endpoint;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.catalina.Container;
-import org.apache.catalina.Context;
-import org.apache.catalina.Manager;
-import org.apache.catalina.session.ManagerBase;
-
-import org.springframework.beans.BeansException;
-import org.springframework.boot.actuate.metrics.Metric;
-import org.springframework.boot.web.embedded.tomcat.TomcatWebServer;
-import org.springframework.boot.web.server.WebServer;
-import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-
-/**
- * A {@link PublicMetrics} implementation that provides Tomcat statistics.
- *
- * @author Johannes Edmeier
- * @author Phillip Webb
- * @since 1.2.0
- */
-public class TomcatPublicMetrics implements PublicMetrics, ApplicationContextAware {
-
- private ApplicationContext applicationContext;
-
- @Override
- public Collection> metrics() {
- if (this.applicationContext instanceof ServletWebServerApplicationContext) {
- Manager manager = getManager(
- (ServletWebServerApplicationContext) this.applicationContext);
- if (manager != null) {
- return metrics(manager);
- }
- }
- return Collections.emptySet();
- }
-
- private Manager getManager(ServletWebServerApplicationContext applicationContext) {
- WebServer webServer = applicationContext.getWebServer();
- if (webServer instanceof TomcatWebServer) {
- return getManager((TomcatWebServer) webServer);
- }
- return null;
- }
-
- private Manager getManager(TomcatWebServer webServer) {
- for (Container container : webServer.getTomcat().getHost().findChildren()) {
- if (container instanceof Context) {
- return ((Context) container).getManager();
- }
- }
- return null;
- }
-
- private Collection> metrics(Manager manager) {
- List> metrics = new ArrayList<>(2);
- if (manager instanceof ManagerBase) {
- addMetric(metrics, "httpsessions.max",
- ((ManagerBase) manager).getMaxActiveSessions());
- }
- addMetric(metrics, "httpsessions.active", manager.getActiveSessions());
- return metrics;
- }
-
- private void addMetric(List> metrics, String name, Integer value) {
- metrics.add(new Metric<>(name, value));
- }
-
- @Override
- public void setApplicationContext(ApplicationContext applicationContext)
- throws BeansException {
- this.applicationContext = applicationContext;
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/CounterService.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/CounterService.java
deleted file mode 100644
index aae0921f912c..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/CounterService.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright 2012-2013 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.metrics;
-
-/**
- * A service that can be used to increment, decrement and reset a named counter value.
- *
- * @author Dave Syer
- */
-public interface CounterService {
-
- /**
- * Increment the specified counter by 1.
- * @param metricName the name of the counter
- */
- void increment(String metricName);
-
- /**
- * Decrement the specified counter by 1.
- * @param metricName the name of the counter
- */
- void decrement(String metricName);
-
- /**
- * Reset the specified counter.
- * @param metricName the name of the counter
- */
- void reset(String metricName);
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/GaugeService.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/GaugeService.java
deleted file mode 100644
index eaa00fb48d3c..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/GaugeService.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright 2012-2017 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.metrics;
-
-/**
- * A service that can be used to submit a named double value for storage and analysis. Any
- * statistics or analysis that needs to be carried out is best left for other concerns,
- * but ultimately they are under control of the implementation of this service. For
- * instance, the value submitted here could be a method execution timing result, and it
- * would go to a backend that keeps a histogram of recent values for comparison purposes.
- * Or it could be a simple measurement of a sensor value (like a temperature reading) to
- * be passed on to a monitoring system in its raw form.
- *
- * @author Dave Syer
- */
-@FunctionalInterface
-public interface GaugeService {
-
- /**
- * Set the specified gauge value.
- * @param metricName the name of the gauge to set
- * @param value the value of the gauge
- */
- void submit(String metricName, double value);
-
-}
diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/Iterables.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/MeterRegistryConfigurer.java
similarity index 55%
rename from spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/Iterables.java
rename to spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/MeterRegistryConfigurer.java
index 6f9562365b95..dd428d0523a5 100644
--- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/Iterables.java
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/MeterRegistryConfigurer.java
@@ -1,4 +1,4 @@
-/*
+/**
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,26 +13,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.springframework.boot.actuate.metrics;
-import java.util.ArrayList;
-import java.util.Collection;
+import io.micrometer.core.instrument.MeterRegistry;
/**
- * @author Dave Syer
+ * Defines callback methods to customize the Java-based configuration for
+ * {@link MeterRegistry} implementations.
+ *
+ *
+ * Add one or more of these configurers to the application context to customize
+ * a registry.
+ *
+ * Configurers are guaranteed to be applied before any {@link io.micrometer.core.instrument.Meter}
+ * is registered with the registry.
+ *
+ * @since 2.0.0
+ * @author Jon Schneider
*/
-public abstract class Iterables {
-
- public static Collection collection(Iterable iterable) {
- if (iterable instanceof Collection) {
- return (Collection) iterable;
- }
- ArrayList list = new ArrayList<>();
- for (T t : iterable) {
- list.add(t);
- }
- return list;
- }
-
+public interface MeterRegistryConfigurer {
+ void configureRegistry(MeterRegistry registry);
}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/Metric.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/Metric.java
deleted file mode 100644
index 19d61ac1784d..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/Metric.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright 2012-2017 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.metrics;
-
-import java.util.Date;
-
-import org.springframework.util.Assert;
-import org.springframework.util.ObjectUtils;
-
-/**
- * Immutable class that can be used to hold any arbitrary system measurement value (a
- * named numeric value with a timestamp). For example a metric might record the number of
- * active connections to a server, or the temperature of a meeting room.
- *
- * @param the value type
- * @author Dave Syer
- */
-public class Metric {
-
- private final String name;
-
- private final T value;
-
- private final Date timestamp;
-
- /**
- * Create a new {@link Metric} instance for the current time.
- * @param name the name of the metric
- * @param value the value of the metric
- */
- public Metric(String name, T value) {
- this(name, value, new Date());
- }
-
- /**
- * Create a new {@link Metric} instance.
- * @param name the name of the metric
- * @param value the value of the metric
- * @param timestamp the timestamp for the metric
- */
- public Metric(String name, T value, Date timestamp) {
- Assert.notNull(name, "Name must not be null");
- this.name = name;
- this.value = value;
- this.timestamp = timestamp;
- }
-
- /**
- * Returns the name of the metric.
- * @return the name
- */
- public String getName() {
- return this.name;
- }
-
- /**
- * Returns the value of the metric.
- * @return the value
- */
- public T getValue() {
- return this.value;
- }
-
- public Date getTimestamp() {
- return this.timestamp;
- }
-
- @Override
- public String toString() {
- return "Metric [name=" + this.name + ", value=" + this.value + ", timestamp="
- + this.timestamp + "]";
- }
-
- /**
- * Create a new {@link Metric} with an incremented value.
- * @param amount the amount that the new metric will differ from this one
- * @return a new {@link Metric} instance
- */
- public Metric increment(int amount) {
- return new Metric<>(this.getName(),
- Long.valueOf(this.getValue().longValue() + amount));
- }
-
- /**
- * Create a new {@link Metric} with a different value.
- * @param the metric value type
- * @param value the value of the new metric
- * @return a new {@link Metric} instance
- */
- public Metric set(S value) {
- return new Metric<>(this.getName(), value);
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ObjectUtils.nullSafeHashCode(this.name);
- result = prime * result + ObjectUtils.nullSafeHashCode(this.timestamp);
- result = prime * result + ObjectUtils.nullSafeHashCode(this.value);
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (obj instanceof Metric) {
- Metric> other = (Metric>) obj;
- boolean rtn = true;
- rtn = rtn && ObjectUtils.nullSafeEquals(this.name, other.name);
- rtn = rtn && ObjectUtils.nullSafeEquals(this.timestamp, other.timestamp);
- rtn = rtn && ObjectUtils.nullSafeEquals(this.value, other.value);
- return rtn;
- }
- return super.equals(obj);
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/MetricsConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/MetricsConfiguration.java
new file mode 100644
index 000000000000..926a587a6c00
--- /dev/null
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/MetricsConfiguration.java
@@ -0,0 +1,135 @@
+/**
+ * Copyright 2012-2017 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.metrics;
+
+import java.util.Collection;
+
+import org.springframework.beans.factory.ObjectProvider;
+import org.springframework.boot.actuate.metrics.binder.SpringIntegrationMetrics;
+import org.springframework.boot.actuate.metrics.export.MetricsExporter;
+import org.springframework.boot.actuate.metrics.export.atlas.AtlasExportConfiguration;
+import org.springframework.boot.actuate.metrics.export.datadog.DatadogExportConfiguration;
+import org.springframework.boot.actuate.metrics.export.ganglia.GangliaExportConfiguration;
+import org.springframework.boot.actuate.metrics.export.graphite.GraphiteExportConfiguration;
+import org.springframework.boot.actuate.metrics.export.influx.InfluxExportConfiguration;
+import org.springframework.boot.actuate.metrics.export.jmx.JmxExportConfiguration;
+import org.springframework.boot.actuate.metrics.export.prometheus.PrometheusExportConfiguration;
+import org.springframework.boot.actuate.metrics.export.simple.SimpleExportConfiguration;
+import org.springframework.boot.actuate.metrics.scheduling.ScheduledMethodMetrics;
+import org.springframework.boot.actuate.metrics.web.MetricsRestTemplateConfiguration;
+import org.springframework.boot.actuate.metrics.web.MetricsServletRequestConfiguration;
+import org.springframework.boot.actuate.metrics.web.MetricsWebfluxRequestConfiguration;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.autoconfigure.condition.SearchStrategy;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.integration.support.management.IntegrationManagementConfigurer;
+
+import io.micrometer.core.instrument.MeterRegistry;
+import io.micrometer.core.instrument.Metrics;
+import io.micrometer.core.instrument.binder.MeterBinder;
+import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
+
+/**
+ * Metrics configuration for Spring 4/Boot 1.x
+ *
+ * @since 2.0.0
+ * @author Jon Schneider
+ */
+@Configuration
+@EnableConfigurationProperties(MetricsConfigurationProperties.class)
+@Import({
+ RecommendedMeterBinders.class,
+ MetricsServletRequestConfiguration.class,
+ MetricsWebfluxRequestConfiguration.class,
+ MetricsRestTemplateConfiguration.class,
+
+ // supported monitoring systems
+ AtlasExportConfiguration.class,
+ DatadogExportConfiguration.class,
+ GangliaExportConfiguration.class,
+ GraphiteExportConfiguration.class,
+ InfluxExportConfiguration.class,
+ JmxExportConfiguration.class,
+ PrometheusExportConfiguration.class,
+ SimpleExportConfiguration.class,
+})
+class MetricsConfiguration {
+ @ConditionalOnMissingBean(MeterRegistry.class)
+ @Bean
+ public CompositeMeterRegistry compositeMeterRegistry(ObjectProvider> exportersProvider) {
+ CompositeMeterRegistry composite = new CompositeMeterRegistry();
+
+ if (exportersProvider.getIfAvailable() != null) {
+ exportersProvider.getIfAvailable().forEach(exporter -> composite.add(exporter.registry()));
+ }
+
+ return composite;
+ }
+
+ @Configuration
+ static class MeterRegistryConfigurationSupport {
+ public MeterRegistryConfigurationSupport(MeterRegistry registry,
+ MetricsConfigurationProperties config,
+ ObjectProvider> binders,
+ ObjectProvider> registryConfigurers) {
+ if (registryConfigurers.getIfAvailable() != null) {
+ registryConfigurers.getIfAvailable().forEach(conf -> conf.configureRegistry(registry));
+ }
+
+ if (binders.getIfAvailable() != null) {
+ binders.getIfAvailable().forEach(binder -> binder.bindTo(registry));
+ }
+
+ if (config.getUseGlobalRegistry()) {
+ Metrics.addRegistry(registry);
+ }
+ }
+ }
+
+ /**
+ * If AOP is not enabled, scheduled interception will not work.
+ */
+ @Bean
+ @ConditionalOnClass(name = "org.aspectj.lang.ProceedingJoinPoint")
+ @ConditionalOnProperty(value = "spring.aop.enabled", havingValue = "true", matchIfMissing = true)
+ public ScheduledMethodMetrics metricsSchedulingAspect(MeterRegistry registry) {
+ return new ScheduledMethodMetrics(registry);
+ }
+
+ @Configuration
+ @ConditionalOnClass(name = "org.springframework.integration.config.EnableIntegrationManagement")
+ static class MetricsIntegrationConfiguration {
+
+ @Bean(name = IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME)
+ @ConditionalOnMissingBean(value = IntegrationManagementConfigurer.class, name = IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME, search = SearchStrategy.CURRENT)
+ public IntegrationManagementConfigurer managementConfigurer() {
+ IntegrationManagementConfigurer configurer = new IntegrationManagementConfigurer();
+ configurer.setDefaultCountsEnabled(true);
+ configurer.setDefaultStatsEnabled(true);
+ return configurer;
+ }
+
+ @Bean
+ public SpringIntegrationMetrics springIntegrationMetrics(IntegrationManagementConfigurer configurer) {
+ return new SpringIntegrationMetrics(configurer);
+ }
+ }
+}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/MetricsConfigurationProperties.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/MetricsConfigurationProperties.java
new file mode 100644
index 000000000000..eb5b2519d740
--- /dev/null
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/MetricsConfigurationProperties.java
@@ -0,0 +1,115 @@
+/**
+ * Copyright 2012-2017 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.metrics;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+import io.micrometer.core.instrument.MeterRegistry;
+
+/**
+ * @since 2.0.0
+ * @author Jon Schneider
+ */
+@ConfigurationProperties("metrics")
+public class MetricsConfigurationProperties {
+ private Web web = new Web();
+
+ /**
+ * Determines whether {@link MeterRegistry} implementations configured by Spring should be
+ * bound to the global static registry on {@link io.micrometer.core.instrument.Metrics}.
+ * For Spring Boot tests involving metrics, set this to {@code false} to maximize test independence.
+ * Otherwise, it can be left to {@code true}.
+ */
+ private Boolean useGlobalRegistry = true;
+
+ public Boolean getUseGlobalRegistry() {
+ return useGlobalRegistry;
+ }
+
+ public void setUseGlobalRegistry(Boolean useGlobalRegistry) {
+ this.useGlobalRegistry = useGlobalRegistry;
+ }
+
+ public static class Web {
+ /**
+ * Determines whether every request mapping (WebMVC or Webflux) should be automatically timed.
+ * If the number of time series emitted from a Spring application grows too large on account
+ * of request mapping timings, disable this and use {@link io.micrometer.core.annotation.Timed}
+ * on a per request mapping basis as needed.
+ */
+ private Boolean autoTimeServerRequests = true;
+
+ private String serverRequestsName = "http.server.requests";
+
+ /**
+ * Determines whether instrumented server requests ship percentiles histogram buckets by default.
+ * The default can be overriden by adding {@link io.micrometer.core.annotation.Timed} to a request
+ * endpoint and setting {@code percentiles} to true.
+ */
+ private Boolean serverRequestPercentiles = false;
+
+ private String clientRequestsName = "http.client.requests";
+
+ /**
+ * Determines whether instrumented client requests ship percentiles histogram buckets by default.
+ */
+ private Boolean clientRequestPercentiles = false;
+
+ public Boolean getAutoTimeServerRequests() {
+ return autoTimeServerRequests;
+ }
+
+ public void setAutoTimeServerRequests(Boolean autoTimeServerRequests) {
+ this.autoTimeServerRequests = autoTimeServerRequests;
+ }
+
+ public void setServerRequestsName(String serverRequestsName) {
+ this.serverRequestsName = serverRequestsName;
+ }
+
+ public String getServerRequestsName() {
+ return serverRequestsName;
+ }
+
+ public void setClientRequestsName(String clientRequestsName) {
+ this.clientRequestsName = clientRequestsName;
+ }
+
+ public String getClientRequestsName() {
+ return clientRequestsName;
+ }
+
+ public void setServerRequestPercentiles(Boolean serverRequestPercentiles) {
+ this.serverRequestPercentiles = serverRequestPercentiles;
+ }
+
+ public Boolean getServerRequestPercentiles() {
+ return serverRequestPercentiles;
+ }
+
+ public void setClientRequestPercentiles(Boolean clientRequestPercentiles) {
+ this.clientRequestPercentiles = clientRequestPercentiles;
+ }
+
+ public Boolean getClientRequestPercentiles() {
+ return clientRequestPercentiles;
+ }
+ }
+
+ public Web getWeb() {
+ return web;
+ }
+}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/MetricsEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/MetricsEndpoint.java
new file mode 100644
index 000000000000..6e603af0035e
--- /dev/null
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/MetricsEndpoint.java
@@ -0,0 +1,97 @@
+/**
+ * Copyright 2012-2017 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.metrics;
+
+import static java.util.stream.Collectors.toList;
+import static java.util.stream.StreamSupport.stream;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import org.springframework.boot.endpoint.Endpoint;
+import org.springframework.boot.endpoint.ReadOperation;
+import org.springframework.boot.endpoint.Selector;
+
+import io.micrometer.core.instrument.MeterRegistry;
+import io.micrometer.core.instrument.Statistic;
+import io.micrometer.core.instrument.util.HierarchicalNameMapper;
+
+/**
+ * @since 2.0.0
+ * @author Jon Schneider
+ */
+@Endpoint(id = "metrics")
+public class MetricsEndpoint {
+ private final MeterRegistry registry;
+ private final HierarchicalNameMapper nameMapper = HierarchicalNameMapper.DEFAULT;
+
+ public MetricsEndpoint(MeterRegistry registry) {
+ this.registry = registry;
+ }
+
+ @ReadOperation
+ public List listNames() {
+ return registry.getMeters().stream().map(m -> m.getId().getName()).collect(toList());
+ }
+
+ @ReadOperation
+ public Map> metric(@Selector String requiredMetricName) {
+ return registry.find(requiredMetricName).meters()
+ .stream()
+ .collect(Collectors.toMap(meter -> nameMapper.toHierarchicalName(meter.getId()),
+ meter -> stream(meter.measure().spliterator(), false)
+ .map(ms -> new MeasurementSample(ms.getStatistic(), ms.getValue()))
+ .collect(toList())));
+ }
+
+ static class MeasurementSample {
+ private Statistic statistic;
+ private Double value;
+
+ MeasurementSample() { } // for jackson in test
+
+ MeasurementSample(Statistic statistic, Double value) {
+ this.statistic = statistic;
+ this.value = value;
+ }
+
+ public Statistic getStatistic() {
+ return statistic;
+ }
+
+ public Double getValue() {
+ return value;
+ }
+
+ public void setValue(Double value) {
+ this.value = value;
+ }
+
+ public void setStatistic(Statistic statistic) {
+ this.statistic = statistic;
+ }
+
+ @Override
+ public String toString() {
+ return "MeasurementSample{" +
+ "statistic=" + statistic +
+ ", value=" + value +
+ '}';
+ }
+ }
+}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/RecommendedMeterBinders.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/RecommendedMeterBinders.java
new file mode 100644
index 000000000000..9afaa4858aad
--- /dev/null
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/RecommendedMeterBinders.java
@@ -0,0 +1,51 @@
+/**
+ * Copyright 2012-2017 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.metrics;
+
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import io.micrometer.core.instrument.binder.JvmMemoryMetrics;
+import io.micrometer.core.instrument.binder.LogbackMetrics;
+import io.micrometer.core.instrument.binder.UptimeMetrics;
+
+/**
+ * @since 2.0.0
+ * @author Jon Schneider
+ */
+@Configuration
+class RecommendedMeterBinders {
+ @Bean
+ @ConditionalOnMissingBean(JvmMemoryMetrics.class)
+ public JvmMemoryMetrics jvmMemoryMetrics() {
+ return new JvmMemoryMetrics();
+ }
+
+ @Bean
+ @ConditionalOnMissingBean(LogbackMetrics.class)
+ @ConditionalOnClass(name = "ch.qos.logback.classic.Logger")
+ public LogbackMetrics logbackMetrics() {
+ return new LogbackMetrics();
+ }
+
+ @Bean
+ @ConditionalOnMissingBean(UptimeMetrics.class)
+ public UptimeMetrics uptimeMetrics() {
+ return new UptimeMetrics();
+ }
+}
\ No newline at end of file
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/SpringMeters.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/SpringMeters.java
new file mode 100644
index 000000000000..e727c3a4fe09
--- /dev/null
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/SpringMeters.java
@@ -0,0 +1,132 @@
+/**
+ * Copyright 2012-2017 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.metrics;
+
+import static java.util.Arrays.asList;
+
+import java.util.Collection;
+
+import javax.sql.DataSource;
+
+import org.springframework.boot.actuate.metrics.binder.DataSourceMetrics;
+import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvider;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
+
+import io.micrometer.core.instrument.MeterRegistry;
+import io.micrometer.core.instrument.Tag;
+import io.micrometer.core.instrument.binder.ExecutorServiceMetrics;
+
+/**
+ * @since 2.0.0
+ * @author Jon Schneider
+ */
+public class SpringMeters {
+ /**
+ * Record metrics on active connections and connection pool utilization.
+ *
+ * @param registry The registry to bind metrics to.
+ * @param dataSource The data source to instrument.
+ * @param metadataProviders A list of providers from which the instrumentation can look up information about pool usage.
+ * @param name The name prefix of the metrics.
+ * @param tags Tags to apply to all recorded metrics.
+ * @return The instrumented data source, unchanged. The original data source
+ * is not wrapped or proxied in any way.
+ */
+ public static DataSource monitor(MeterRegistry registry,
+ DataSource dataSource,
+ Collection metadataProviders,
+ String name,
+ Iterable tags) {
+ new DataSourceMetrics(dataSource, metadataProviders, name, tags).bindTo(registry);
+ return dataSource;
+ }
+
+ /**
+ * Record metrics on active connections and connection pool utilization.
+ *
+ * @param registry The registry to bind metrics to.
+ * @param dataSource The data source to instrument.
+ * @param metadataProviders A list of providers from which the instrumentation can look up information about pool usage.
+ * @param name The name prefix of the metrics
+ * @param tags Tags to apply to all recorded metrics.
+ * @return The instrumented data source, unchanged. The original data source
+ * is not wrapped or proxied in any way.
+ */
+ public static DataSource monitor(MeterRegistry registry,
+ DataSource dataSource,
+ Collection metadataProviders,
+ String name,
+ Tag... tags) {
+ return monitor(registry, dataSource, metadataProviders, name, asList(tags));
+ }
+
+ /**
+ * Record metrics on the use of a {@link ThreadPoolTaskExecutor}.
+ *
+ * @param registry The registry to bind metrics to.
+ * @param executor The task executor to instrument.
+ * @param name The name prefix of the metrics.
+ * @param tags Tags to apply to all recorded metrics.
+ * @return The instrumented executor, proxied.
+ */
+ public static ThreadPoolTaskExecutor monitor(MeterRegistry registry, ThreadPoolTaskExecutor executor, String name, Iterable tags) {
+ ExecutorServiceMetrics.monitor(registry, executor.getThreadPoolExecutor(), name, tags);
+ return executor;
+ }
+
+ /**
+ * Record metrics on the use of a {@link ThreadPoolTaskExecutor}.
+ *
+ * @param registry The registry to bind metrics to.
+ * @param executor The executor to instrument.
+ * @param name The name prefix of the metrics.
+ * @param tags Tags to apply to all recorded metrics.
+ * @return The instrumented executor, proxied.
+ */
+ public static ThreadPoolTaskExecutor monitor(MeterRegistry registry, ThreadPoolTaskExecutor executor, String name, Tag... tags) {
+ ExecutorServiceMetrics.monitor(registry, executor.getThreadPoolExecutor(), name, tags);
+ return executor;
+ }
+
+ /**
+ * Record metrics on the use of a {@link ThreadPoolTaskExecutor}.
+ *
+ * @param registry The registry to bind metrics to.
+ * @param scheduler The task scheduler to instrument.
+ * @param name The name prefix of the metrics.
+ * @param tags Tags to apply to all recorded metrics.
+ * @return The instrumented scheduler, proxied.
+ */
+ public static ThreadPoolTaskScheduler monitor(MeterRegistry registry, ThreadPoolTaskScheduler scheduler, String name, Iterable tags) {
+ ExecutorServiceMetrics.monitor(registry, scheduler.getScheduledExecutor(), name, tags);
+ return scheduler;
+ }
+
+ /**
+ * Record metrics on the use of a {@link ThreadPoolTaskExecutor}.
+ *
+ * @param registry The registry to bind metrics to.
+ * @param scheduler The scheduler to instrument.
+ * @param name The name prefix of the metrics.
+ * @param tags Tags to apply to all recorded metrics.
+ * @return The instrumented scheduler, proxied.
+ */
+ public static ThreadPoolTaskScheduler monitor(MeterRegistry registry, ThreadPoolTaskScheduler scheduler, String name, Tag... tags) {
+ ExecutorServiceMetrics.monitor(registry, scheduler.getScheduledExecutor(), name, tags);
+ return scheduler;
+ }
+}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/aggregate/AggregateMetricReader.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/aggregate/AggregateMetricReader.java
deleted file mode 100644
index 96a3ec368040..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/aggregate/AggregateMetricReader.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * Copyright 2012-2017 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.metrics.aggregate;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import org.springframework.boot.actuate.metrics.Metric;
-import org.springframework.boot.actuate.metrics.reader.MetricReader;
-import org.springframework.boot.actuate.metrics.repository.InMemoryMetricRepository;
-import org.springframework.util.StringUtils;
-
-/**
- * A metric reader that aggregates values from a source reader, normally one that has been
- * collecting data from many sources in the same form (like a scaled-out application). The
- * source has metrics with names in the form {@code *.*.counter.**} and
- * {@code *.*.[anything].**}, and the result has metric names in the form
- * {@code aggregate.count.**} and {@code aggregate.[anything].**}. Counters are summed and
- * anything else (i.e. gauges) are aggregated by choosing the most recent value.
- *
- * @author Dave Syer
- * @since 1.3.0
- */
-public class AggregateMetricReader implements MetricReader {
-
- private MetricReader source;
-
- private String keyPattern = "d.d";
-
- private String prefix = "aggregate.";
-
- public AggregateMetricReader(MetricReader source) {
- this.source = source;
- }
-
- /**
- * Pattern that tells the aggregator what to do with the keys from the source
- * repository. The keys in the source repository are assumed to be period separated,
- * and the pattern is in the same format, e.g. "d.d.k.d". The pattern segments are
- * matched against the source keys and a rule is applied:
- *
- * - "d" means "discard" this key segment (useful for global prefixes like system
- * identifiers, or aggregate keys a.k.a. physical identifiers)
- * - "k" means "keep" it with no change (useful for logical identifiers like app
- * names)
- *
- * Default is "d.d" (we assume there is a global prefix of length 2).
- * @param keyPattern the keyPattern to set
- */
- public void setKeyPattern(String keyPattern) {
- this.keyPattern = keyPattern;
- }
-
- /**
- * Prefix to apply to all output metrics. A period will be appended if not present in
- * the provided value.
- * @param prefix the prefix to use (default "aggregator.")
- */
- public void setPrefix(String prefix) {
- if (StringUtils.hasText(prefix) && !prefix.endsWith(".")) {
- prefix = prefix + ".";
- }
- this.prefix = prefix;
- }
-
- @Override
- public Metric> findOne(String metricName) {
- if (!metricName.startsWith(this.prefix)) {
- return null;
- }
- InMemoryMetricRepository result = new InMemoryMetricRepository();
- String baseName = metricName.substring(this.prefix.length());
- for (Metric> metric : this.source.findAll()) {
- String name = getSourceKey(metric.getName());
- if (baseName.equals(name)) {
- update(result, name, metric);
- }
- }
- return result.findOne(metricName);
- }
-
- @Override
- public Iterable> findAll() {
- InMemoryMetricRepository result = new InMemoryMetricRepository();
- for (Metric> metric : this.source.findAll()) {
- String key = getSourceKey(metric.getName());
- if (key != null) {
- update(result, key, metric);
- }
- }
- return result.findAll();
- }
-
- @Override
- public long count() {
- Set names = new HashSet<>();
- for (Metric> metric : this.source.findAll()) {
- String name = getSourceKey(metric.getName());
- if (name != null) {
- names.add(name);
- }
- }
- return names.size();
- }
-
- private void update(InMemoryMetricRepository result, String key, Metric> metric) {
- String name = this.prefix + key;
- Metric> aggregate = result.findOne(name);
- if (aggregate == null) {
- aggregate = new Metric(name, metric.getValue(),
- metric.getTimestamp());
- }
- else if (key.contains("counter.")) {
- // accumulate all values
- aggregate = new Metric(name,
- metric.increment(aggregate.getValue().intValue()).getValue(),
- metric.getTimestamp());
- }
- else if (aggregate.getTimestamp().before(metric.getTimestamp())) {
- // sort by timestamp and only take the latest
- aggregate = new Metric(name, metric.getValue(),
- metric.getTimestamp());
- }
- result.set(aggregate);
- }
-
- private String getSourceKey(String name) {
- String[] keys = StringUtils.delimitedListToStringArray(name, ".");
- String[] patterns = StringUtils.delimitedListToStringArray(this.keyPattern, ".");
- StringBuilder builder = new StringBuilder();
- for (int i = 0; i < patterns.length; i++) {
- if ("k".equals(patterns[i])) {
- builder.append(builder.length() > 0 ? "." : "");
- builder.append(keys[i]);
- }
- }
- for (int i = patterns.length; i < keys.length; i++) {
- builder.append(builder.length() > 0 ? "." : "");
- builder.append(keys[i]);
- }
- return builder.toString();
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/aggregate/package-info.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/aggregate/package-info.java
deleted file mode 100644
index 85e328bc6ec9..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/aggregate/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2012-2017 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.
- */
-
-/**
- * Classes for aggregation metrics.
- */
-package org.springframework.boot.actuate.metrics.aggregate;
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/binder/DataSourceMetrics.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/binder/DataSourceMetrics.java
new file mode 100644
index 000000000000..2fb8ab3734a2
--- /dev/null
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/binder/DataSourceMetrics.java
@@ -0,0 +1,65 @@
+/**
+ * Copyright 2012-2017 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.metrics.binder;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.sql.DataSource;
+
+import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadata;
+import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvider;
+import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProviders;
+
+import io.micrometer.core.instrument.MeterRegistry;
+import io.micrometer.core.instrument.Tag;
+import io.micrometer.core.instrument.binder.MeterBinder;
+
+/**
+ * @since 2.0.0
+ * @author Jon Schneider
+ */
+public class DataSourceMetrics implements MeterBinder {
+ private final String name;
+ private final Iterable tags;
+ private final DataSourcePoolMetadata poolMetadata;
+
+ // prevents the poolMetadata that we base the gauges on from being garbage collected
+ private static Collection instrumentedPools = new ArrayList<>();
+
+ public DataSourceMetrics(DataSource dataSource, Collection metadataProviders, String name, Iterable tags) {
+ this.name = name;
+ this.tags = tags;
+
+ DataSourcePoolMetadataProvider provider = new DataSourcePoolMetadataProviders(metadataProviders);
+ poolMetadata = provider.getDataSourcePoolMetadata(dataSource);
+ instrumentedPools.add(poolMetadata);
+ }
+
+ @Override
+ public void bindTo(MeterRegistry registry) {
+ if (poolMetadata != null) {
+ if(poolMetadata.getActive() != null)
+ registry.gauge(name + ".active.connections", tags, poolMetadata, DataSourcePoolMetadata::getActive);
+
+ if(poolMetadata.getMax() != null)
+ registry.gauge(name + ".max.connections", tags, poolMetadata, DataSourcePoolMetadata::getMax);
+
+ if(poolMetadata.getMin() != null)
+ registry.gauge(name + ".min.connections", tags, poolMetadata, DataSourcePoolMetadata::getMin);
+ }
+ }
+}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/binder/SpringIntegrationMetrics.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/binder/SpringIntegrationMetrics.java
new file mode 100644
index 000000000000..39de3483f220
--- /dev/null
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/binder/SpringIntegrationMetrics.java
@@ -0,0 +1,127 @@
+/**
+ * Copyright 2012-2017 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.metrics.binder;
+
+import static java.util.Collections.emptyList;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.concurrent.TimeUnit;
+
+import org.springframework.beans.factory.SmartInitializingSingleton;
+import org.springframework.integration.support.management.*;
+
+import io.micrometer.core.instrument.MeterRegistry;
+import io.micrometer.core.instrument.Tag;
+import io.micrometer.core.instrument.Tags;
+import io.micrometer.core.instrument.binder.MeterBinder;
+
+/**
+ * @since 2.0.0
+ * @author Jon Schneider
+ */
+public class SpringIntegrationMetrics implements MeterBinder, SmartInitializingSingleton {
+ private final Iterable tags;
+ private Collection registries = new ArrayList<>();
+
+ private final IntegrationManagementConfigurer configurer;
+
+ public SpringIntegrationMetrics(IntegrationManagementConfigurer configurer) {
+ this(configurer, emptyList());
+ }
+
+ public SpringIntegrationMetrics(IntegrationManagementConfigurer configurer, Iterable tags) {
+ this.configurer = configurer;
+ this.tags = tags;
+ }
+
+ @Override
+ public void bindTo(MeterRegistry registry) {
+ registry.gauge(registry.createId("spring.integration.channelNames", tags, "The number of spring integration channels"),
+ configurer, c -> c.getChannelNames().length);
+
+ registry.gauge(registry.createId("spring.integration.handlerNames", tags, "The number of spring integration handlers"),
+ configurer, c -> c.getHandlerNames().length);
+
+ registry.gauge(registry.createId("spring.integration.sourceNames", tags, "The number of spring integration sources"),
+ configurer, c -> c.getSourceNames().length);
+
+ registries.add(registry);
+ }
+
+ private void addSourceMetrics(MeterRegistry registry) {
+ for (String source : configurer.getSourceNames()) {
+ MessageSourceMetrics sourceMetrics = configurer.getSourceMetrics(source);
+ Iterable tagsWithSource = Tags.concat(tags, "source", source);
+ registry.more().counter(registry.createId("spring.integration.source.messages", tagsWithSource, "The number of successful handler calls"),
+ sourceMetrics, MessageSourceMetrics::getMessageCount);
+ }
+ }
+
+ private void addHandlerMetrics(MeterRegistry registry) {
+ for (String handler : configurer.getHandlerNames()) {
+ MessageHandlerMetrics handlerMetrics = configurer.getHandlerMetrics(handler);
+
+ // TODO could use improvement to dynamically commute the handler name with its ID, which can change after
+ // creation as shown in the SpringIntegrationApplication sample.
+ Iterable tagsWithHandler = Tags.concat(tags, "handler", handler);
+
+ registry.more().timeGauge(registry.createId("spring.integration.handler.duration.max", tagsWithHandler, "The maximum handler duration"),
+ handlerMetrics, TimeUnit.MILLISECONDS, MessageHandlerMetrics::getMaxDuration);
+
+ registry.more().timeGauge(registry.createId("spring.integration.handler.duration.min", tagsWithHandler, "The minimum handler duration"),
+ handlerMetrics, TimeUnit.MILLISECONDS, MessageHandlerMetrics::getMinDuration);
+
+ registry.more().timeGauge(registry.createId("spring.integration.handler.duration.mean", tagsWithHandler, "The mean handler duration"),
+ handlerMetrics, TimeUnit.MILLISECONDS, MessageHandlerMetrics::getMeanDuration);
+
+ registry.gauge(registry.createId("spring.integration.handler.activeCount", tagsWithHandler, "The number of active handlers"),
+ handlerMetrics, MessageHandlerMetrics::getActiveCount);
+ }
+ }
+
+ private void addChannelMetrics(MeterRegistry registry) {
+ for (String channel : configurer.getChannelNames()) {
+ MessageChannelMetrics channelMetrics = configurer.getChannelMetrics(channel);
+ Iterable tagsWithChannel = Tags.concat(tags, "channel", channel);
+
+ registry.more().counter(registry.createId("spring.integration.channel.sendErrors", tagsWithChannel,
+ "The number of failed sends (either throwing an exception or rejected by the channel)"),
+ channelMetrics, MessageChannelMetrics::getSendErrorCount);
+
+ registry.more().counter(registry.createId("spring.integration.channel.sends", tagsWithChannel,
+ "The number of successful sends"),
+ channelMetrics, MessageChannelMetrics::getSendCount);
+
+ if (channelMetrics instanceof PollableChannelManagement) {
+ registry.more().counter(registry.createId("spring.integration.receives", tagsWithChannel,
+ "The number of messages received"),
+ (PollableChannelManagement) channelMetrics, PollableChannelManagement::getReceiveCount);
+ }
+ }
+ }
+
+ @Override
+ public void afterSingletonsInstantiated() {
+ // TODO better would be to use a BeanPostProcessor
+ configurer.afterSingletonsInstantiated();
+ registries.forEach(registry -> {
+ addChannelMetrics(registry);
+ addHandlerMetrics(registry);
+ addSourceMetrics(registry);
+ });
+ }
+}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/Buffer.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/Buffer.java
deleted file mode 100644
index 708fbf89d743..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/Buffer.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2012-2016 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.metrics.buffer;
-
-/**
- * Base class for a mutable buffer containing a timestamp and a value.
- *
- * @param the value type
- * @author Dave Syer
- * @author Phillip Webb
- */
-abstract class Buffer {
-
- private volatile long timestamp;
-
- Buffer(long timestamp) {
- this.timestamp = timestamp;
- }
-
- public long getTimestamp() {
- return this.timestamp;
- }
-
- public void setTimestamp(long timestamp) {
- this.timestamp = timestamp;
- }
-
- /**
- * Returns the buffer value.
- * @return the value of the buffer
- */
- public abstract T getValue();
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/BufferCounterService.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/BufferCounterService.java
deleted file mode 100644
index 0ffa20dc85ab..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/BufferCounterService.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright 2012-2017 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.metrics.buffer;
-
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.springframework.boot.actuate.metrics.CounterService;
-
-/**
- * Fast implementation of {@link CounterService} using {@link CounterBuffers}.
- *
- * @author Dave Syer
- * @since 1.3.0
- */
-public class BufferCounterService implements CounterService {
-
- private final ConcurrentHashMap names = new ConcurrentHashMap<>();
-
- private final CounterBuffers buffers;
-
- /**
- * Create a {@link BufferCounterService} instance.
- * @param buffers the underlying buffers used to store metrics
- */
- public BufferCounterService(CounterBuffers buffers) {
- this.buffers = buffers;
- }
-
- @Override
- public void increment(String metricName) {
- this.buffers.increment(wrap(metricName), 1L);
- }
-
- @Override
- public void decrement(String metricName) {
- this.buffers.increment(wrap(metricName), -1L);
- }
-
- @Override
- public void reset(String metricName) {
- this.buffers.reset(wrap(metricName));
- }
-
- private String wrap(String metricName) {
- String cached = this.names.get(metricName);
- if (cached != null) {
- return cached;
- }
- if (metricName.startsWith("counter") || metricName.startsWith("meter")) {
- return metricName;
- }
- String name = "counter." + metricName;
- this.names.put(metricName, name);
- return name;
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/BufferGaugeService.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/BufferGaugeService.java
deleted file mode 100644
index d928cbd31f4d..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/BufferGaugeService.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2012-2017 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.metrics.buffer;
-
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.springframework.boot.actuate.metrics.GaugeService;
-
-/**
- * Fast implementation of {@link GaugeService} using {@link GaugeBuffers}.
- *
- * @author Dave Syer
- * @since 1.3.0
- */
-public class BufferGaugeService implements GaugeService {
-
- private final ConcurrentHashMap names = new ConcurrentHashMap<>();
-
- private final GaugeBuffers buffers;
-
- /**
- * Create a {@link BufferGaugeService} instance.
- * @param buffers the underlying buffers used to store metrics
- */
- public BufferGaugeService(GaugeBuffers buffers) {
- this.buffers = buffers;
- }
-
- @Override
- public void submit(String metricName, double value) {
- this.buffers.set(wrap(metricName), value);
- }
-
- private String wrap(String metricName) {
- String cached = this.names.get(metricName);
- if (cached != null) {
- return cached;
- }
- if (metricName.startsWith("gauge") || metricName.startsWith("histogram")
- || metricName.startsWith("timer")) {
- return metricName;
- }
- String name = "gauge." + metricName;
- this.names.put(metricName, name);
- return name;
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/BufferMetricReader.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/BufferMetricReader.java
deleted file mode 100644
index ae0070fafe89..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/BufferMetricReader.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright 2012-2017 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.metrics.buffer;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.function.Predicate;
-import java.util.regex.Pattern;
-
-import org.springframework.boot.actuate.metrics.Metric;
-import org.springframework.boot.actuate.metrics.reader.MetricReader;
-import org.springframework.boot.actuate.metrics.reader.PrefixMetricReader;
-
-/**
- * {@link MetricReader} implementation using {@link CounterBuffers} and
- * {@link GaugeBuffers}.
- *
- * @author Dave Syer
- * @since 1.3.0
- */
-public class BufferMetricReader implements MetricReader, PrefixMetricReader {
-
- private static final Predicate ALL = Pattern.compile(".*").asPredicate();
-
- private final CounterBuffers counterBuffers;
-
- private final GaugeBuffers gaugeBuffers;
-
- public BufferMetricReader(CounterBuffers counterBuffers, GaugeBuffers gaugeBuffers) {
- this.counterBuffers = counterBuffers;
- this.gaugeBuffers = gaugeBuffers;
- }
-
- @Override
- public Metric> findOne(String name) {
- Buffer> buffer = this.counterBuffers.find(name);
- if (buffer == null) {
- buffer = this.gaugeBuffers.find(name);
- }
- return (buffer == null ? null : asMetric(name, buffer));
- }
-
- @Override
- public Iterable> findAll() {
- return findAll(BufferMetricReader.ALL);
- }
-
- @Override
- public Iterable> findAll(String prefix) {
- return findAll(Pattern.compile(prefix + ".*").asPredicate());
- }
-
- @Override
- public long count() {
- return this.counterBuffers.count() + this.gaugeBuffers.count();
- }
-
- private Iterable> findAll(Predicate predicate) {
- final List> metrics = new ArrayList<>();
- collectMetrics(this.gaugeBuffers, predicate, metrics);
- collectMetrics(this.counterBuffers, predicate, metrics);
- return metrics;
- }
-
- private > void collectMetrics(
- Buffers buffers, Predicate predicate,
- final List> metrics) {
- buffers.forEach(predicate, (name, value) -> metrics.add(asMetric(name, value)));
- }
-
- private Metric asMetric(String name, Buffer buffer) {
- return new Metric<>(name, buffer.getValue(), new Date(buffer.getTimestamp()));
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/Buffers.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/Buffers.java
deleted file mode 100644
index f7bad60d514a..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/Buffers.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2012-2017 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.metrics.buffer;
-
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.function.BiConsumer;
-import java.util.function.Consumer;
-import java.util.function.Predicate;
-
-/**
- * Base class used to manage a map of {@link Buffer} objects.
- *
- * @param The buffer type
- * @author Dave Syer
- * @author Phillip Webb
- */
-abstract class Buffers> {
-
- private final ConcurrentHashMap buffers = new ConcurrentHashMap<>();
-
- public void forEach(final Predicate predicate,
- BiConsumer consumer) {
- this.buffers.forEach((name, value) -> {
- if (predicate.test(name)) {
- consumer.accept(name, value);
- }
- });
- }
-
- public B find(String name) {
- return this.buffers.get(name);
- }
-
- public int count() {
- return this.buffers.size();
- }
-
- protected final void doWith(String name, Consumer consumer) {
- B buffer = this.buffers.get(name);
- if (buffer == null) {
- buffer = this.buffers.computeIfAbsent(name, (k) -> createBuffer());
- }
- consumer.accept(buffer);
- }
-
- protected abstract B createBuffer();
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/CounterBuffer.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/CounterBuffer.java
deleted file mode 100644
index 2d34e68acb4b..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/CounterBuffer.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright 2012-2016 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.metrics.buffer;
-
-import java.util.concurrent.atomic.LongAdder;
-
-/**
- * Mutable buffer containing a long adder (Java 8) and a timestamp.
- *
- * @author Dave Syer
- * @since 1.3.0
- */
-public class CounterBuffer extends Buffer {
-
- private final LongAdder adder;
-
- public CounterBuffer(long timestamp) {
- super(timestamp);
- this.adder = new LongAdder();
- }
-
- public void add(long delta) {
- this.adder.add(delta);
- }
-
- public void reset() {
- this.adder.reset();
- }
-
- @Override
- public Long getValue() {
- return this.adder.sum();
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/CounterBuffers.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/CounterBuffers.java
deleted file mode 100644
index 7381fde6c52c..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/CounterBuffers.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright 2012-2017 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.metrics.buffer;
-
-/**
- * Fast writes to in-memory metrics store using {@link CounterBuffer}.
- *
- * @author Dave Syer
- * @since 1.3.0
- */
-public class CounterBuffers extends Buffers {
-
- public void increment(String name, long delta) {
- doWith(name, (buffer) -> {
- buffer.setTimestamp(System.currentTimeMillis());
- buffer.add(delta);
- });
- }
-
- public void reset(String name) {
- doWith(name, (buffer) -> {
- buffer.setTimestamp(System.currentTimeMillis());
- buffer.reset();
- });
- }
-
- @Override
- protected CounterBuffer createBuffer() {
- return new CounterBuffer(0);
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/GaugeBuffer.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/GaugeBuffer.java
deleted file mode 100644
index fa5f6568bc1e..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/GaugeBuffer.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 2012-2015 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.metrics.buffer;
-
-/**
- * Mutable buffer containing a double value and a timestamp.
- *
- * @author Dave Syer
- * @since 1.3.0
- */
-public class GaugeBuffer extends Buffer {
-
- private volatile double value;
-
- public GaugeBuffer(long timestamp) {
- super(timestamp);
- this.value = 0;
- }
-
- @Override
- public Double getValue() {
- return this.value;
- }
-
- public void setValue(double value) {
- this.value = value;
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/package-info.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/package-info.java
deleted file mode 100644
index b7090d885b41..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2012-2015 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.
- */
-
-/**
- * Metrics buffering support.
- */
-package org.springframework.boot.actuate.metrics.buffer;
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/dropwizard/DropwizardMetricServices.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/dropwizard/DropwizardMetricServices.java
deleted file mode 100644
index 64d11a5605f8..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/dropwizard/DropwizardMetricServices.java
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- * Copyright 2012-2017 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.metrics.dropwizard;
-
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.TimeUnit;
-
-import com.codahale.metrics.Counter;
-import com.codahale.metrics.Gauge;
-import com.codahale.metrics.Histogram;
-import com.codahale.metrics.Meter;
-import com.codahale.metrics.Metric;
-import com.codahale.metrics.MetricRegistry;
-import com.codahale.metrics.Reservoir;
-import com.codahale.metrics.Timer;
-
-import org.springframework.boot.actuate.metrics.CounterService;
-import org.springframework.boot.actuate.metrics.GaugeService;
-import org.springframework.core.ResolvableType;
-import org.springframework.util.Assert;
-
-/**
- * A {@link GaugeService} and {@link CounterService} that sends data to a Dropwizard
- * {@link MetricRegistry} based on a naming convention.
- *
- * - Updates to {@link #increment(String)} with names in "meter.*" are treated as
- * {@link Meter} events
- * - Other deltas are treated as simple {@link Counter} values
- * - Inputs to {@link #submit(String, double)} with names in "histogram.*" are treated
- * as {@link Histogram} updates
- * - Inputs to {@link #submit(String, double)} with names in "timer.*" are treated as
- * {@link Timer} updates
- * - Other metrics are treated as simple {@link Gauge} values (single valued
- * measurements of type double)
- *
- *
- * @author Dave Syer
- * @author Jay Anderson
- * @author Andy Wilkinson
- */
-public class DropwizardMetricServices implements CounterService, GaugeService {
-
- private final MetricRegistry registry;
-
- private final ReservoirFactory reservoirFactory;
-
- private final ConcurrentMap gauges = new ConcurrentHashMap<>();
-
- private final ConcurrentHashMap names = new ConcurrentHashMap<>();
-
- /**
- * Create a new {@link DropwizardMetricServices} instance.
- * @param registry the underlying metric registry
- */
- public DropwizardMetricServices(MetricRegistry registry) {
- this(registry, null);
- }
-
- /**
- * Create a new {@link DropwizardMetricServices} instance.
- * @param registry the underlying metric registry
- * @param reservoirFactory the factory that instantiates the {@link Reservoir} that
- * will be used on Timers and Histograms
- */
- public DropwizardMetricServices(MetricRegistry registry,
- ReservoirFactory reservoirFactory) {
- this.registry = registry;
- this.reservoirFactory = (reservoirFactory == null ? ReservoirFactory.NONE
- : reservoirFactory);
- }
-
- @Override
- public void increment(String name) {
- incrementInternal(name, 1L);
- }
-
- @Override
- public void decrement(String name) {
- incrementInternal(name, -1L);
- }
-
- private void incrementInternal(String name, long value) {
- if (name.startsWith("meter")) {
- Meter meter = this.registry.meter(name);
- meter.mark(value);
- }
- else {
- name = wrapCounterName(name);
- Counter counter = this.registry.counter(name);
- counter.inc(value);
- }
- }
-
- @Override
- public void submit(String name, double value) {
- if (name.startsWith("histogram")) {
- submitHistogram(name, value);
- }
- else if (name.startsWith("timer")) {
- submitTimer(name, value);
- }
- else {
- name = wrapGaugeName(name);
- setGaugeValue(name, value);
- }
- }
-
- private void submitTimer(String name, double value) {
- long longValue = (long) value;
- Timer metric = register(name, new TimerMetricRegistrar());
- metric.update(longValue, TimeUnit.MILLISECONDS);
- }
-
- private void submitHistogram(String name, double value) {
- long longValue = (long) value;
- Histogram metric = register(name, new HistogramMetricRegistrar());
- metric.update(longValue);
- }
-
- @SuppressWarnings("unchecked")
- private T register(String name, MetricRegistrar registrar) {
- Reservoir reservoir = this.reservoirFactory.getReservoir(name);
- if (reservoir == null) {
- return registrar.register(this.registry, name);
- }
- Metric metric = this.registry.getMetrics().get(name);
- if (metric != null) {
- registrar.checkExisting(metric);
- return (T) metric;
- }
- try {
- return this.registry.register(name, registrar.createForReservoir(reservoir));
- }
- catch (IllegalArgumentException ex) {
- Metric added = this.registry.getMetrics().get(name);
- registrar.checkExisting(added);
- return (T) added;
- }
- }
-
- private void setGaugeValue(String name, double value) {
- // NOTE: Dropwizard provides no way to do this atomically
- SimpleGauge gauge = this.gauges.get(name);
- if (gauge == null) {
- SimpleGauge newGauge = new SimpleGauge(value);
- gauge = this.gauges.putIfAbsent(name, newGauge);
- if (gauge == null) {
- this.registry.register(name, newGauge);
- return;
- }
- }
- gauge.setValue(value);
- }
-
- private String wrapGaugeName(String metricName) {
- return wrapName(metricName, "gauge.");
- }
-
- private String wrapCounterName(String metricName) {
- return wrapName(metricName, "counter.");
- }
-
- private String wrapName(String metricName, String prefix) {
- String cached = this.names.get(metricName);
- if (cached != null) {
- return cached;
- }
- if (metricName.startsWith(prefix)) {
- return metricName;
- }
- String name = prefix + metricName;
- this.names.put(metricName, name);
- return name;
- }
-
- @Override
- public void reset(String name) {
- if (!name.startsWith("meter")) {
- name = wrapCounterName(name);
- }
- this.registry.remove(name);
- }
-
- /**
- * Simple {@link Gauge} implementation to {@literal double} value.
- */
- private final static class SimpleGauge implements Gauge {
-
- private volatile double value;
-
- private SimpleGauge(double value) {
- this.value = value;
- }
-
- @Override
- public Double getValue() {
- return this.value;
- }
-
- public void setValue(double value) {
- this.value = value;
- }
-
- }
-
- /**
- * Strategy used to register metrics.
- */
- private static abstract class MetricRegistrar {
-
- private final Class type;
-
- @SuppressWarnings("unchecked")
- MetricRegistrar() {
- this.type = (Class) ResolvableType
- .forClass(MetricRegistrar.class, getClass()).resolveGeneric();
- }
-
- public void checkExisting(Metric metric) {
- Assert.isInstanceOf(this.type, metric,
- "Different metric type already registered");
- }
-
- protected abstract T register(MetricRegistry registry, String name);
-
- protected abstract T createForReservoir(Reservoir reservoir);
-
- }
-
- /**
- * {@link MetricRegistrar} for {@link Timer} metrics.
- */
- private static class TimerMetricRegistrar extends MetricRegistrar {
-
- @Override
- protected Timer register(MetricRegistry registry, String name) {
- return registry.timer(name);
- }
-
- @Override
- protected Timer createForReservoir(Reservoir reservoir) {
- return new Timer(reservoir);
- }
-
- }
-
- /**
- * {@link MetricRegistrar} for {@link Histogram} metrics.
- */
- private static class HistogramMetricRegistrar extends MetricRegistrar {
-
- @Override
- protected Histogram register(MetricRegistry registry, String name) {
- return registry.histogram(name);
- }
-
- @Override
- protected Histogram createForReservoir(Reservoir reservoir) {
- return new Histogram(reservoir);
- }
-
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/dropwizard/ReservoirFactory.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/dropwizard/ReservoirFactory.java
deleted file mode 100644
index b3a20b6edfbf..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/dropwizard/ReservoirFactory.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2012-2017 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.metrics.dropwizard;
-
-import com.codahale.metrics.Reservoir;
-
-/**
- * Factory interface that can be used by {@link DropwizardMetricServices} to create a
- * custom {@link Reservoir}.
- *
- * @author Lucas Saldanha
- * @author Phillip Webb
- * @since 1.5.0
- */
-@FunctionalInterface
-public interface ReservoirFactory {
-
- /**
- * Default empty {@link ReservoirFactory} implementation.
- */
- ReservoirFactory NONE = (name) -> null;
-
- /**
- * Return the {@link Reservoir} instance to use or {@code null} if a custom reservoir
- * is not needed.
- * @param name the name of the metric
- * @return a reservoir instance or {@code null}
- */
- Reservoir getReservoir(String name);
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/dropwizard/package-info.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/dropwizard/package-info.java
deleted file mode 100644
index 14864c15e2d4..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/dropwizard/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2012-2015 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.
- */
-
-/**
- * Metrics integration with Dropwizard Metrics.
- */
-package org.springframework.boot.actuate.metrics.dropwizard;
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/AbstractMetricExporter.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/AbstractMetricExporter.java
deleted file mode 100644
index 9a93e2b0f7f7..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/AbstractMetricExporter.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * Copyright 2012-2017 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.metrics.export;
-
-import java.io.Closeable;
-import java.io.Flushable;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.springframework.boot.actuate.metrics.Metric;
-import org.springframework.util.StringUtils;
-
-/**
- * Base class for metric exporters that have common features, principally a prefix for
- * exported metrics and filtering by timestamp (so only new values are included in the
- * export).
- *
- * @author Dave Syer
- * @since 1.3.0
- */
-public abstract class AbstractMetricExporter implements Exporter, Closeable, Flushable {
-
- private static final Log logger = LogFactory.getLog(AbstractMetricExporter.class);
-
- private final String prefix;
-
- private Date earliestTimestamp = new Date();
-
- private boolean ignoreTimestamps = false;
-
- private boolean sendLatest = true;
-
- private volatile AtomicBoolean processing = new AtomicBoolean(false);
-
- private Date latestTimestamp = new Date(0L);
-
- public AbstractMetricExporter(String prefix) {
- this.prefix = (!StringUtils.hasText(prefix) ? ""
- : (prefix.endsWith(".") ? prefix : prefix + "."));
- }
-
- /**
- * The earliest time for which data will be exported.
- * @param earliestTimestamp the timestamp to set
- */
- public void setEarliestTimestamp(Date earliestTimestamp) {
- this.earliestTimestamp = earliestTimestamp;
- }
-
- /**
- * Ignore timestamps (export all metrics).
- * @param ignoreTimestamps the flag to set
- */
- public void setIgnoreTimestamps(boolean ignoreTimestamps) {
- this.ignoreTimestamps = ignoreTimestamps;
- }
-
- /**
- * Send only the data that changed since the last export.
- * @param sendLatest the flag to set
- */
- public void setSendLatest(boolean sendLatest) {
- this.sendLatest = sendLatest;
- }
-
- @Override
- public void export() {
- if (this.processing.compareAndSet(false, true)) {
- long latestTimestamp = System.currentTimeMillis();
- try {
- exportGroups();
- }
- catch (Exception ex) {
- logger.warn("Could not write to MetricWriter: " + ex.getClass() + ": "
- + ex.getMessage());
- }
- finally {
- this.latestTimestamp = new Date(latestTimestamp);
- flushQuietly();
- this.processing.set(false);
- }
- }
- }
-
- private void exportGroups() {
- for (String group : groups()) {
- Collection> values = new ArrayList<>();
- for (Metric> metric : next(group)) {
- Date timestamp = metric.getTimestamp();
- if (canExportTimestamp(timestamp)) {
- values.add(getPrefixedMetric(metric));
- }
- }
- if (!values.isEmpty()) {
- write(group, values);
- }
- }
- }
-
- private Metric> getPrefixedMetric(Metric> metric) {
- String name = this.prefix + metric.getName();
- return new Metric(name, metric.getValue(), metric.getTimestamp());
- }
-
- private boolean canExportTimestamp(Date timestamp) {
- if (this.ignoreTimestamps) {
- return true;
- }
- if (this.earliestTimestamp.after(timestamp)) {
- return false;
- }
- if (this.sendLatest && this.latestTimestamp.after(timestamp)) {
- return false;
- }
- return true;
- }
-
- private void flushQuietly() {
- try {
- flush();
- }
- catch (Exception ex) {
- logger.warn("Could not flush MetricWriter: " + ex.getClass() + ": "
- + ex.getMessage());
- }
- }
-
- @Override
- public void close() throws IOException {
- export();
- flushQuietly();
- }
-
- @Override
- public void flush() {
- }
-
- /**
- * Generate a group of metrics to iterate over in the form of a set of Strings (e.g.
- * prefixes). If the metrics to be exported partition into groups identified by a
- * String, subclasses should override this method. Otherwise the default should be
- * fine (iteration over all metrics).
- * @return groups of metrics to iterate over (default singleton empty string)
- */
- protected Iterable groups() {
- return Collections.singleton("");
- }
-
- /**
- * Write the values associated with a group.
- * @param group the group to write
- * @param values the values to write
- */
- protected abstract void write(String group, Collection> values);
-
- /**
- * Get the next group of metrics to write.
- * @param group the group name to write
- * @return some metrics to write
- */
- protected abstract Iterable> next(String group);
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/SpecificTriggerProperties.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/DurationConverter.java
similarity index 56%
rename from spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/SpecificTriggerProperties.java
rename to spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/DurationConverter.java
index 0b291dbb9ed2..e08896f4f8b5 100644
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/SpecificTriggerProperties.java
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/DurationConverter.java
@@ -1,5 +1,5 @@
-/*
- * Copyright 2012-2015 the original author or authors.
+/**
+ * Copyright 2012-2017 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.
@@ -13,28 +13,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.springframework.boot.actuate.metrics.export;
-/**
- * Trigger for specific names or patterns.
- *
- * @author Dave Syer
- * @since 1.3.0
- */
-public class SpecificTriggerProperties extends TriggerProperties {
+import java.time.Duration;
- /**
- * Names (or patterns) for bean names that this configuration applies to.
- */
- private String[] names;
-
- public String[] getNames() {
- return this.names;
- }
-
- public void setNames(String[] names) {
- this.names = names;
- }
+import org.springframework.boot.context.properties.ConfigurationPropertiesBinding;
+import org.springframework.core.convert.converter.Converter;
+/**
+ * @since 2.0.0
+ * @author Jon Schneider
+ */
+@ConfigurationPropertiesBinding
+public class DurationConverter implements Converter {
+ @Override
+ public Duration convert(String source) {
+ return Duration.parse(source);
+ }
}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/Exporter.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/Exporter.java
deleted file mode 100644
index 067197b19ada..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/Exporter.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2012-2017 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.metrics.export;
-
-/**
- * Generic interface for metric exports. As you scale up metric collection you will often
- * need to buffer metric data locally and export it periodically (e.g. for aggregation
- * across a cluster), so this is the marker interface for those operations. The trigger of
- * an export operation might be periodic or event driven, but it remains outside the scope
- * of this interface. You might for instance create an instance of an Exporter and trigger
- * it using a {@code @Scheduled} annotation in a Spring ApplicationContext.
- *
- * @author Dave Syer
- * @since 1.3.0
- */
-@FunctionalInterface
-public interface Exporter {
-
- /**
- * Export metric data.
- */
- void export();
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/MetricCopyExporter.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/MetricCopyExporter.java
deleted file mode 100644
index 5eec2cdff568..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/MetricCopyExporter.java
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
- * Copyright 2012-2017 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.metrics.export;
-
-import java.io.Flushable;
-import java.lang.reflect.Method;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.springframework.boot.actuate.metrics.Metric;
-import org.springframework.boot.actuate.metrics.reader.MetricReader;
-import org.springframework.boot.actuate.metrics.writer.CompositeMetricWriter;
-import org.springframework.boot.actuate.metrics.writer.CounterWriter;
-import org.springframework.boot.actuate.metrics.writer.Delta;
-import org.springframework.boot.actuate.metrics.writer.GaugeWriter;
-import org.springframework.boot.actuate.metrics.writer.MetricWriter;
-import org.springframework.util.ClassUtils;
-import org.springframework.util.ObjectUtils;
-import org.springframework.util.PatternMatchUtils;
-import org.springframework.util.ReflectionUtils;
-
-/**
- * {@link Exporter} that "exports" by copying metric data from a source
- * {@link MetricReader} to a destination {@link MetricWriter}. Actually the output writer
- * can be a {@link GaugeWriter}, in which case all metrics are simply output as their
- * current value. If the output writer is also a {@link CounterWriter} then metrics whose
- * names begin with "counter." are special: instead of writing them out as simple gauges
- * the writer will increment the counter value. This involves the exporter storing the
- * previous value of the counter so the delta can be computed. For best results with the
- * counters, do not use the exporter concurrently in multiple threads (normally it will
- * only be used periodically and sequentially, even if it is in a background thread, and
- * this is fine).
- *
- * @author Dave Syer
- * @since 1.3.0
- */
-public class MetricCopyExporter extends AbstractMetricExporter {
-
- private static final Log logger = LogFactory.getLog(MetricCopyExporter.class);
-
- private final MetricReader reader;
-
- private final GaugeWriter writer;
-
- private final CounterWriter counter;
-
- private ConcurrentMap counts = new ConcurrentHashMap<>();
-
- private String[] includes = new String[0];
-
- private String[] excludes = new String[0];
-
- /**
- * Create a new {@link MetricCopyExporter} instance.
- * @param reader the metric reader
- * @param writer the metric writer
- */
- public MetricCopyExporter(MetricReader reader, GaugeWriter writer) {
- this(reader, writer, "");
- }
-
- /**
- * Create a new {@link MetricCopyExporter} instance.
- * @param reader the metric reader
- * @param writer the metric writer
- * @param prefix the name prefix
- */
- public MetricCopyExporter(MetricReader reader, GaugeWriter writer, String prefix) {
- super(prefix);
- this.reader = reader;
- this.writer = writer;
- if (writer instanceof CounterWriter) {
- this.counter = (CounterWriter) writer;
- }
- else {
- this.counter = null;
- }
- }
-
- /**
- * Set the include patterns used to filter metrics.
- * @param includes the include patterns
- */
- public void setIncludes(String... includes) {
- if (includes != null) {
- this.includes = includes;
- }
- }
-
- /**
- * Set the exclude patterns used to filter metrics.
- * @param excludes the exclude patterns
- */
- public void setExcludes(String... excludes) {
- if (excludes != null) {
- this.excludes = excludes;
- }
- }
-
- @Override
- protected Iterable> next(String group) {
- if (ObjectUtils.isEmpty(this.includes) && ObjectUtils.isEmpty(this.excludes)) {
- return this.reader.findAll();
- }
- return new PatternMatchingIterable(MetricCopyExporter.this.reader);
- }
-
- @Override
- protected void write(String group, Collection> values) {
- for (Metric> value : values) {
- if (value.getName().startsWith("counter.") && this.counter != null) {
- this.counter.increment(calculateDelta(value));
- }
- else {
- this.writer.set(value);
- }
- }
- }
-
- private Delta> calculateDelta(Metric> value) {
- long delta = value.getValue().longValue();
- Long old = this.counts.replace(value.getName(), delta);
- if (old != null) {
- delta = delta - old;
- }
- else {
- this.counts.putIfAbsent(value.getName(), delta);
- }
- return new Delta<>(value.getName(), delta, value.getTimestamp());
- }
-
- @Override
- public void flush() {
- flush(this.writer);
- }
-
- private void flush(GaugeWriter writer) {
- if (writer instanceof CompositeMetricWriter) {
- for (MetricWriter child : (CompositeMetricWriter) writer) {
- flush(child);
- }
- }
- try {
- if (ClassUtils.isPresent("java.io.Flushable", null)) {
- if (writer instanceof Flushable) {
- ((Flushable) writer).flush();
- return;
- }
- }
- Method method = ReflectionUtils.findMethod(writer.getClass(), "flush");
- if (method != null) {
- ReflectionUtils.invokeMethod(method, writer);
- }
- }
- catch (Exception ex) {
- logger.warn("Could not flush MetricWriter: " + ex.getClass() + ": "
- + ex.getMessage());
- }
- }
-
- private class PatternMatchingIterable implements Iterable> {
-
- private final MetricReader reader;
-
- PatternMatchingIterable(MetricReader reader) {
- this.reader = reader;
- }
-
- @Override
- public Iterator> iterator() {
- return new PatternMatchingIterator(this.reader.findAll().iterator());
- }
-
- }
-
- private class PatternMatchingIterator implements Iterator> {
-
- private Metric> buffer = null;
-
- private Iterator> iterator;
-
- PatternMatchingIterator(Iterator> iterator) {
- this.iterator = iterator;
- }
-
- @Override
- public boolean hasNext() {
- if (this.buffer != null) {
- return true;
- }
- this.buffer = findNext();
- return this.buffer != null;
- }
-
- private Metric> findNext() {
- while (this.iterator.hasNext()) {
- Metric> metric = this.iterator.next();
- if (isMatch(metric)) {
- return metric;
- }
- }
- return null;
- }
-
- private boolean isMatch(Metric> metric) {
- String[] includes = MetricCopyExporter.this.includes;
- String[] excludes = MetricCopyExporter.this.excludes;
- String name = metric.getName();
- if (ObjectUtils.isEmpty(includes)
- || PatternMatchUtils.simpleMatch(includes, name)) {
- return !PatternMatchUtils.simpleMatch(excludes, name);
- }
- return false;
- }
-
- @Override
- public Metric> next() {
- Metric> metric = this.buffer;
- this.buffer = null;
- return metric;
- }
-
- };
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/MetricExportProperties.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/MetricExportProperties.java
deleted file mode 100644
index 39222ea745c9..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/MetricExportProperties.java
+++ /dev/null
@@ -1,265 +0,0 @@
-/*
- * Copyright 2012-2017 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.metrics.export;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import javax.annotation.PostConstruct;
-
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.util.PatternMatchUtils;
-
-/**
- * Configuration properties for metrics export.
- *
- * @author Dave Syer
- * @author Simon Buettner
- * @since 1.3.0
- */
-@ConfigurationProperties(prefix = "spring.metrics.export")
-public class MetricExportProperties extends TriggerProperties {
-
- /**
- * Specific trigger properties per MetricWriter bean name.
- */
- private Map triggers = new LinkedHashMap<>();
-
- private Aggregate aggregate = new Aggregate();
-
- private Redis redis = new Redis();
-
- private Statsd statsd = new Statsd();
-
- @PostConstruct
- public void setUpDefaults() {
- TriggerProperties defaults = this;
- for (Entry entry : this.triggers.entrySet()) {
- String key = entry.getKey();
- SpecificTriggerProperties value = entry.getValue();
- if (value.getNames() == null || value.getNames().length == 0) {
- value.setNames(new String[] { key });
- }
- }
- if (defaults.isSendLatest() == null) {
- defaults.setSendLatest(true);
- }
- if (defaults.getDelayMillis() == null) {
- defaults.setDelayMillis(5000);
- }
- for (TriggerProperties value : this.triggers.values()) {
- if (value.isSendLatest() == null) {
- value.setSendLatest(defaults.isSendLatest());
- }
- if (value.getDelayMillis() == null) {
- value.setDelayMillis(defaults.getDelayMillis());
- }
- }
- }
-
- /**
- * Configuration for triggers on individual named writers. Each value can individually
- * specify a name pattern explicitly, or else the map key will be used if the name is
- * not set.
- * @return the writers
- */
- public Map getTriggers() {
- return this.triggers;
- }
-
- public Aggregate getAggregate() {
- return this.aggregate;
- }
-
- public void setAggregate(Aggregate aggregate) {
- this.aggregate = aggregate;
- }
-
- public Redis getRedis() {
- return this.redis;
- }
-
- public void setRedis(Redis redis) {
- this.redis = redis;
- }
-
- public Statsd getStatsd() {
- return this.statsd;
- }
-
- public void setStatsd(Statsd statsd) {
- this.statsd = statsd;
- }
-
- /**
- * Find a matching trigger configuration.
- * @param name the bean name to match
- * @return a matching configuration if there is one
- */
- public TriggerProperties findTrigger(String name) {
- for (SpecificTriggerProperties value : this.triggers.values()) {
- if (PatternMatchUtils.simpleMatch(value.getNames(), name)) {
- return value;
- }
- }
- return this;
- }
-
- /**
- * Aggregate properties.
- */
- public static class Aggregate {
-
- /**
- * Prefix for global repository if active. Should be unique for this JVM, but most
- * useful if it also has the form "a.b" where "a" is unique to this logical
- * process (this application) and "b" is unique to this physical process. If you
- * set spring.application.name elsewhere, then the default will be in the right
- * form.
- */
- private String prefix = "";
-
- /**
- * Pattern that tells the aggregator what to do with the keys from the source
- * repository. The keys in the source repository are assumed to be period
- * separated, and the pattern is in the same format, e.g. "d.d.k.d". Here "d"
- * means "discard" and "k" means "keep" the key segment in the corresponding
- * position in the source.
- */
- private String keyPattern = "";
-
- public String getPrefix() {
- return this.prefix;
- }
-
- public void setPrefix(String prefix) {
- this.prefix = prefix;
- }
-
- public String getKeyPattern() {
- return this.keyPattern;
- }
-
- public void setKeyPattern(String keyPattern) {
- this.keyPattern = keyPattern;
- }
-
- }
-
- /**
- * Redis properties.
- */
- public static class Redis {
-
- /**
- * Prefix for redis repository if active. Should be globally unique across all
- * processes sharing the same repository.
- */
- private String prefix = "spring.metrics";
-
- /**
- * Key for redis repository export (if active). Should be globally unique for a
- * system sharing a redis repository across multiple processes.
- */
- private String key = "keys.spring.metrics";
-
- public String getPrefix() {
- return this.prefix;
- }
-
- public void setPrefix(String prefix) {
- this.prefix = prefix;
- }
-
- public String getKey() {
- return this.key;
- }
-
- public void setKey(String key) {
- this.key = key;
- }
-
- public String getAggregatePrefix() {
- // The common case including a standalone aggregator would have a prefix that
- // starts with the end of the key, so strip that bit off and call it the
- // aggregate prefix.
- if (this.key.startsWith("keys.")) {
- String candidate = this.key.substring("keys.".length());
- if (this.prefix.startsWith(candidate)) {
- return candidate;
- }
- return candidate;
- }
- // If the user went off piste, choose something that is safe (not empty) but
- // not the whole prefix (on the assumption that it contains dimension keys)
- if (this.prefix.contains(".")
- && this.prefix.indexOf(".") < this.prefix.length() - 1) {
- return this.prefix.substring(this.prefix.indexOf(".") + 1);
- }
- return this.prefix;
- }
-
- }
-
- /**
- * Statsd properties.
- */
- public static class Statsd {
-
- /**
- * Host of a statsd server to receive exported metrics.
- */
- private String host;
-
- /**
- * Port of a statsd server to receive exported metrics.
- */
- private int port = 8125;
-
- /**
- * Prefix for statsd exported metrics.
- */
- private String prefix;
-
- public String getHost() {
- return this.host;
- }
-
- public void setHost(String host) {
- this.host = host;
- }
-
- public int getPort() {
- return this.port;
- }
-
- public void setPort(int port) {
- this.port = port;
- }
-
- public String getPrefix() {
- return this.prefix;
- }
-
- public void setPrefix(String prefix) {
- this.prefix = prefix;
- }
-
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/MetricExporters.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/MetricExporters.java
deleted file mode 100644
index fb6d06e7d205..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/MetricExporters.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Copyright 2012-2017 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.metrics.export;
-
-import java.io.Closeable;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import org.springframework.boot.actuate.metrics.reader.MetricReader;
-import org.springframework.boot.actuate.metrics.writer.GaugeWriter;
-import org.springframework.scheduling.annotation.SchedulingConfigurer;
-import org.springframework.scheduling.config.IntervalTask;
-import org.springframework.scheduling.config.ScheduledTaskRegistrar;
-
-/**
- * {@link SchedulingConfigurer} to handle metrics {@link MetricCopyExporter export}.
- *
- * @author Dave Syer
- * @since 1.3.0
- */
-public class MetricExporters implements SchedulingConfigurer, Closeable {
-
- private MetricReader reader;
-
- private Map writers = new HashMap<>();
-
- private final MetricExportProperties properties;
-
- private final Map exporters = new HashMap<>();
-
- private final Set closeables = new HashSet<>();
-
- public MetricExporters(MetricExportProperties properties) {
- this.properties = properties;
- }
-
- public void setReader(MetricReader reader) {
- this.reader = reader;
- }
-
- public void setWriters(Map writers) {
- this.writers.putAll(writers);
- }
-
- public void setExporters(Map exporters) {
- this.exporters.putAll(exporters);
- }
-
- @Override
- public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
- for (Entry entry : this.exporters.entrySet()) {
- String name = entry.getKey();
- Exporter exporter = entry.getValue();
- TriggerProperties trigger = this.properties.findTrigger(name);
- if (trigger != null) {
- ExportRunner runner = new ExportRunner(exporter);
- IntervalTask task = new IntervalTask(runner, trigger.getDelayMillis(),
- trigger.getDelayMillis());
- taskRegistrar.addFixedDelayTask(task);
- }
- }
- for (Entry entry : this.writers.entrySet()) {
- String name = entry.getKey();
- GaugeWriter writer = entry.getValue();
- TriggerProperties trigger = this.properties.findTrigger(name);
- if (trigger != null) {
- MetricCopyExporter exporter = getExporter(writer, trigger);
- this.exporters.put(name, exporter);
- this.closeables.add(name);
- ExportRunner runner = new ExportRunner(exporter);
- IntervalTask task = new IntervalTask(runner, trigger.getDelayMillis(),
- trigger.getDelayMillis());
- taskRegistrar.addFixedDelayTask(task);
- }
- }
- }
-
- private MetricCopyExporter getExporter(GaugeWriter writer,
- TriggerProperties trigger) {
- MetricCopyExporter exporter = new MetricCopyExporter(this.reader, writer);
- exporter.setIncludes(trigger.getIncludes());
- exporter.setExcludes(trigger.getExcludes());
- exporter.setSendLatest(trigger.isSendLatest());
- return exporter;
- }
-
- public Map getExporters() {
- return this.exporters;
- }
-
- @Override
- public void close() throws IOException {
- for (String name : this.closeables) {
- Exporter exporter = this.exporters.get(name);
- if (exporter instanceof Closeable) {
- ((Closeable) exporter).close();
- }
- }
- }
-
- private static class ExportRunner implements Runnable {
-
- private final Exporter exporter;
-
- ExportRunner(Exporter exporter) {
- this.exporter = exporter;
- }
-
- @Override
- public void run() {
- this.exporter.export();
- }
-
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/package-info.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/MetricsExporter.java
similarity index 74%
rename from spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/package-info.java
rename to spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/MetricsExporter.java
index 2a0ab81c8095..1803fa2875b2 100644
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/package-info.java
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/MetricsExporter.java
@@ -1,5 +1,5 @@
-/*
- * Copyright 2012-2015 the original author or authors.
+/**
+ * Copyright 2012-2017 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.
@@ -13,8 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+package org.springframework.boot.actuate.metrics.export;
+
+import io.micrometer.core.instrument.MeterRegistry;
/**
- * Metrics export support.
+ * @since 2.0.0
+ * @author Jon Schneider
*/
-package org.springframework.boot.actuate.metrics.export;
+public interface MetricsExporter {
+ MeterRegistry registry();
+}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/PrefixMetricGroupExporter.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/PrefixMetricGroupExporter.java
deleted file mode 100644
index 90e8a9ebe77d..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/PrefixMetricGroupExporter.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright 2012-2017 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.metrics.export;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-import org.springframework.boot.actuate.metrics.Metric;
-import org.springframework.boot.actuate.metrics.reader.PrefixMetricReader;
-import org.springframework.boot.actuate.metrics.repository.MultiMetricRepository;
-import org.springframework.boot.actuate.metrics.writer.Delta;
-import org.springframework.boot.actuate.metrics.writer.PrefixMetricWriter;
-
-/**
- * A convenient exporter for a group of metrics from a {@link PrefixMetricReader}. Exports
- * all metrics whose name starts with a prefix (or all metrics if the prefix is empty).
- *
- * @author Dave Syer
- * @since 1.3.0
- */
-public class PrefixMetricGroupExporter extends AbstractMetricExporter {
-
- private final PrefixMetricReader reader;
-
- private final PrefixMetricWriter writer;
-
- private ConcurrentMap counts = new ConcurrentHashMap<>();
-
- private Set groups = new HashSet<>();
-
- /**
- * Create a new exporter for metrics to a writer based on an empty prefix for the
- * metric names.
- * @param reader a reader as the source of metrics
- * @param writer the writer to send the metrics to
- */
- public PrefixMetricGroupExporter(PrefixMetricReader reader,
- PrefixMetricWriter writer) {
- this(reader, writer, "");
- }
-
- /**
- * Create a new exporter for metrics to a writer based on a prefix for the metric
- * names.
- * @param reader a reader as the source of metrics
- * @param writer the writer to send the metrics to
- * @param prefix the prefix for metrics to export
- */
- public PrefixMetricGroupExporter(PrefixMetricReader reader, PrefixMetricWriter writer,
- String prefix) {
- super(prefix);
- this.reader = reader;
- this.writer = writer;
- }
-
- /**
- * The groups to export.
- * @param groups the groups to set
- */
- public void setGroups(Set groups) {
- this.groups = groups;
- }
-
- @Override
- protected Iterable groups() {
- if ((this.reader instanceof MultiMetricRepository) && this.groups.isEmpty()) {
- return ((MultiMetricRepository) this.reader).groups();
- }
- return this.groups;
- }
-
- @Override
- protected Iterable> next(String group) {
- return this.reader.findAll(group);
- }
-
- @Override
- protected void write(String group, Collection> values) {
- if (group.contains("counter.")) {
- for (Metric> value : values) {
- this.writer.increment(group, calculateDelta(value));
- }
- }
- else {
- this.writer.set(group, values);
- }
- }
-
- private Delta> calculateDelta(Metric> value) {
- long delta = value.getValue().longValue();
- Long old = this.counts.replace(value.getName(), delta);
- if (old != null) {
- delta = delta - old;
- }
- else {
- this.counts.putIfAbsent(value.getName(), delta);
- }
- return new Delta<>(value.getName(), delta, value.getTimestamp());
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/MetricsFilterSubmission.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/RegistryConfigurationProperties.java
similarity index 59%
rename from spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/MetricsFilterSubmission.java
rename to spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/RegistryConfigurationProperties.java
index 846ab20aba44..428767bde1a0 100644
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/MetricsFilterSubmission.java
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/RegistryConfigurationProperties.java
@@ -1,4 +1,4 @@
-/*
+/**
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,25 +13,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+package org.springframework.boot.actuate.metrics.export;
-package org.springframework.boot.actuate.metrics.web.servlet;
+import java.util.Properties;
/**
- * Submission types that can be made by the {@link MetricsFilter}.
- *
- * @author Phillip Webb
* @since 2.0.0
+ * @author Jon Schneider
*/
-public enum MetricsFilterSubmission {
+public abstract class RegistryConfigurationProperties {
+ private Properties props = new Properties();
- /**
- * Merge all HTTP methods into a single submission.
- */
- MERGED,
+ protected abstract String prefix();
- /**
- * Group submissions by the HTTP method of the request.
- */
- PER_HTTP_METHOD
+ public String get(String k) {
+ return props.getProperty(k);
+ }
+ protected void set(String k, Object v) {
+ props.put(prefix() + "." + k, v.toString());
+ }
}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/RichGaugeExporter.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/RichGaugeExporter.java
deleted file mode 100644
index f996bac0f1f0..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/RichGaugeExporter.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright 2012-2017 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.metrics.export;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-
-import org.springframework.boot.actuate.metrics.Metric;
-import org.springframework.boot.actuate.metrics.repository.MultiMetricRepository;
-import org.springframework.boot.actuate.metrics.rich.RichGauge;
-import org.springframework.boot.actuate.metrics.rich.RichGaugeReader;
-import org.springframework.boot.actuate.metrics.writer.MetricWriter;
-import org.springframework.boot.actuate.metrics.writer.PrefixMetricWriter;
-
-/**
- * Exporter or converter for {@link RichGauge} data to a metric-based back end. Each gauge
- * measurement is stored as a set of related metrics with a common prefix (the name of the
- * gauge), and suffixes that describe the data. For example, a gauge called {@code foo} is
- * stored as {@code[foo.min, foo.max. foo.val, foo.count, foo.avg, foo.alpha]}. If the
- * {@link MetricWriter} provided is a {@link MultiMetricRepository} then the values for a
- * gauge will be stored as a group, and hence will be retrievable from the repository in a
- * single query (or optionally individually).
- *
- * @author Dave Syer
- * @since 1.3.0
- */
-public class RichGaugeExporter extends AbstractMetricExporter {
-
- private static final String MIN = ".min";
-
- private static final String MAX = ".max";
-
- private static final String COUNT = ".count";
-
- private static final String VALUE = ".val";
-
- private static final String AVG = ".avg";
-
- private static final String ALPHA = ".alpha";
-
- private final RichGaugeReader reader;
-
- private final PrefixMetricWriter writer;
-
- public RichGaugeExporter(RichGaugeReader reader, PrefixMetricWriter writer) {
- this(reader, writer, "");
- }
-
- public RichGaugeExporter(RichGaugeReader reader, PrefixMetricWriter writer,
- String prefix) {
- super(prefix);
- this.reader = reader;
- this.writer = writer;
- }
-
- @Override
- protected Iterable> next(String group) {
- RichGauge rich = this.reader.findOne(group);
- Collection> metrics = new ArrayList<>();
- metrics.add(new Metric(group + MIN, rich.getMin()));
- metrics.add(new Metric(group + MAX, rich.getMax()));
- metrics.add(new Metric(group + COUNT, rich.getCount()));
- metrics.add(new Metric(group + VALUE, rich.getValue()));
- metrics.add(new Metric(group + AVG, rich.getAverage()));
- metrics.add(new Metric(group + ALPHA, rich.getAlpha()));
- return metrics;
- }
-
- @Override
- protected Iterable groups() {
- Collection names = new HashSet<>();
- for (RichGauge rich : this.reader.findAll()) {
- names.add(rich.getName());
- }
- return names;
- }
-
- @Override
- protected void write(String group, Collection> values) {
- this.writer.set(group, values);
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/StepRegistryConfigurationProperties.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/StepRegistryConfigurationProperties.java
new file mode 100644
index 000000000000..20a6bdcdcbef
--- /dev/null
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/StepRegistryConfigurationProperties.java
@@ -0,0 +1,50 @@
+/**
+ * Copyright 2012-2017 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.metrics.export;
+
+import java.time.Duration;
+
+import io.micrometer.core.instrument.spectator.step.StepRegistryConfig;
+
+/**
+ * @since 2.0.0
+ * @author Jon Schneider
+ */
+public abstract class StepRegistryConfigurationProperties extends RegistryConfigurationProperties implements StepRegistryConfig {
+ public void setStep(Duration step) {
+ set("step", step);
+ }
+
+ public void setEnabled(Boolean enabled) {
+ set("enabled", enabled);
+ }
+
+ public void setBatchSize(Integer batchSize) {
+ set("batchSize", batchSize);
+ }
+
+ public void setConnectTimeout(Duration connectTimeout) {
+ set("connectTimeout", connectTimeout);
+ }
+
+ public void setReadTimeout(Duration readTimeout) {
+ set("readTimeout", readTimeout);
+ }
+
+ public void setNumThreads(Integer numThreads) {
+ set("numThreads", numThreads);
+ }
+}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/TriggerProperties.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/TriggerProperties.java
deleted file mode 100644
index 513c0a0f377a..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/TriggerProperties.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright 2012-2015 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.metrics.export;
-
-/**
- * Abstract base class for trigger properties.
- *
- * @author Dave Syer
- * @since 1.3.0
- */
-public abstract class TriggerProperties {
-
- /**
- * Delay in milliseconds between export ticks. Metrics are exported to external
- * sources on a schedule with this delay.
- */
- private Long delayMillis;
-
- /**
- * Flag to enable metric export (assuming a MetricWriter is available).
- */
- private boolean enabled = true;
-
- /**
- * Flag to switch off any available optimizations based on not exporting unchanged
- * metric values.
- */
- private Boolean sendLatest;
-
- /**
- * List of patterns for metric names to include.
- */
- private String[] includes;
-
- /**
- * List of patterns for metric names to exclude. Applied after the includes.
- */
- private String[] excludes;
-
- public String[] getIncludes() {
- return this.includes;
- }
-
- public void setIncludes(String[] includes) {
- this.includes = includes;
- }
-
- public void setExcludes(String[] excludes) {
- this.excludes = excludes;
- }
-
- public String[] getExcludes() {
- return this.excludes;
- }
-
- public boolean isEnabled() {
- return this.enabled;
- }
-
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
-
- public Long getDelayMillis() {
- return this.delayMillis;
- }
-
- public void setDelayMillis(long delayMillis) {
- this.delayMillis = delayMillis;
- }
-
- public Boolean isSendLatest() {
- return this.sendLatest;
- }
-
- public void setSendLatest(boolean sendLatest) {
- this.sendLatest = sendLatest;
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/atlas/AtlasConfigurationProperties.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/atlas/AtlasConfigurationProperties.java
new file mode 100644
index 000000000000..7a934e913aed
--- /dev/null
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/atlas/AtlasConfigurationProperties.java
@@ -0,0 +1,87 @@
+/**
+ * Copyright 2012-2017 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.metrics.export.atlas;
+
+import java.time.Duration;
+
+import org.springframework.boot.actuate.metrics.export.RegistryConfigurationProperties;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+import com.netflix.spectator.atlas.AtlasConfig;
+
+/**
+ * @since 2.0.0
+ * @author Jon Schneider
+ */
+@ConfigurationProperties(prefix = "metrics.atlas")
+public class AtlasConfigurationProperties extends RegistryConfigurationProperties implements AtlasConfig {
+ public void setStep(Duration step) {
+ set("step", step);
+ }
+
+ public void setMeterTTL(Duration meterTTL) {
+ set("meterTTL", meterTTL);
+ }
+
+ public void setEnabled(Boolean enabled) {
+ set("enabled", enabled);
+ }
+
+ public void setNumThreads(Integer numThreads) {
+ set("numThreads", numThreads);
+ }
+
+ public void setUri(String uri) {
+ set("uri", uri);
+ }
+
+ public void setLwcEnabled(boolean lwcEnabled) {
+ set("lwcEnabled", lwcEnabled);
+ }
+
+ public void setConfigRefreshFrequency(Duration configRefreshFrequency) {
+ set("configRefreshFrequency", configRefreshFrequency);
+ }
+
+ public void setConfigTTL(Duration configTTL) {
+ set("configTTL", configTTL);
+ }
+
+ public void setConfigUri(String configUri) {
+ set("configUri", configUri);
+ }
+
+ public void setEvalUri(String evalUri) {
+ set("evalUri", evalUri);
+ }
+
+ public void setConnectTimeout(Duration connectTimeout) {
+ set("connectTimeout", connectTimeout);
+ }
+
+ public void setReadTimeout(Duration readTimeout) {
+ set("readTimeout", readTimeout);
+ }
+
+ public void setBatchSize(Integer batchSize) {
+ set("batchSize", batchSize);
+ }
+
+ @Override
+ protected String prefix() {
+ return "atlas";
+ }
+}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/atlas/AtlasExportConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/atlas/AtlasExportConfiguration.java
new file mode 100644
index 000000000000..a284fb4731b8
--- /dev/null
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/atlas/AtlasExportConfiguration.java
@@ -0,0 +1,53 @@
+/**
+ * Copyright 2012-2017 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.metrics.export.atlas;
+
+import org.springframework.boot.actuate.metrics.export.DurationConverter;
+import org.springframework.boot.actuate.metrics.export.MetricsExporter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+
+import com.netflix.spectator.atlas.AtlasConfig;
+
+import io.micrometer.atlas.AtlasMeterRegistry;
+import io.micrometer.core.instrument.Clock;
+
+/**
+ * @since 2.0.0
+ * @author Jon Schneider
+ */
+@Configuration
+@ConditionalOnClass(name = "io.micrometer.atlas.AtlasMeterRegistry")
+@Import(DurationConverter.class)
+@EnableConfigurationProperties(AtlasConfigurationProperties.class)
+public class AtlasExportConfiguration {
+ @ConditionalOnProperty(value = "metrics.atlas.enabled", matchIfMissing = true)
+ @Bean
+ public MetricsExporter atlasExporter(AtlasConfig config, Clock clock) {
+ return () -> new AtlasMeterRegistry(config, clock);
+ }
+
+ @ConditionalOnMissingBean
+ @Bean
+ public Clock clock() {
+ return Clock.SYSTEM;
+ }
+}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/datadog/DatadogConfigurationProperties.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/datadog/DatadogConfigurationProperties.java
new file mode 100644
index 000000000000..c0214620c723
--- /dev/null
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/datadog/DatadogConfigurationProperties.java
@@ -0,0 +1,45 @@
+/**
+ * Copyright 2012-2017 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.metrics.export.datadog;
+
+import org.springframework.boot.actuate.metrics.export.StepRegistryConfigurationProperties;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+import io.micrometer.datadog.DatadogConfig;
+
+/**
+ * @since 2.0.0
+ * @author Jon Schneider
+ */
+@ConfigurationProperties(prefix = "metrics.datadog")
+public class DatadogConfigurationProperties extends StepRegistryConfigurationProperties implements DatadogConfig {
+ public DatadogConfigurationProperties() {
+ set("apiKey", "dummyKey"); // FIXME otherwise tests fail
+ }
+
+ public void setApiKey(String apiKey) {
+ set("apiKey", apiKey);
+ }
+
+ public void setHostTag(String hostTag) {
+ set("hostTag", hostTag);
+ }
+
+ @Override
+ public String prefix() {
+ return "metrics.datadog";
+ }
+}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/datadog/DatadogExportConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/datadog/DatadogExportConfiguration.java
new file mode 100644
index 000000000000..6e2c72508d1c
--- /dev/null
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/datadog/DatadogExportConfiguration.java
@@ -0,0 +1,52 @@
+/**
+ * Copyright 2012-2017 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.metrics.export.datadog;
+
+import org.springframework.boot.actuate.metrics.export.DurationConverter;
+import org.springframework.boot.actuate.metrics.export.MetricsExporter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+
+import io.micrometer.core.instrument.Clock;
+import io.micrometer.datadog.DatadogConfig;
+import io.micrometer.datadog.DatadogMeterRegistry;
+
+/**
+ * @since 2.0.0
+ * @author Jon Schneider
+ */
+@Configuration
+@ConditionalOnClass(name = "io.micrometer.datadog.DatadogMeterRegistry")
+@Import(DurationConverter.class)
+@EnableConfigurationProperties(DatadogConfigurationProperties.class)
+public class DatadogExportConfiguration {
+ @ConditionalOnProperty(value = "metrics.datadog.enabled", matchIfMissing = true)
+ @Bean
+ public MetricsExporter datadogExporter(DatadogConfig config, Clock clock) {
+ return () -> new DatadogMeterRegistry(config, clock);
+ }
+
+ @ConditionalOnMissingBean
+ @Bean
+ public Clock clock() {
+ return Clock.SYSTEM;
+ }
+}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/ganglia/GangliaConfigurationProperties.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/ganglia/GangliaConfigurationProperties.java
new file mode 100644
index 000000000000..68497aaa7d03
--- /dev/null
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/ganglia/GangliaConfigurationProperties.java
@@ -0,0 +1,73 @@
+/**
+ * Copyright 2012-2017 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.metrics.export.ganglia;
+
+import java.time.Duration;
+import java.util.concurrent.TimeUnit;
+
+import org.springframework.boot.actuate.metrics.export.RegistryConfigurationProperties;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+import info.ganglia.gmetric4j.gmetric.GMetric;
+import io.micrometer.ganglia.GangliaConfig;
+
+/**
+ * @since 2.0.0
+ * @author Jon Schneider
+ */
+@ConfigurationProperties(prefix = "metrics.ganglia")
+public class GangliaConfigurationProperties extends RegistryConfigurationProperties implements GangliaConfig {
+ public void setStep(Duration step) {
+ set("step", step);
+ }
+
+ public void setRateUnits(TimeUnit rateUnits) {
+ set("rateUnits", rateUnits);
+ }
+
+ public void setDurationUnits(TimeUnit durationUnits) {
+ set("durationUnits", durationUnits);
+ }
+
+ public void setProtocolVersion(String protocolVersion) {
+ set("protocolVersion", protocolVersion);
+ }
+
+ public void setAddressingMode(GMetric.UDPAddressingMode addressingMode) {
+ set("addressingMode", addressingMode);
+ }
+
+ public void setTtl(Integer ttl) {
+ set("ttl", ttl);
+ }
+
+ public void setHost(String host) {
+ set("host", host);
+ }
+
+ public void setPort(Integer port) {
+ set("port", port);
+ }
+
+ public void setEnabled(Boolean enabled) {
+ set("enabled", enabled);
+ }
+
+ @Override
+ public String prefix() {
+ return "metrics.ganglia";
+ }
+}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/ganglia/GangliaExportConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/ganglia/GangliaExportConfiguration.java
new file mode 100644
index 000000000000..45f3a3cc9e6d
--- /dev/null
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/ganglia/GangliaExportConfiguration.java
@@ -0,0 +1,59 @@
+/**
+ * Copyright 2012-2017 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.metrics.export.ganglia;
+
+import org.springframework.boot.actuate.metrics.export.DurationConverter;
+import org.springframework.boot.actuate.metrics.export.MetricsExporter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+
+import io.micrometer.core.instrument.Clock;
+import io.micrometer.core.instrument.util.HierarchicalNameMapper;
+import io.micrometer.ganglia.GangliaConfig;
+import io.micrometer.ganglia.GangliaMeterRegistry;
+
+/**
+ * @since 2.0.0
+ * @author Jon Schneider
+ */
+@Configuration
+@ConditionalOnClass(name = "io.micrometer.ganglia.GangliaMeterRegistry")
+@Import(DurationConverter.class)
+@EnableConfigurationProperties(GangliaConfigurationProperties.class)
+public class GangliaExportConfiguration {
+ @ConditionalOnProperty(value = "metrics.ganglia.enabled", matchIfMissing = true)
+ @Bean
+ public MetricsExporter gangliaExporter(GangliaConfig config, HierarchicalNameMapper nameMapper, Clock clock) {
+ return () -> new GangliaMeterRegistry(config, nameMapper, clock);
+ }
+
+ @ConditionalOnMissingBean
+ @Bean
+ public Clock clock() {
+ return Clock.SYSTEM;
+ }
+
+ @ConditionalOnMissingBean
+ @Bean
+ public HierarchicalNameMapper hierarchicalNameMapper() {
+ return HierarchicalNameMapper.DEFAULT;
+ }
+}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/graphite/GraphiteConfigurationProperties.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/graphite/GraphiteConfigurationProperties.java
new file mode 100644
index 000000000000..149e994fd49c
--- /dev/null
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/graphite/GraphiteConfigurationProperties.java
@@ -0,0 +1,60 @@
+/**
+ * Copyright 2012-2017 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.metrics.export.graphite;
+
+import java.time.Duration;
+import java.util.concurrent.TimeUnit;
+
+import org.springframework.boot.actuate.metrics.export.RegistryConfigurationProperties;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+import io.micrometer.graphite.GraphiteConfig;
+
+/**
+ * @since 2.0.0
+ * @author Jon Schneider
+ */
+@ConfigurationProperties(prefix = "metrics.graphite")
+public class GraphiteConfigurationProperties extends RegistryConfigurationProperties implements GraphiteConfig {
+ public void setStep(Duration step) {
+ set("step", step);
+ }
+
+ public void setRateUnits(TimeUnit rateUnits) {
+ set("rateUnits", rateUnits);
+ }
+
+ public void setDurationUnits(TimeUnit durationUnits) {
+ set("durationUnits", durationUnits);
+ }
+
+ public void setHost(String host) {
+ set("host", host);
+ }
+
+ public void setPort(Integer port) {
+ set("port", port);
+ }
+
+ public void setEnabled(Boolean enabled) {
+ set("enabled", enabled);
+ }
+
+ @Override
+ public String prefix() {
+ return "metrics.graphite";
+ }
+}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/graphite/GraphiteExportConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/graphite/GraphiteExportConfiguration.java
new file mode 100644
index 000000000000..2e2d6979263c
--- /dev/null
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/graphite/GraphiteExportConfiguration.java
@@ -0,0 +1,59 @@
+/**
+ * Copyright 2012-2017 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.metrics.export.graphite;
+
+import org.springframework.boot.actuate.metrics.export.DurationConverter;
+import org.springframework.boot.actuate.metrics.export.MetricsExporter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+
+import io.micrometer.core.instrument.Clock;
+import io.micrometer.core.instrument.util.HierarchicalNameMapper;
+import io.micrometer.graphite.GraphiteConfig;
+import io.micrometer.graphite.GraphiteMeterRegistry;
+
+/**
+ * @since 2.0.0
+ * @author Jon Schneider
+ */
+@Configuration
+@ConditionalOnClass(name = "io.micrometer.graphite.GraphiteMeterRegistry")
+@Import(DurationConverter.class)
+@EnableConfigurationProperties(GraphiteConfigurationProperties.class)
+public class GraphiteExportConfiguration {
+ @ConditionalOnProperty(value = "metrics.graphite.enabled", matchIfMissing = true)
+ @Bean
+ public MetricsExporter graphiteExporter(GraphiteConfig config, HierarchicalNameMapper nameMapper, Clock clock) {
+ return () -> new GraphiteMeterRegistry(config, nameMapper, clock);
+ }
+
+ @ConditionalOnMissingBean
+ @Bean
+ public Clock clock() {
+ return Clock.SYSTEM;
+ }
+
+ @ConditionalOnMissingBean
+ @Bean
+ public HierarchicalNameMapper hierarchicalNameMapper() {
+ return HierarchicalNameMapper.DEFAULT;
+ }
+}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/influx/InfluxConfigurationProperties.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/influx/InfluxConfigurationProperties.java
new file mode 100644
index 000000000000..63b3edd9ef56
--- /dev/null
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/influx/InfluxConfigurationProperties.java
@@ -0,0 +1,62 @@
+/**
+ * Copyright 2012-2017 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.metrics.export.influx;
+
+import org.springframework.boot.actuate.metrics.export.StepRegistryConfigurationProperties;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+import io.micrometer.influx.InfluxConfig;
+import io.micrometer.influx.InfluxConsistency;
+
+/**
+ * @since 2.0.0
+ * @author Jon Schneider
+ */
+@ConfigurationProperties(prefix = "metrics.influx")
+public class InfluxConfigurationProperties extends StepRegistryConfigurationProperties implements InfluxConfig {
+ public void setDb(String db) {
+ set("db", db);
+ }
+
+ public void setConsistency(InfluxConsistency consistency) {
+ set("consistency", consistency);
+ }
+
+ public void setUserName(String userName) {
+ set("userName", userName);
+ }
+
+ public void setPassword(String password) {
+ set("password", password);
+ }
+
+ public void setRetentionPolicy(String retentionPolicy) {
+ set("retentionPolicy", retentionPolicy);
+ }
+
+ public void setUri(String uri) {
+ set("uri", uri);
+ }
+
+ public void setCompressed(Boolean compressed) {
+ set("compressed", compressed);
+ }
+
+ @Override
+ public String prefix() {
+ return "metrics.influx";
+ }
+}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/influx/InfluxExportConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/influx/InfluxExportConfiguration.java
new file mode 100644
index 000000000000..76080157c6e7
--- /dev/null
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/influx/InfluxExportConfiguration.java
@@ -0,0 +1,52 @@
+/**
+ * Copyright 2012-2017 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.metrics.export.influx;
+
+import org.springframework.boot.actuate.metrics.export.DurationConverter;
+import org.springframework.boot.actuate.metrics.export.MetricsExporter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+
+import io.micrometer.core.instrument.Clock;
+import io.micrometer.influx.InfluxConfig;
+import io.micrometer.influx.InfluxMeterRegistry;
+
+/**
+ * @since 2.0.0
+ * @author Jon Schneider
+ */
+@Configuration
+@ConditionalOnClass(name = "io.micrometer.influx.InfluxMeterRegistry")
+@Import(DurationConverter.class)
+@EnableConfigurationProperties(InfluxConfigurationProperties.class)
+public class InfluxExportConfiguration {
+ @ConditionalOnProperty(value = "metrics.influx.enabled", matchIfMissing = true)
+ @Bean
+ public MetricsExporter influxExporter(InfluxConfig config, Clock clock) {
+ return () -> new InfluxMeterRegistry(config, clock);
+ }
+
+ @ConditionalOnMissingBean
+ @Bean
+ public Clock clock() {
+ return Clock.SYSTEM;
+ }
+}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsChannelAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/jmx/JmxExportConfiguration.java
similarity index 50%
rename from spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsChannelAutoConfiguration.java
rename to spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/jmx/JmxExportConfiguration.java
index f5415bc61c55..9f4c597a94e7 100644
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsChannelAutoConfiguration.java
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/jmx/JmxExportConfiguration.java
@@ -1,4 +1,4 @@
-/*
+/**
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,39 +13,41 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+package org.springframework.boot.actuate.metrics.export.jmx;
-package org.springframework.boot.actuate.autoconfigure.metrics;
-
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.boot.actuate.metrics.writer.MessageChannelMetricWriter;
-import org.springframework.boot.autoconfigure.AutoConfigureBefore;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.actuate.metrics.export.MetricsExporter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.messaging.MessageChannel;
+
+import io.micrometer.core.instrument.Clock;
+import io.micrometer.core.instrument.util.HierarchicalNameMapper;
+import io.micrometer.jmx.JmxMeterRegistry;
/**
- * {@link EnableAutoConfiguration Auto-configuration} for writing metrics to a
- * {@link MessageChannel}.
- *
- * @author Dave Syer
* @since 2.0.0
+ * @author Jon Schneider
*/
@Configuration
-@ConditionalOnClass(MessageChannel.class)
-@ConditionalOnBean(name = "metricsChannel")
-@AutoConfigureBefore(MetricRepositoryAutoConfiguration.class)
-public class MetricsChannelAutoConfiguration {
+@ConditionalOnClass(name = "io.micrometer.jmx.JmxMeterRegistry")
+public class JmxExportConfiguration {
+ @ConditionalOnProperty(value = "metrics.jmx.enabled", matchIfMissing = true)
+ @Bean
+ public MetricsExporter jmxExporter(HierarchicalNameMapper nameMapper, Clock clock) {
+ return () -> new JmxMeterRegistry(nameMapper, clock);
+ }
- @Bean
- @ExportMetricWriter
- @ConditionalOnMissingBean
- public MessageChannelMetricWriter messageChannelMetricWriter(
- @Qualifier("metricsChannel") MessageChannel channel) {
- return new MessageChannelMetricWriter(channel);
- }
+ @ConditionalOnMissingBean
+ @Bean
+ public Clock clock() {
+ return Clock.SYSTEM;
+ }
+ @ConditionalOnMissingBean
+ @Bean
+ public HierarchicalNameMapper hierarchicalNameMapper() {
+ return HierarchicalNameMapper.DEFAULT;
+ }
}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/prometheus/PrometheusConfigurationProperties.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/prometheus/PrometheusConfigurationProperties.java
new file mode 100644
index 000000000000..077abf81205f
--- /dev/null
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/prometheus/PrometheusConfigurationProperties.java
@@ -0,0 +1,50 @@
+/**
+ * Copyright 2012-2017 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.metrics.export.prometheus;
+
+
+import org.springframework.boot.actuate.metrics.export.RegistryConfigurationProperties;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+import io.micrometer.prometheus.PrometheusConfig;
+
+/**
+ * Exists solely to aid in autocompletion of Prometheus enablement in .properties and .yml.
+ *
+ * @since 2.0.0
+ * @author Jon Schneider
+ */
+@ConfigurationProperties(prefix = "metrics.prometheus")
+public class PrometheusConfigurationProperties extends RegistryConfigurationProperties implements PrometheusConfig {
+ private boolean enabled = true;
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ public void setDescriptions(Boolean descriptions) {
+ set("descriptions", descriptions);
+ }
+
+ @Override
+ public String prefix() {
+ return "metrics.prometheus";
+ }
+}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/prometheus/PrometheusExportConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/prometheus/PrometheusExportConfiguration.java
new file mode 100644
index 000000000000..b4bdee1153db
--- /dev/null
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/prometheus/PrometheusExportConfiguration.java
@@ -0,0 +1,65 @@
+/**
+ * Copyright 2012-2017 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.metrics.export.prometheus;
+
+import org.springframework.boot.actuate.autoconfigure.ManagementContextConfiguration;
+import org.springframework.boot.actuate.metrics.export.MetricsExporter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import io.micrometer.core.instrument.Clock;
+import io.micrometer.prometheus.PrometheusConfig;
+import io.micrometer.prometheus.PrometheusMeterRegistry;
+import io.prometheus.client.CollectorRegistry;
+
+/**
+ * @since 2.0.0
+ * @author Jon Schneider
+ */
+@Configuration
+@ConditionalOnClass(name = "io.micrometer.prometheus.PrometheusMeterRegistry")
+@EnableConfigurationProperties(PrometheusConfigurationProperties.class)
+public class PrometheusExportConfiguration {
+ @ConditionalOnProperty(value = "metrics.prometheus.enabled", matchIfMissing = true)
+ @Bean
+ public MetricsExporter prometheusExporter(PrometheusConfig config, CollectorRegistry collectorRegistry, Clock clock) {
+ return () -> new PrometheusMeterRegistry(config, collectorRegistry, clock);
+ }
+
+ @ConditionalOnMissingBean
+ @Bean
+ public CollectorRegistry collectorRegistry() {
+ return new CollectorRegistry(true);
+ }
+
+ @ConditionalOnMissingBean
+ @Bean
+ public Clock clock() {
+ return Clock.SYSTEM;
+ }
+
+ @ManagementContextConfiguration
+ public static class PrometheusScrapeEndpointConfiguration {
+ @Bean
+ public PrometheusScrapeEndpoint prometheusEndpoint(CollectorRegistry collectorRegistry) {
+ return new PrometheusScrapeEndpoint(collectorRegistry);
+ }
+ }
+}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/prometheus/PrometheusScrapeEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/prometheus/PrometheusScrapeEndpoint.java
new file mode 100644
index 000000000000..9204f72bf3b8
--- /dev/null
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/prometheus/PrometheusScrapeEndpoint.java
@@ -0,0 +1,55 @@
+/**
+ * Copyright 2012-2017 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.metrics.export.prometheus;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+
+import org.springframework.boot.endpoint.Endpoint;
+import org.springframework.boot.endpoint.EndpointExposure;
+import org.springframework.boot.endpoint.ReadOperation;
+
+import io.prometheus.client.CollectorRegistry;
+import io.prometheus.client.exporter.common.TextFormat;
+
+/**
+ * @since 2.0.0
+ * @author Jon Schneider
+ *
+ * Spring Boot Actuator endpoint that outputs Prometheus metrics in a format that
+ * can be scraped by the Prometheus server
+ */
+@Endpoint(id = "prometheus", exposure = EndpointExposure.WEB)
+public class PrometheusScrapeEndpoint {
+ private final CollectorRegistry collectorRegistry;
+
+ PrometheusScrapeEndpoint(CollectorRegistry collectorRegistry) {
+ this.collectorRegistry = collectorRegistry;
+ }
+
+ @ReadOperation(produces = TextFormat.CONTENT_TYPE_004)
+ public String scrape() {
+ try {
+ Writer writer = new StringWriter();
+ TextFormat.write004(writer, collectorRegistry.metricFamilySamples());
+ return writer.toString();
+ } catch (IOException e) {
+ // This actually never happens since StringWriter::write() doesn't throw any IOException
+ throw new RuntimeException("Writing metrics failed", e);
+ }
+ }
+}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/GaugeBuffers.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/simple/SimpleConfigurationProperties.java
similarity index 53%
rename from spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/GaugeBuffers.java
rename to spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/simple/SimpleConfigurationProperties.java
index 6ed46231858a..ddf515369758 100644
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/GaugeBuffers.java
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/simple/SimpleConfigurationProperties.java
@@ -1,4 +1,4 @@
-/*
+/**
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,27 +13,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+package org.springframework.boot.actuate.metrics.export.simple;
+
-package org.springframework.boot.actuate.metrics.buffer;
+import org.springframework.boot.context.properties.ConfigurationProperties;
/**
- * Fast writes to in-memory metrics store using {@link GaugeBuffer}.
+ * Exists solely to aid in autocompletion of simple registry enablement in .properties and .yml.
*
- * @author Dave Syer
- * @since 1.3.0
+ * @author Jon Schneider
*/
-public class GaugeBuffers extends Buffers {
-
- public void set(String name, double value) {
- doWith(name, (buffer) -> {
- buffer.setTimestamp(System.currentTimeMillis());
- buffer.setValue(value);
- });
- }
+@ConfigurationProperties(prefix = "metrics.simple")
+public class SimpleConfigurationProperties {
+ private boolean enabled = true;
- @Override
- protected GaugeBuffer createBuffer() {
- return new GaugeBuffer(0L);
- }
+ public boolean isEnabled() {
+ return enabled;
+ }
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/simple/SimpleExportConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/simple/SimpleExportConfiguration.java
new file mode 100644
index 000000000000..6099e487ebf9
--- /dev/null
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/simple/SimpleExportConfiguration.java
@@ -0,0 +1,43 @@
+/**
+ * Copyright 2012-2017 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.metrics.export.simple;
+
+import org.springframework.boot.actuate.metrics.export.MetricsExporter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import io.micrometer.core.instrument.Clock;
+import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
+
+@Configuration
+@EnableConfigurationProperties(SimpleConfigurationProperties.class)
+public class SimpleExportConfiguration {
+ @ConditionalOnProperty(value = "metrics.simple.enabled", matchIfMissing = true)
+ @ConditionalOnMissingBean(MetricsExporter.class) // steps out of the way the moment any other monitoring system is configured
+ @Bean
+ public MetricsExporter simpleExporter(Clock clock) {
+ return () -> new SimpleMeterRegistry(clock);
+ }
+
+ @ConditionalOnMissingBean
+ @Bean
+ public Clock clock() {
+ return Clock.SYSTEM;
+ }
+}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetricReader.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetricReader.java
deleted file mode 100644
index cb3bffb186ae..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetricReader.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Copyright 2012-2017 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.metrics.integration;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.springframework.boot.actuate.metrics.Metric;
-import org.springframework.boot.actuate.metrics.reader.MetricReader;
-import org.springframework.integration.support.management.IntegrationManagementConfigurer;
-import org.springframework.integration.support.management.MessageChannelMetrics;
-import org.springframework.integration.support.management.MessageHandlerMetrics;
-import org.springframework.integration.support.management.MessageSourceMetrics;
-import org.springframework.integration.support.management.PollableChannelManagement;
-import org.springframework.integration.support.management.Statistics;
-
-/**
- * A {@link MetricReader} for Spring Integration metrics (as provided by
- * {@link IntegrationManagementConfigurer}).
- *
- * @author Dave Syer
- * @author Artem Bilan
- * @since 1.3.0
- */
-public class SpringIntegrationMetricReader implements MetricReader {
-
- private final IntegrationManagementConfigurer configurer;
-
- public SpringIntegrationMetricReader(IntegrationManagementConfigurer configurer) {
- this.configurer = configurer;
- }
-
- @Override
- public Metric> findOne(String metricName) {
- return null;
- }
-
- @Override
- public Iterable> findAll() {
- List> result = new ArrayList<>();
- String[] channelNames = this.configurer.getChannelNames();
- String[] handlerNames = this.configurer.getHandlerNames();
- String[] sourceNames = this.configurer.getSourceNames();
- addChannelMetrics(result, channelNames);
- addHandlerMetrics(result, handlerNames);
- addSourceMetrics(result, sourceNames);
- result.add(new Metric<>("integration.handlerCount", handlerNames.length));
- result.add(new Metric<>("integration.channelCount", channelNames.length));
- result.add(new Metric<>("integration.sourceCount", sourceNames.length));
- return result;
- }
-
- private void addChannelMetrics(List> result, String[] names) {
- for (String name : names) {
- addChannelMetrics(result, name, this.configurer.getChannelMetrics(name));
- }
- }
-
- private void addChannelMetrics(List> result, String name,
- MessageChannelMetrics metrics) {
- String prefix = "integration.channel." + name;
- result.addAll(getStatistics(prefix + ".errorRate", metrics.getErrorRate()));
- result.add(new Metric<>(prefix + ".sendCount", metrics.getSendCountLong()));
- result.addAll(getStatistics(prefix + ".sendRate", metrics.getSendRate()));
- if (metrics instanceof PollableChannelManagement) {
- result.add(new Metric<>(prefix + ".receiveCount",
- ((PollableChannelManagement) metrics).getReceiveCountLong()));
- }
- }
-
- private void addHandlerMetrics(List> result, String[] names) {
- for (String name : names) {
- addHandlerMetrics(result, name, this.configurer.getHandlerMetrics(name));
- }
- }
-
- private void addHandlerMetrics(List> result, String name,
- MessageHandlerMetrics metrics) {
- String prefix = "integration.handler." + name;
- result.addAll(getStatistics(prefix + ".duration", metrics.getDuration()));
- long activeCount = metrics.getActiveCountLong();
- result.add(new Metric<>(prefix + ".activeCount", activeCount));
- }
-
- private void addSourceMetrics(List> result, String[] names) {
- for (String name : names) {
- addSourceMetrics(result, name, this.configurer.getSourceMetrics(name));
- }
- }
-
- private void addSourceMetrics(List> result, String name,
- MessageSourceMetrics sourceMetrics) {
- String prefix = "integration.source." + name;
- result.add(new Metric<>(prefix + ".messageCount",
- sourceMetrics.getMessageCountLong()));
- }
-
- private Collection extends Metric>> getStatistics(String name, Statistics stats) {
- List> metrics = new ArrayList<>();
- metrics.add(new Metric<>(name + ".mean", stats.getMean()));
- metrics.add(new Metric<>(name + ".max", stats.getMax()));
- metrics.add(new Metric<>(name + ".min", stats.getMin()));
- metrics.add(new Metric<>(name + ".stdev", stats.getStandardDeviation()));
- metrics.add(new Metric<>(name + ".count", stats.getCountLong()));
- return metrics;
- }
-
- @Override
- public long count() {
- int totalChannelCount = this.configurer.getChannelNames().length;
- int totalHandlerCount = this.configurer.getHandlerNames().length;
- int totalSourceCount = this.configurer.getSourceNames().length;
- return totalChannelCount + totalHandlerCount + totalSourceCount;
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/integration/package-info.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/integration/package-info.java
deleted file mode 100644
index bfa7a446fe0f..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/integration/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2012-2017 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.
- */
-
-/**
- * Spring Integration metrics support.
- */
-package org.springframework.boot.actuate.metrics.integration;
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jmx/DefaultMetricNamingStrategy.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jmx/DefaultMetricNamingStrategy.java
deleted file mode 100644
index 45ddd1e36d55..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jmx/DefaultMetricNamingStrategy.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright 2012-2017 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.metrics.jmx;
-
-import java.util.Hashtable;
-
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-
-import org.springframework.jmx.export.naming.KeyNamingStrategy;
-import org.springframework.jmx.export.naming.ObjectNamingStrategy;
-import org.springframework.util.StringUtils;
-
-/**
- * MBean naming strategy for metric keys. A metric name of {@code counter.foo.bar.spam}
- * translates to an object name with {@code type=counter}, {@code name=foo} and
- * {@code value=bar.spam}. This results in a more or less pleasing view with no tweaks in
- * jconsole or jvisualvm. The domain is copied from the input key and the type in the
- * input key is discarded.
- *
- * @author Dave Syer
- * @since 1.3.0
- */
-public class DefaultMetricNamingStrategy implements ObjectNamingStrategy {
-
- private ObjectNamingStrategy namingStrategy = new KeyNamingStrategy();
-
- @Override
- public ObjectName getObjectName(Object managedBean, String beanKey)
- throws MalformedObjectNameException {
- ObjectName objectName = this.namingStrategy.getObjectName(managedBean, beanKey);
- String domain = objectName.getDomain();
- Hashtable table = new Hashtable<>(
- objectName.getKeyPropertyList());
- String name = objectName.getKeyProperty("name");
- if (name != null) {
- table.remove("name");
- String[] parts = StringUtils.delimitedListToStringArray(name, ".");
- table.put("type", parts[0]);
- if (parts.length > 1) {
- table.put(parts.length > 2 ? "name" : "value", parts[1]);
- }
- if (parts.length > 2) {
- table.put("value",
- name.substring(parts[0].length() + parts[1].length() + 2));
- }
- }
- return new ObjectName(domain, table);
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jmx/JmxMetricWriter.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jmx/JmxMetricWriter.java
deleted file mode 100644
index 9a0f271ea953..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jmx/JmxMetricWriter.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * Copyright 2012-2017 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.metrics.jmx;
-
-import java.util.Date;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.springframework.boot.actuate.metrics.Metric;
-import org.springframework.boot.actuate.metrics.writer.Delta;
-import org.springframework.boot.actuate.metrics.writer.MetricWriter;
-import org.springframework.jmx.export.MBeanExporter;
-import org.springframework.jmx.export.annotation.ManagedAttribute;
-import org.springframework.jmx.export.annotation.ManagedOperation;
-import org.springframework.jmx.export.annotation.ManagedResource;
-import org.springframework.jmx.export.naming.ObjectNamingStrategy;
-
-/**
- * A {@link MetricWriter} for MBeans. Each metric is registered as an individual MBean, so
- * (for instance) it can be graphed and monitored. The object names are provided by an
- * {@link ObjectNamingStrategy}, where the default is a
- * {@link DefaultMetricNamingStrategy} which provides {@code type}, {@code name} and
- * {@code value} keys by splitting up the metric name on periods.
- *
- * @author Dave Syer
- * @since 1.3.0
- */
-@ManagedResource(description = "MetricWriter for pushing metrics to JMX MBeans.")
-public class JmxMetricWriter implements MetricWriter {
-
- private static final Log logger = LogFactory.getLog(JmxMetricWriter.class);
-
- private final ConcurrentMap values = new ConcurrentHashMap<>();
-
- private final MBeanExporter exporter;
-
- private ObjectNamingStrategy namingStrategy = new DefaultMetricNamingStrategy();
-
- private String domain = "org.springframework.metrics";
-
- public JmxMetricWriter(MBeanExporter exporter) {
- this.exporter = exporter;
- }
-
- public void setNamingStrategy(ObjectNamingStrategy namingStrategy) {
- this.namingStrategy = namingStrategy;
- }
-
- public void setDomain(String domain) {
- this.domain = domain;
- }
-
- @ManagedOperation
- public void increment(String name, long value) {
- increment(new Delta<>(name, value));
- }
-
- @Override
- public void increment(Delta> delta) {
- MetricValue counter = getValue(delta.getName());
- counter.increment(delta.getValue().longValue());
- }
-
- @ManagedOperation
- public void set(String name, double value) {
- set(new Metric<>(name, value));
- }
-
- @Override
- public void set(Metric> value) {
- MetricValue metric = getValue(value.getName());
- metric.setValue(value.getValue().doubleValue());
- }
-
- @Override
- @ManagedOperation
- public void reset(String name) {
- MetricValue value = this.values.remove(name);
- if (value != null) {
- try {
- // We can unregister the MBean, but if this writer is on the end of an
- // Exporter the chances are it will be re-registered almost immediately.
- this.exporter.unregisterManagedResource(getName(name, value));
- }
- catch (MalformedObjectNameException ex) {
- logger.warn("Could not unregister MBean for " + name);
- }
- }
- }
-
- private MetricValue getValue(String name) {
- MetricValue value = this.values.get(name);
- if (value == null) {
- value = new MetricValue();
- MetricValue oldValue = this.values.putIfAbsent(name, value);
- if (oldValue != null) {
- value = oldValue;
- }
- try {
- this.exporter.registerManagedResource(value, getName(name, value));
- }
- catch (Exception ex) {
- // Could not register mbean, maybe just a race condition
- }
- }
- return value;
- }
-
- private ObjectName getName(String name, MetricValue value)
- throws MalformedObjectNameException {
- String key = String.format(this.domain + ":type=MetricValue,name=%s", name);
- return this.namingStrategy.getObjectName(value, key);
- }
-
- /**
- * A single metric value.
- */
- @ManagedResource
- public static class MetricValue {
-
- private double value;
-
- private long lastUpdated = 0;
-
- public void setValue(double value) {
- if (this.value != value) {
- this.lastUpdated = System.currentTimeMillis();
- }
- this.value = value;
- }
-
- public void increment(long value) {
- this.lastUpdated = System.currentTimeMillis();
- this.value += value;
- }
-
- @ManagedAttribute
- public double getValue() {
- return this.value;
- }
-
- @ManagedAttribute
- public Date getLastUpdated() {
- return new Date(this.lastUpdated);
- }
-
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jmx/package-info.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jmx/package-info.java
deleted file mode 100644
index af557de79930..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jmx/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2012-2015 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.
- */
-
-/**
- * Metrics integration with JMX.
- */
-package org.springframework.boot.actuate.metrics.jmx;
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/opentsdb/DefaultOpenTsdbNamingStrategy.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/opentsdb/DefaultOpenTsdbNamingStrategy.java
deleted file mode 100644
index abdd76fc99a8..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/opentsdb/DefaultOpenTsdbNamingStrategy.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright 2012-2017 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.metrics.opentsdb;
-
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import org.springframework.util.ObjectUtils;
-
-/**
- * A naming strategy that just passes through the metric name, together with tags from a
- * set of static values. Open TSDB requires at least one tag, so tags are always added for
- * you: the {@value #DOMAIN_KEY} key is added with a value "spring", and the
- * {@value #PROCESS_KEY} key is added with a value equal to the object hash of "this" (the
- * naming strategy). The "domain" value is a system identifier - it would be common to all
- * processes in the same distributed system. In most cases this will be unique enough to
- * allow aggregation of the underlying metrics in Open TSDB, but normally it is best to
- * provide your own tags, including a prefix and process identifier if you know one
- * (overwriting the default).
- *
- * @author Dave Syer
- * @since 1.3.0
- */
-public class DefaultOpenTsdbNamingStrategy implements OpenTsdbNamingStrategy {
-
- /**
- * The domain key.
- */
- public static final String DOMAIN_KEY = "domain";
-
- /**
- * The process key.
- */
- public static final String PROCESS_KEY = "process";
-
- /**
- * Tags to apply to every metric. Open TSDB requires at least one tag, so a "prefix"
- * tag is added for you by default.
- */
- private Map tags = new LinkedHashMap<>();
-
- private Map cache = new HashMap<>();
-
- public DefaultOpenTsdbNamingStrategy() {
- this.tags.put(DOMAIN_KEY, "org.springframework.metrics");
- this.tags.put(PROCESS_KEY, ObjectUtils.getIdentityHexString(this));
- }
-
- public void setTags(Map staticTags) {
- this.tags.putAll(staticTags);
- }
-
- @Override
- public OpenTsdbName getName(String name) {
- if (this.cache.containsKey(name)) {
- return this.cache.get(name);
- }
- OpenTsdbName value = new OpenTsdbName(name);
- value.setTags(this.tags);
- this.cache.put(name, value);
- return value;
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/opentsdb/OpenTsdbData.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/opentsdb/OpenTsdbData.java
deleted file mode 100644
index df216ab96548..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/opentsdb/OpenTsdbData.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright 2012-2015 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.metrics.opentsdb;
-
-import java.util.Map;
-
-/**
- * OpenTSDB Data.
- *
- * @author Dave Syer
- * @since 1.3.0
- */
-public class OpenTsdbData {
-
- private OpenTsdbName name;
-
- private Long timestamp;
-
- private Number value;
-
- protected OpenTsdbData() {
- this.name = new OpenTsdbName();
- }
-
- public OpenTsdbData(String metric, Number value) {
- this(metric, value, System.currentTimeMillis());
- }
-
- public OpenTsdbData(String metric, Number value, Long timestamp) {
- this(new OpenTsdbName(metric), value, timestamp);
- }
-
- public OpenTsdbData(OpenTsdbName name, Number value, Long timestamp) {
- this.name = name;
- this.value = value;
- this.timestamp = timestamp;
- }
-
- public String getMetric() {
- return this.name.getMetric();
- }
-
- public void setMetric(String metric) {
- this.name.setMetric(metric);
- }
-
- public Long getTimestamp() {
- return this.timestamp;
- }
-
- public void setTimestamp(Long timestamp) {
- this.timestamp = timestamp;
- }
-
- public Number getValue() {
- return this.value;
- }
-
- public void setValue(Number value) {
- this.value = value;
- }
-
- public Map getTags() {
- return this.name.getTags();
- }
-
- public void setTags(Map tags) {
- this.name.setTags(tags);
- }
-
-}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/opentsdb/OpenTsdbGaugeWriter.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/opentsdb/OpenTsdbGaugeWriter.java
deleted file mode 100644
index 576ffa20f5a3..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/opentsdb/OpenTsdbGaugeWriter.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * Copyright 2012-2017 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.metrics.opentsdb;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.springframework.boot.actuate.metrics.Metric;
-import org.springframework.boot.actuate.metrics.writer.GaugeWriter;
-import org.springframework.http.HttpEntity;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.MediaType;
-import org.springframework.http.ResponseEntity;
-import org.springframework.http.client.SimpleClientHttpRequestFactory;
-import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.web.client.RestOperations;
-import org.springframework.web.client.RestTemplate;
-
-/**
- * A {@link GaugeWriter} for the Open TSDB database (version 2.0), writing metrics to the
- * HTTP endpoint provided by the server. Data are buffered according to the
- * {@link #setBufferSize(int) bufferSize} property, and only flushed automatically when
- * the buffer size is reached. Users should either manually {@link #flush()} after writing
- * a batch of data if that makes sense, or consider adding a {@link Scheduled Scheduled}
- * task to flush periodically.
- *
- * @author Dave Syer
- * @author Thomas Badie
- * @since 1.3.0
- */
-public class OpenTsdbGaugeWriter implements GaugeWriter {
-
- private static final int DEFAULT_CONNECT_TIMEOUT = 10000;
-
- private static final int DEFAULT_READ_TIMEOUT = 30000;
-
- private static final Log logger = LogFactory.getLog(OpenTsdbGaugeWriter.class);
-
- private RestOperations restTemplate;
-
- /**
- * URL for POSTing data. Defaults to http://localhost:4242/api/put.
- */
- private String url = "http://localhost:4242/api/put";
-
- /**
- * Buffer size to fill before posting data to server.
- */
- private int bufferSize = 64;
-
- /**
- * The media type to use to serialize and accept responses from the server. Defaults
- * to "application/json".
- */
- private MediaType mediaType = MediaType.APPLICATION_JSON;
-
- private final List buffer = new ArrayList<>(this.bufferSize);
-
- private OpenTsdbNamingStrategy namingStrategy = new DefaultOpenTsdbNamingStrategy();
-
- /**
- * Creates a new {@code OpenTsdbGaugeWriter} with the default connect (10 seconds) and
- * read (30 seconds) timeouts.
- */
- public OpenTsdbGaugeWriter() {
- this(DEFAULT_CONNECT_TIMEOUT, DEFAULT_READ_TIMEOUT);
- }
-
- /**
- * Creates a new {@code OpenTsdbGaugeWriter} with the given millisecond
- * {@code connectTimeout} and {@code readTimeout}.
- * @param connectTimeout the connect timeout in milliseconds
- * @param readTimeout the read timeout in milliseconds
- */
- public OpenTsdbGaugeWriter(int connectTimeout, int readTimeout) {
- SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
- requestFactory.setConnectTimeout(connectTimeout);
- requestFactory.setReadTimeout(readTimeout);
- this.restTemplate = new RestTemplate(requestFactory);
- }
-
- public RestOperations getRestTemplate() {
- return this.restTemplate;
- }
-
- public void setRestTemplate(RestOperations restTemplate) {
- this.restTemplate = restTemplate;
- }
-
- public void setUrl(String url) {
- this.url = url;
- }
-
- public void setBufferSize(int bufferSize) {
- this.bufferSize = bufferSize;
- }
-
- public void setMediaType(MediaType mediaType) {
- this.mediaType = mediaType;
- }
-
- public void setNamingStrategy(OpenTsdbNamingStrategy namingStrategy) {
- this.namingStrategy = namingStrategy;
- }
-
- @Override
- public void set(Metric> value) {
- OpenTsdbData data = new OpenTsdbData(this.namingStrategy.getName(value.getName()),
- value.getValue(), value.getTimestamp().getTime());
- synchronized (this.buffer) {
- this.buffer.add(data);
- if (this.buffer.size() >= this.bufferSize) {
- flush();
- }
- }
- }
-
- /**
- * Flush the buffer without waiting for it to fill any further.
- */
- @SuppressWarnings("rawtypes")
- public void flush() {
- List snapshot = getBufferSnapshot();
- if (snapshot.isEmpty()) {
- return;
- }
- HttpHeaders headers = new HttpHeaders();
- headers.setAccept(Arrays.asList(this.mediaType));
- headers.setContentType(this.mediaType);
- ResponseEntity