> 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 922292e85713..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.
- */
-
-/**
- * Actuator support for cache statistics.
- */
-package org.springframework.boot.actuate.cache;
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/DataSourcePublicMetrics.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/DataSourcePublicMetrics.java
deleted file mode 100644
index ade95e797560..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/DataSourcePublicMetrics.java
+++ /dev/null
@@ -1,127 +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.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.jdbc.metadata.DataSourcePoolMetadata;
-import org.springframework.boot.jdbc.metadata.DataSourcePoolMetadataProvider;
-import org.springframework.boot.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 2.0.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/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/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/MetricsEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/MetricsEndpoint.java
index 143fb2b5719f..6572573482c6 100644
--- 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
@@ -16,93 +16,100 @@
package org.springframework.boot.actuate.metrics;
-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 java.util.stream.Collectors;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
+
+import io.micrometer.core.instrument.Measurement;
+import io.micrometer.core.instrument.Meter;
+import io.micrometer.core.instrument.MeterRegistry;
+import io.micrometer.core.instrument.Statistic;
+import io.micrometer.core.instrument.util.HierarchicalNameMapper;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.annotation.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}.
+ * An {@link Endpoint} for exposing the metrics held by a {@link MeterRegistry}.
*
- * @author Dave Syer
+ * @author Jon Schneider
* @since 2.0.0
*/
@Endpoint(id = "metrics")
public class MetricsEndpoint {
- private final List publicMetrics;
+ private final MeterRegistry registry;
- /**
- * Create a new {@link MetricsEndpoint} instance.
- * @param publicMetrics the metrics to expose
- */
- public MetricsEndpoint(PublicMetrics publicMetrics) {
- this(Collections.singleton(publicMetrics));
+ public MetricsEndpoint(MeterRegistry registry) {
+ this.registry = registry;
}
- /**
- * 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);
+ @ReadOperation
+ public Map> listNames() {
+ return Collections.singletonMap("names", this.registry.getMeters().stream()
+ .map(this::getMeterIdName).collect(Collectors.toList()));
}
- public void registerPublicMetrics(PublicMetrics metrics) {
- this.publicMetrics.add(metrics);
- AnnotationAwareOrderComparator.sort(this.publicMetrics);
+ private String getMeterIdName(Meter meter) {
+ return meter.getId().getName();
}
- public void unregisterPublicMetrics(PublicMetrics metrics) {
- this.publicMetrics.remove(metrics);
+ @ReadOperation
+ public Map> metric(
+ @Selector String requiredMetricName) {
+ return this.registry.find(requiredMetricName).meters().stream()
+ .collect(Collectors.toMap(this::getHierarchicalName, this::getSamples));
}
- @ReadOperation
- public Map metrics(String pattern) {
- return metrics(StringUtils.hasText(pattern)
- ? Pattern.compile(pattern).asPredicate() : (name) -> true);
+ private List getSamples(Meter meter) {
+ return stream(meter.measure()).map(this::getSample).collect(Collectors.toList());
}
- @ReadOperation
- public Map metricNamed(@Selector String requiredName) {
- Map metrics = metrics((name) -> name.equals(requiredName));
- if (metrics.isEmpty()) {
- return null;
- }
- return metrics;
+ private MeasurementSample getSample(Measurement measurement) {
+ return new MeasurementSample(measurement.getStatistic(), measurement.getValue());
+ }
+
+ private String getHierarchicalName(Meter meter) {
+ return HierarchicalNameMapper.DEFAULT.toHierarchicalName(meter.getId());
+ }
+
+ private Stream stream(Iterable measure) {
+ return StreamSupport.stream(measure.spliterator(), false);
}
- 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
- }
+ /**
+ * A measurement sample combining a {@link Statistic statistic} and a value.
+ */
+ static class MeasurementSample {
+
+ private final Statistic statistic;
+
+ private final Double value;
+
+ MeasurementSample(Statistic statistic, Double value) {
+ this.statistic = statistic;
+ this.value = value;
}
- return result;
+
+ public Statistic getStatistic() {
+ return this.statistic;
+ }
+
+ public Double getValue() {
+ return this.value;
+ }
+
+ @Override
+ public String toString() {
+ return "MeasurementSample{" + "statistic=" + this.statistic + ", value="
+ + this.value + '}';
+ }
+
}
}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/SystemPublicMetrics.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/SystemPublicMetrics.java
deleted file mode 100644
index 848915f7e645..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/SystemPublicMetrics.java
+++ /dev/null
@@ -1,193 +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.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.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 2.0.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/metrics/TomcatPublicMetrics.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/TomcatPublicMetrics.java
deleted file mode 100644
index 9c9b1264be6b..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/TomcatPublicMetrics.java
+++ /dev/null
@@ -1,96 +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.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.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 2.0.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/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/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/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/GaugeBuffers.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/GaugeBuffers.java
deleted file mode 100644
index 6ed46231858a..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/GaugeBuffers.java
+++ /dev/null
@@ -1,39 +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 GaugeBuffer}.
- *
- * @author Dave Syer
- * @since 1.3.0
- */
-public class GaugeBuffers extends Buffers {
-
- public void set(String name, double value) {
- doWith(name, (buffer) -> {
- buffer.setTimestamp(System.currentTimeMillis());
- buffer.setValue(value);
- });
- }
-
- @Override
- protected GaugeBuffer createBuffer() {
- return new GaugeBuffer(0L);
- }
-
-}
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/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/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/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/SpecificTriggerProperties.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/SpecificTriggerProperties.java
deleted file mode 100644
index 0b291dbb9ed2..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/SpecificTriggerProperties.java
+++ /dev/null
@@ -1,40 +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;
-
-/**
- * Trigger for specific names or patterns.
- *
- * @author Dave Syer
- * @since 1.3.0
- */
-public class SpecificTriggerProperties extends TriggerProperties {
-
- /**
- * 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;
- }
-
-}
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/package-info.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/package-info.java
deleted file mode 100644
index 2a0ab81c8095..000000000000
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/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 export support.
- */
-package org.springframework.boot.actuate.metrics.export;
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..1d914e648e72
--- /dev/null
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/prometheus/PrometheusScrapeEndpoint.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.prometheus;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+
+import io.prometheus.client.CollectorRegistry;
+import io.prometheus.client.exporter.common.TextFormat;
+
+import org.springframework.boot.actuate.endpoint.EndpointExposure;
+import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
+import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
+
+/**
+ * {@link Endpoint} that outputs metrics in a format that can be scraped by the Prometheus
+ * server.
+ *
+ * @author Jon Schneider
+ * @since 2.0.0
+ */
+@Endpoint(id = "prometheus", exposure = EndpointExposure.WEB)
+public class PrometheusScrapeEndpoint {
+
+ private final CollectorRegistry collectorRegistry;
+
+ public PrometheusScrapeEndpoint(CollectorRegistry collectorRegistry) {
+ this.collectorRegistry = collectorRegistry;
+ }
+
+ @ReadOperation(produces = TextFormat.CONTENT_TYPE_004)
+ public String scrape() {
+ try {
+ Writer writer = new StringWriter();
+ TextFormat.write004(writer, this.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/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/SpringIntegrationMetrics.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetrics.java
new file mode 100644
index 000000000000..3fb677d1d1b6
--- /dev/null
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetrics.java
@@ -0,0 +1,201 @@
+/*
+ * 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.Collections;
+import java.util.concurrent.TimeUnit;
+
+import io.micrometer.core.instrument.Meter.Id;
+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;
+
+import org.springframework.beans.factory.SmartInitializingSingleton;
+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;
+
+/**
+ * A {@link MeterBinder} for Spring Integration metrics.
+ *
+ * @author Jon Schneider
+ * @since 2.0.0
+ */
+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, Collections.emptyList());
+ }
+
+ public SpringIntegrationMetrics(IntegrationManagementConfigurer configurer,
+ Iterable tags) {
+ this.configurer = configurer;
+ this.tags = tags;
+ }
+
+ @Override
+ public void bindTo(MeterRegistry registry) {
+ bindChannelNames(registry);
+ bindHandlerNames(registry);
+ bindSourceNames(registry);
+ this.registries.add(registry);
+ }
+
+ private void bindChannelNames(MeterRegistry registry) {
+ Id id = registry.createId("spring.integration.channelNames", this.tags,
+ "The number of spring integration channels");
+ registry.gauge(id, this.configurer, (c) -> c.getChannelNames().length);
+ }
+
+ private void bindHandlerNames(MeterRegistry registry) {
+ Id id = registry.createId("spring.integration.handlerNames", this.tags,
+ "The number of spring integration handlers");
+ registry.gauge(id, this.configurer, (c) -> c.getHandlerNames().length);
+ }
+
+ private void bindSourceNames(MeterRegistry registry) {
+ Id id = registry.createId("spring.integration.sourceNames", this.tags,
+ "The number of spring integration sources");
+ registry.gauge(id, this.configurer, (c) -> c.getSourceNames().length);
+ }
+
+ private void addSourceMetrics(MeterRegistry registry) {
+ for (String sourceName : this.configurer.getSourceNames()) {
+ addSourceMetrics(registry, sourceName);
+ }
+ }
+
+ private void addSourceMetrics(MeterRegistry registry, String sourceName) {
+ MessageSourceMetrics sourceMetrics = this.configurer.getSourceMetrics(sourceName);
+ Iterable tags = Tags.concat(this.tags, "source", sourceName);
+ Id id = registry.createId("spring.integration.source.messages", tags,
+ "The number of successful handler calls");
+ registry.more().counter(id, sourceMetrics, MessageSourceMetrics::getMessageCount);
+ }
+
+ private void addHandlerMetrics(MeterRegistry registry) {
+ for (String handler : this.configurer.getHandlerNames()) {
+ addHandlerMetrics(registry, handler);
+ }
+ }
+
+ private void addHandlerMetrics(MeterRegistry registry, String handler) {
+ MessageHandlerMetrics handlerMetrics = this.configurer.getHandlerMetrics(handler);
+ // FIXME could use improvement to dynamically compute the handler name with its
+ // ID, which can change after
+ // creation as shown in the SpringIntegrationApplication sample.
+ Iterable tags = Tags.concat(this.tags, "handler", handler);
+ addDurationMax(registry, handlerMetrics, tags);
+ addDurationMin(registry, handlerMetrics, tags);
+ addDurationMean(registry, handlerMetrics, tags);
+ addActiveCount(registry, handlerMetrics, tags);
+ }
+
+ private void addDurationMax(MeterRegistry registry,
+ MessageHandlerMetrics handlerMetrics, Iterable tags) {
+ Id id = registry.createId("spring.integration.handler.duration.max", tags,
+ "The maximum handler duration");
+ registry.more().timeGauge(id, handlerMetrics, TimeUnit.MILLISECONDS,
+ MessageHandlerMetrics::getMaxDuration);
+ }
+
+ private void addDurationMin(MeterRegistry registry,
+ MessageHandlerMetrics handlerMetrics, Iterable tags) {
+ Id id = registry.createId("spring.integration.handler.duration.min", tags,
+ "The minimum handler duration");
+ registry.more().timeGauge(id, handlerMetrics, TimeUnit.MILLISECONDS,
+ MessageHandlerMetrics::getMinDuration);
+ }
+
+ private void addDurationMean(MeterRegistry registry,
+ MessageHandlerMetrics handlerMetrics, Iterable tags) {
+ Id id = registry.createId("spring.integration.handler.duration.mean", tags,
+ "The mean handler duration");
+ registry.more().timeGauge(id, handlerMetrics, TimeUnit.MILLISECONDS,
+ MessageHandlerMetrics::getMeanDuration);
+ }
+
+ private void addActiveCount(MeterRegistry registry,
+ MessageHandlerMetrics handlerMetrics, Iterable tags) {
+ Id id = registry.createId("spring.integration.handler.activeCount", tags,
+ "The number of active handlers");
+ registry.gauge(id, handlerMetrics, MessageHandlerMetrics::getActiveCount);
+ }
+
+ private void addChannelMetrics(MeterRegistry registry) {
+ for (String channel : this.configurer.getChannelNames()) {
+ addChannelMetrics(registry, channel);
+ }
+ }
+
+ private void addChannelMetrics(MeterRegistry registry, String channel) {
+ Iterable tags = Tags.concat(this.tags, "channel", channel);
+ MessageChannelMetrics channelMetrics = this.configurer.getChannelMetrics(channel);
+ addSendErrors(registry, tags, channelMetrics);
+ addChannelSends(registry, tags, channelMetrics);
+ if (channelMetrics instanceof PollableChannelManagement) {
+ addReceives(registry, tags, channelMetrics);
+ }
+ }
+
+ private void addSendErrors(MeterRegistry registry, Iterable tags,
+ MessageChannelMetrics channelMetrics) {
+ Id id = registry.createId("spring.integration.channel.sendErrors", tags,
+ "The number of failed sends (either throwing an exception or "
+ + "rejected by the channel)");
+ registry.more().counter(id, channelMetrics,
+ MessageChannelMetrics::getSendErrorCount);
+ }
+
+ private void addReceives(MeterRegistry registry, Iterable tags,
+ MessageChannelMetrics channelMetrics) {
+ Id id = registry.createId("spring.integration.channel.receives", tags,
+ "The number of messages received");
+ registry.more().counter(id, (PollableChannelManagement) channelMetrics,
+ PollableChannelManagement::getReceiveCount);
+ }
+
+ private void addChannelSends(MeterRegistry registry, Iterable tags,
+ MessageChannelMetrics channelMetrics) {
+ Id id = registry.createId("spring.integration.channel.sends", tags,
+ "The number of successful sends");
+ registry.more().counter(id, channelMetrics, MessageChannelMetrics::getSendCount);
+ }
+
+ @Override
+ public void afterSingletonsInstantiated() {
+ // FIXME better would be to use a BeanPostProcessor
+ this.configurer.afterSingletonsInstantiated();
+ this.registries.forEach((registry) -> {
+ addChannelMetrics(registry);
+ addHandlerMetrics(registry);
+ addSourceMetrics(registry);
+ });
+ }
+
+}
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/jdbc/DataSourcePoolMetrics.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetrics.java
new file mode 100644
index 000000000000..f958006b528d
--- /dev/null
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetrics.java
@@ -0,0 +1,122 @@
+/*
+ * 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.jdbc;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.function.Function;
+
+import javax.sql.DataSource;
+
+import io.micrometer.core.instrument.MeterRegistry;
+import io.micrometer.core.instrument.Tag;
+import io.micrometer.core.instrument.binder.MeterBinder;
+
+import org.springframework.boot.jdbc.metadata.CompositeDataSourcePoolMetadataProvider;
+import org.springframework.boot.jdbc.metadata.DataSourcePoolMetadata;
+import org.springframework.boot.jdbc.metadata.DataSourcePoolMetadataProvider;
+import org.springframework.util.Assert;
+import org.springframework.util.ConcurrentReferenceHashMap;
+
+/**
+ * A {@link MeterBinder} for a {@link DataSource}.
+ *
+ * @author Jon Schneider
+ * @author Phillip Webb
+ * @since 2.0.0
+ */
+public class DataSourcePoolMetrics implements MeterBinder {
+
+ private final DataSource dataSource;
+
+ private final CachingDataSourcePoolMetadataProvider metadataProvider;
+
+ private final String name;
+
+ private final Iterable tags;
+
+ public DataSourcePoolMetrics(DataSource dataSource,
+ Collection metadataProviders, String name,
+ Iterable tags) {
+ this(dataSource, new CompositeDataSourcePoolMetadataProvider(metadataProviders),
+ name, tags);
+ }
+
+ public DataSourcePoolMetrics(DataSource dataSource,
+ DataSourcePoolMetadataProvider metadataProvider, String name,
+ Iterable tags) {
+ Assert.notNull(dataSource, "DataSource must not be null");
+ Assert.notNull(metadataProvider, "MetadataProvider must not be null");
+ this.dataSource = dataSource;
+ this.metadataProvider = new CachingDataSourcePoolMetadataProvider(dataSource,
+ metadataProvider);
+ this.name = name;
+ this.tags = tags;
+ }
+
+ @Override
+ public void bindTo(MeterRegistry registry) {
+ if (this.metadataProvider.getDataSourcePoolMetadata(this.dataSource) != null) {
+ bindPoolMetadata(registry, "active", DataSourcePoolMetadata::getActive);
+ bindPoolMetadata(registry, "max", DataSourcePoolMetadata::getMax);
+ bindPoolMetadata(registry, "min", DataSourcePoolMetadata::getMin);
+ }
+ }
+
+ private void bindPoolMetadata(MeterRegistry registry, String name,
+ Function function) {
+ bindDataSource(registry, name, this.metadataProvider.getValueFunction(function));
+ }
+
+ private void bindDataSource(MeterRegistry registry, String name,
+ Function function) {
+ if (function.apply(this.dataSource) != null) {
+ registry.gauge(this.name + "." + name + ".connections", this.tags,
+ this.dataSource, (m) -> function.apply(m).doubleValue());
+ }
+ }
+
+ private static class CachingDataSourcePoolMetadataProvider
+ implements DataSourcePoolMetadataProvider {
+
+ private static final Map cache = new ConcurrentReferenceHashMap<>();
+
+ private final DataSourcePoolMetadataProvider metadataProvider;
+
+ CachingDataSourcePoolMetadataProvider(DataSource dataSource,
+ DataSourcePoolMetadataProvider metadataProvider) {
+ this.metadataProvider = metadataProvider;
+ }
+
+ public Function getValueFunction(
+ Function function) {
+ return (dataSource) -> function.apply(getDataSourcePoolMetadata(dataSource));
+ }
+
+ @Override
+ public DataSourcePoolMetadata getDataSourcePoolMetadata(DataSource dataSource) {
+ DataSourcePoolMetadata metadata = cache.get(dataSource);
+ if (metadata == null) {
+ metadata = this.metadataProvider.getDataSourcePoolMetadata(dataSource);
+ cache.put(dataSource, metadata);
+ }
+ return metadata;
+ }
+
+ }
+
+}
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