Add JMX to Redis sample

pull/2938/merge
Dave Syer 10 years ago committed by Andy Wilkinson
parent 089b1d05dc
commit 0ce72105b9

@ -19,7 +19,7 @@ package sample.metrics.redis;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@ConfigurationProperties("metrics.export") @ConfigurationProperties("redis.metrics.export")
class ExportProperties { class ExportProperties {
private String prefix = "spring.metrics"; private String prefix = "spring.metrics";

@ -17,13 +17,15 @@
package sample.metrics.redis; package sample.metrics.redis;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.metrics.jmx.JmxMetricWriter;
import org.springframework.boot.actuate.metrics.repository.redis.RedisMetricRepository; import org.springframework.boot.actuate.metrics.repository.redis.RedisMetricRepository;
import org.springframework.boot.actuate.metrics.writer.MetricWriter;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.jmx.export.MBeanExporter;
@SpringBootApplication @SpringBootApplication
@EnableConfigurationProperties(ExportProperties.class) @EnableConfigurationProperties(ExportProperties.class)
@ -37,9 +39,16 @@ public class SampleRedisExportApplication {
} }
@Bean @Bean
public MetricWriter redisMetricWriter(RedisConnectionFactory connectionFactory) { public RedisMetricRepository redisMetricWriter(
RedisConnectionFactory connectionFactory) {
return new RedisMetricRepository(connectionFactory, this.export.getPrefix(), return new RedisMetricRepository(connectionFactory, this.export.getPrefix(),
this.export.getKey()); this.export.getKey());
} }
@Bean
public JmxMetricWriter jmxMetricWriter(
@Qualifier("mbeanExporter") MBeanExporter exporter) {
return new JmxMetricWriter(exporter);
}
} }

@ -1,3 +1,3 @@
service.name: Phil service.name: Phil
metrics.export.prefix: metrics.sample.${random.value:0000}.${spring.application.name:application} redis.metrics.export.prefix: metrics.sample.${random.value:0000}.${spring.application.name:application}
metrics.export.key: keys.metrics.sample redis.metrics.export.key: keys.metrics.sample

Loading…
Cancel
Save