Skip to content

Commit

Permalink
Add JMX to Redis sample
Browse files Browse the repository at this point in the history
  • Loading branch information
dsyer authored and wilkinsona committed May 13, 2015
1 parent 089b1d0 commit 0ce7210
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.StringUtils;

@ConfigurationProperties("metrics.export")
@ConfigurationProperties("redis.metrics.export")
class ExportProperties {

private String prefix = "spring.metrics";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
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.jmx.JmxMetricWriter;
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.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)
Expand All @@ -37,9 +39,16 @@ public static void main(String[] args) throws Exception {
}

@Bean
public MetricWriter redisMetricWriter(RedisConnectionFactory connectionFactory) {
public RedisMetricRepository redisMetricWriter(
RedisConnectionFactory connectionFactory) {
return new RedisMetricRepository(connectionFactory, this.export.getPrefix(),
this.export.getKey());
}

@Bean
public JmxMetricWriter jmxMetricWriter(
@Qualifier("mbeanExporter") MBeanExporter exporter) {
return new JmxMetricWriter(exporter);
}

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

0 comments on commit 0ce7210

Please sign in to comment.