Add redis properties as convenience in spring.metrics.export
The redis export and aggregate use case is a lot nicer with this shared data between the two component types. Also made MetricExportProperties itself a Trigger (so the default delay etc. can be configured via spring.metrics.export.*).
This commit is contained in:
@@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.endpoint.MetricReaderPublicMetrics;
|
||||
import org.springframework.boot.actuate.endpoint.PublicMetrics;
|
||||
import org.springframework.boot.actuate.metrics.aggregate.AggregateMetricReader;
|
||||
import org.springframework.boot.actuate.metrics.export.MetricExportProperties;
|
||||
import org.springframework.boot.actuate.metrics.reader.MetricReader;
|
||||
import org.springframework.boot.actuate.metrics.repository.redis.RedisMetricRepository;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -33,7 +34,7 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
public class AggregateMetricsConfiguration {
|
||||
|
||||
@Autowired
|
||||
private ExportProperties export;
|
||||
private MetricExportProperties export;
|
||||
|
||||
@Autowired
|
||||
private RedisConnectionFactory connectionFactory;
|
||||
@@ -45,7 +46,7 @@ public class AggregateMetricsConfiguration {
|
||||
|
||||
private MetricReader globalMetricsForAggregation() {
|
||||
return new RedisMetricRepository(this.connectionFactory,
|
||||
this.export.getAggregatePrefix(), this.export.getKey());
|
||||
this.export.getRedis().getAggregatePrefix(), this.export.getRedis().getKey());
|
||||
}
|
||||
|
||||
private MetricReader aggregatesMetricReader() {
|
||||
|
||||
@@ -1,55 +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 sample.metrics.redis;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@ConfigurationProperties("redis.metrics.export")
|
||||
class ExportProperties {
|
||||
|
||||
private String prefix = "spring.metrics";
|
||||
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() {
|
||||
String[] tokens = StringUtils.delimitedListToStringArray(this.prefix, ".");
|
||||
if (tokens.length > 1) {
|
||||
if (StringUtils.hasText(tokens[1])) {
|
||||
// If the prefix has 2 or more non-trivial parts, use the first 1
|
||||
return tokens[0];
|
||||
}
|
||||
}
|
||||
return this.prefix;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,20 +19,19 @@ package sample.metrics.redis;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.actuate.metrics.export.MetricExportProperties;
|
||||
import org.springframework.boot.actuate.metrics.jmx.JmxMetricWriter;
|
||||
import org.springframework.boot.actuate.metrics.repository.redis.RedisMetricRepository;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.jmx.export.MBeanExporter;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableConfigurationProperties(ExportProperties.class)
|
||||
public class SampleRedisExportApplication {
|
||||
|
||||
@Autowired
|
||||
private ExportProperties export;
|
||||
private MetricExportProperties export;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SpringApplication.run(SampleRedisExportApplication.class, args);
|
||||
@@ -41,8 +40,8 @@ public class SampleRedisExportApplication {
|
||||
@Bean
|
||||
public RedisMetricRepository redisMetricWriter(
|
||||
RedisConnectionFactory connectionFactory) {
|
||||
return new RedisMetricRepository(connectionFactory, this.export.getPrefix(),
|
||||
this.export.getKey());
|
||||
return new RedisMetricRepository(connectionFactory, this.export.getRedis().getPrefix(),
|
||||
this.export.getRedis().getKey());
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -1,4 +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.metrics.export.redis.prefix: metrics.sample.${random.value:0000}.${spring.application.name:application}
|
||||
spring.metrics.export.redis.key: keys.metrics.sample
|
||||
spring.jmx.default-domain: org.springframework.boot
|
||||
|
||||
Reference in New Issue
Block a user