Add @ActuatorMetricRepository to qualify the "native" repository
Primarily when it is needed for metric export.
This commit is contained in:
parent
2f2750e713
commit
270d5e3205
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* 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.autoconfigure;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
|
||||
/**
|
||||
* Qualifier annotation for a metric repository that is used by the actuator (to
|
||||
* distinguish it from others that might be installed by the user).
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@Qualifier
|
||||
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE,
|
||||
ElementType.ANNOTATION_TYPE })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Inherited
|
||||
@Documented
|
||||
public @interface ActuatorMetricRepository {
|
||||
|
||||
}
|
|
@ -21,7 +21,6 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.actuate.metrics.CounterService;
|
||||
import org.springframework.boot.actuate.metrics.GaugeService;
|
||||
import org.springframework.boot.actuate.metrics.buffer.BufferCounterService;
|
||||
|
@ -48,7 +47,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
|
@ -96,10 +94,11 @@ public class MetricRepositoryAutoConfiguration {
|
|||
|
||||
@Configuration
|
||||
@ConditionalOnJava(value = JavaVersion.EIGHT, range = Range.OLDER_THAN)
|
||||
@ConditionalOnMissingBean(MetricRepository.class)
|
||||
@ConditionalOnMissingBean(GaugeService.class)
|
||||
static class LegacyMetricServicesConfiguration {
|
||||
|
||||
@Autowired
|
||||
@ActuatorMetricRepository
|
||||
private MetricWriter writer;
|
||||
|
||||
@Bean
|
||||
|
@ -118,7 +117,7 @@ public class MetricRepositoryAutoConfiguration {
|
|||
|
||||
@Configuration
|
||||
@ConditionalOnJava(value = JavaVersion.EIGHT)
|
||||
@ConditionalOnMissingBean(MetricRepository.class)
|
||||
@ConditionalOnMissingBean(GaugeService.class)
|
||||
static class FastMetricServicesConfiguration {
|
||||
|
||||
@Bean
|
||||
|
@ -134,9 +133,9 @@ public class MetricRepositoryAutoConfiguration {
|
|||
}
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
@ActuatorMetricRepository
|
||||
@ConditionalOnMissingBean
|
||||
public BufferMetricReader metricReader(CounterBuffers counters,
|
||||
public BufferMetricReader actuatorMetricReader(CounterBuffers counters,
|
||||
GaugeBuffers gauges) {
|
||||
return new BufferMetricReader(counters, gauges);
|
||||
}
|
||||
|
@ -160,7 +159,7 @@ public class MetricRepositoryAutoConfiguration {
|
|||
static class LegacyMetricRepositoryConfiguration {
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
@ActuatorMetricRepository
|
||||
public InMemoryMetricRepository actuatorMetricRepository() {
|
||||
return new InMemoryMetricRepository();
|
||||
}
|
||||
|
@ -179,12 +178,13 @@ public class MetricRepositoryAutoConfiguration {
|
|||
private MetricExportProperties metrics;
|
||||
|
||||
@Autowired(required = false)
|
||||
@Qualifier("actuatorMetricRepository")
|
||||
@ActuatorMetricRepository
|
||||
private MetricWriter actuatorMetricRepository;
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public MetricExporters metricWritersMetricExporter(MetricReader reader) {
|
||||
public MetricExporters metricWritersMetricExporter(
|
||||
@ActuatorMetricRepository MetricReader reader) {
|
||||
Map<String, MetricWriter> writers = new HashMap<String, MetricWriter>(
|
||||
this.writers);
|
||||
if (this.actuatorMetricRepository != null
|
||||
|
|
|
@ -60,6 +60,7 @@ import org.springframework.context.annotation.Configuration;
|
|||
public class PublicMetricsAutoConfiguration {
|
||||
|
||||
@Autowired(required = false)
|
||||
@ActuatorMetricRepository
|
||||
private MetricReader metricReader = new InMemoryMetricRepository();
|
||||
|
||||
@Bean
|
||||
|
|
|
@ -62,8 +62,13 @@ public class MetricsEndpoint extends AbstractEndpoint<Map<String, Object>> {
|
|||
public Map<String, Object> invoke() {
|
||||
Map<String, Object> result = new LinkedHashMap<String, Object>();
|
||||
for (PublicMetrics publicMetric : this.publicMetrics) {
|
||||
for (Metric<?> metric : publicMetric.metrics()) {
|
||||
result.put(metric.getName(), metric.getValue());
|
||||
try {
|
||||
for (Metric<?> metric : publicMetric.metrics()) {
|
||||
result.put(metric.getName(), metric.getValue());
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Could not evaluate metrics
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
service.name: Phil
|
||||
redis.metrics.export.prefix: metrics.sample.${random.value:0000}.${spring.application.name:application}
|
||||
redis.metrics.export.key: keys.metrics.sample
|
||||
spring.jmx.default-domain: org.springframework.boot
|
||||
|
|
Loading…
Reference in New Issue