From 6c057181671339b747bcf9642de8989a6e12ad77 Mon Sep 17 00:00:00 2001 From: Pierre-Alain RIVIERE <--global> Date: Sun, 9 Mar 2014 21:56:54 +0100 Subject: [PATCH 1/5] Fix graphite hostname checking --- .../java/fr/ippon/tatami/config/MetricsConfiguration.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/fr/ippon/tatami/config/MetricsConfiguration.java b/src/main/java/fr/ippon/tatami/config/MetricsConfiguration.java index 7afd96861..a39fc8d16 100644 --- a/src/main/java/fr/ippon/tatami/config/MetricsConfiguration.java +++ b/src/main/java/fr/ippon/tatami/config/MetricsConfiguration.java @@ -2,17 +2,21 @@ import com.yammer.metrics.HealthChecks; import com.yammer.metrics.reporting.GraphiteReporter; + import fr.ippon.tatami.config.metrics.CassandraHealthCheck; import fr.ippon.tatami.config.metrics.JavaMailHealthCheck; import fr.ippon.tatami.service.MailService; import me.prettyprint.hector.api.Keyspace; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; +import org.springframework.util.StringUtils; import javax.annotation.PostConstruct; import javax.inject.Inject; + import java.util.concurrent.TimeUnit; @Configuration @@ -37,7 +41,7 @@ public void initMetrics() { HealthChecks.register(new JavaMailHealthCheck(mailService)); String graphiteHost = env.getProperty("tatami.metrics.graphite.host"); - if (graphiteHost != null) { + if (!StringUtils.isEmpty(graphiteHost)) { log.debug("Initializing Metrics Graphite reporting"); Integer graphitePort = env.getProperty("tatami.metrics.graphite.port", Integer.class); GraphiteReporter.enable(1, From 4e711efc6c8cc5cdbf1c851f6b86025d4c6be7fa Mon Sep 17 00:00:00 2001 From: Pierre-Alain RIVIERE Date: Sun, 9 Mar 2014 23:04:11 +0100 Subject: [PATCH 2/5] Add support for pushing metrics to Riemann --- pom.xml | 12 ++++ .../tatami/config/MetricsConfiguration.java | 60 +++++++++++++++---- .../META-INF/tatami/tatami.properties | 3 + 3 files changed, 64 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index af20586ab..335ef5d6d 100755 --- a/pom.xml +++ b/pom.xml @@ -400,6 +400,9 @@ false 2003 + + 5555 + UTF-8 @@ -457,6 +460,10 @@ Sonatype Releases Repository http://oss.sonatype.org/content/repositories/releases/ + + clojars.org + http://clojars.org/repo + 3.0.0 @@ -788,6 +795,11 @@ rome ${rome.version} + + com.aphyr + riemann-java-client + 0.2.8 + diff --git a/src/main/java/fr/ippon/tatami/config/MetricsConfiguration.java b/src/main/java/fr/ippon/tatami/config/MetricsConfiguration.java index a39fc8d16..7874275e1 100644 --- a/src/main/java/fr/ippon/tatami/config/MetricsConfiguration.java +++ b/src/main/java/fr/ippon/tatami/config/MetricsConfiguration.java @@ -2,6 +2,8 @@ import com.yammer.metrics.HealthChecks; import com.yammer.metrics.reporting.GraphiteReporter; +import com.yammer.metrics.reporting.RiemannReporter; +import com.yammer.metrics.reporting.RiemannReporter.ConfigBuilder; import fr.ippon.tatami.config.metrics.CassandraHealthCheck; import fr.ippon.tatami.config.metrics.JavaMailHealthCheck; @@ -17,6 +19,10 @@ import javax.annotation.PostConstruct; import javax.inject.Inject; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; import java.util.concurrent.TimeUnit; @Configuration @@ -40,17 +46,49 @@ public void initMetrics() { HealthChecks.register(new CassandraHealthCheck(keyspaceOperator)); HealthChecks.register(new JavaMailHealthCheck(mailService)); - String graphiteHost = env.getProperty("tatami.metrics.graphite.host"); - if (!StringUtils.isEmpty(graphiteHost)) { - log.debug("Initializing Metrics Graphite reporting"); - Integer graphitePort = env.getProperty("tatami.metrics.graphite.port", Integer.class); - GraphiteReporter.enable(1, - TimeUnit.MINUTES, - graphiteHost, - graphitePort); - } else { - log.warn("Graphite server is not configured, unable to send any data to Graphite"); - } + initGraphite(); + initRiemann(); } } + + private void initGraphite() { + String graphiteHost = env.getProperty("tatami.metrics.graphite.host"); + if (!StringUtils.isEmpty(graphiteHost)) { + log.debug("Initializing Metrics Graphite reporting"); + Integer graphitePort = env.getProperty("tatami.metrics.graphite.port", Integer.class); + GraphiteReporter.enable(1, + TimeUnit.MINUTES, + graphiteHost, + graphitePort); + } else { + log.debug("Graphite server is not configured : disabling graphite reporting"); + } + } + + private void initRiemann() { + String riemannHost = env.getProperty("tatami.metrics.riemann.host"); + if (!StringUtils.isEmpty(riemannHost)) { + log.debug("Initializing Metrics Riemann reporting"); + + ConfigBuilder builder = RiemannReporter.Config.newBuilder(); + builder.host(riemannHost); + + Integer riemannPort = env.getProperty("tatami.metrics.riemann.port", Integer.class); + if (riemannPort != null) + builder.port(riemannPort); + + List tagsList = new ArrayList(); + tagsList.add("tatami"); + + String tags = env.getProperty("tatami.metrics.riemann.tags"); + if (!StringUtils.isEmpty(tags)) { + tagsList.addAll( Arrays.asList(tags.split(","))); + } + builder.tags(tagsList); + + RiemannReporter.enable(builder.build()); + } else { + log.debug("Riemann server is not configured : disabling riemann reporting"); + } + } } diff --git a/src/main/resources/META-INF/tatami/tatami.properties b/src/main/resources/META-INF/tatami/tatami.properties index 339426b48..db2c326ba 100755 --- a/src/main/resources/META-INF/tatami/tatami.properties +++ b/src/main/resources/META-INF/tatami/tatami.properties @@ -14,6 +14,9 @@ tatami.automatic.registration=${tatami.automatic.registration} #Monitoring using Yammer Metrics tatami.metrics.graphite.host=${tatami.metrics.graphite.host} tatami.metrics.graphite.port=${tatami.metrics.graphite.port} +tatami.metrics.riemann.host=${tatami.metrics.riemann.host} +tatami.metrics.riemann.port=${tatami.metrics.riemann.port} +tatami.metrics.riemann.tags=${tatami.metrics.riemann.tags} #User configuration tatami.admin.users=jdubois@ippon.fr,julien.dubois@gmail.com,vdebelil@ippon.fr,ggruel@ippon.fr From baf5e693c7ad6fead9c1923b3a2ba848ecd57abb Mon Sep 17 00:00:00 2001 From: Pierre-Alain RIVIERE Date: Mon, 17 Mar 2014 16:37:32 +0100 Subject: [PATCH 3/5] Metrics does not published everything if jmx-reporter is declared in XML file. NOTE : JmxReporter seems to be active by default even if jmx-reporter tag is not present --- .../resources/META-INF/spring/applicationContext-metrics.xml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/resources/META-INF/spring/applicationContext-metrics.xml b/src/main/resources/META-INF/spring/applicationContext-metrics.xml index 66ff2523b..e91884d2b 100644 --- a/src/main/resources/META-INF/spring/applicationContext-metrics.xml +++ b/src/main/resources/META-INF/spring/applicationContext-metrics.xml @@ -6,10 +6,8 @@ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd" profile="metrics"> - - + - \ No newline at end of file From c43c080585dc3797ce00d9addf8d18c4b3c2bac4 Mon Sep 17 00:00:00 2001 From: Pierre-Alain RIVIERE Date: Mon, 17 Mar 2014 16:41:01 +0100 Subject: [PATCH 4/5] Push metrics to the default MetricsRegistry. Should avoid creation of a specific MetricsRegistry. --- .../java/fr/ippon/tatami/config/MetricsConfiguration.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/fr/ippon/tatami/config/MetricsConfiguration.java b/src/main/java/fr/ippon/tatami/config/MetricsConfiguration.java index 7874275e1..064b9a79f 100644 --- a/src/main/java/fr/ippon/tatami/config/MetricsConfiguration.java +++ b/src/main/java/fr/ippon/tatami/config/MetricsConfiguration.java @@ -1,7 +1,10 @@ package fr.ippon.tatami.config; import com.yammer.metrics.HealthChecks; +import com.yammer.metrics.Metrics; +import com.yammer.metrics.core.MetricsRegistry; import com.yammer.metrics.reporting.GraphiteReporter; +import com.yammer.metrics.reporting.JmxReporter; import com.yammer.metrics.reporting.RiemannReporter; import com.yammer.metrics.reporting.RiemannReporter.ConfigBuilder; @@ -56,7 +59,7 @@ private void initGraphite() { if (!StringUtils.isEmpty(graphiteHost)) { log.debug("Initializing Metrics Graphite reporting"); Integer graphitePort = env.getProperty("tatami.metrics.graphite.port", Integer.class); - GraphiteReporter.enable(1, + GraphiteReporter.enable(Metrics.defaultRegistry(), 1, TimeUnit.MINUTES, graphiteHost, graphitePort); @@ -66,12 +69,14 @@ private void initGraphite() { } private void initRiemann() { + String riemannHost = env.getProperty("tatami.metrics.riemann.host"); if (!StringUtils.isEmpty(riemannHost)) { log.debug("Initializing Metrics Riemann reporting"); ConfigBuilder builder = RiemannReporter.Config.newBuilder(); builder.host(riemannHost); + builder.metricsRegistry(Metrics.defaultRegistry()); Integer riemannPort = env.getProperty("tatami.metrics.riemann.port", Integer.class); if (riemannPort != null) From fe1b55f2a543f82988ed5752d889652b58da53f4 Mon Sep 17 00:00:00 2001 From: Pierre-Alain RIVIERE Date: Mon, 17 Mar 2014 17:01:35 +0100 Subject: [PATCH 5/5] Allow to configuration Cassandra replication factor from tatami.properties --- .../fr/ippon/tatami/config/CassandraConfiguration.java | 9 +++++++++ src/main/resources/META-INF/tatami/tatami.properties | 1 + 2 files changed, 10 insertions(+) diff --git a/src/main/java/fr/ippon/tatami/config/CassandraConfiguration.java b/src/main/java/fr/ippon/tatami/config/CassandraConfiguration.java index 1d72b11df..2f2822415 100644 --- a/src/main/java/fr/ippon/tatami/config/CassandraConfiguration.java +++ b/src/main/java/fr/ippon/tatami/config/CassandraConfiguration.java @@ -54,6 +54,14 @@ public Keyspace keyspaceOperator() { String cassandraHost = env.getProperty("cassandra.host"); String cassandraClusterName = env.getProperty("cassandra.clusterName"); String cassandraKeyspace = env.getProperty("cassandra.keyspace"); + + int cassandraReplicationFactor = 1; + + try { + cassandraReplicationFactor = Integer.parseInt(env.getProperty("cassandra.replicationFactor")); + } catch (NumberFormatException nfe) { + log.warn("cassandra.replicationFactor property should contains a integer. Default to 1."); + } CassandraHostConfigurator cassandraHostConfigurator = new CassandraHostConfigurator(cassandraHost); cassandraHostConfigurator.setMaxActive(100); @@ -71,6 +79,7 @@ public Keyspace keyspaceOperator() { if (keyspaceDef == null) { log.warn("Keyspace \" {} \" does not exist, creating it!", cassandraKeyspace); keyspaceDef = new ThriftKsDef(cassandraKeyspace); + ((ThriftKsDef)keyspaceDef).setReplicationFactor(cassandraReplicationFactor); cluster.addKeyspace(keyspaceDef, true); addColumnFamily(cluster, USER_CF, 0); diff --git a/src/main/resources/META-INF/tatami/tatami.properties b/src/main/resources/META-INF/tatami/tatami.properties index db2c326ba..6ba621f0d 100755 --- a/src/main/resources/META-INF/tatami/tatami.properties +++ b/src/main/resources/META-INF/tatami/tatami.properties @@ -45,6 +45,7 @@ apple.push.password=${apple.push.password} cassandra.host=127.0.0.1:9160 cassandra.clusterName=Tatami cluster cassandra.keyspace=tatami +cassandra.replicationFactor=1 # Search engine configuration : you can use either Elastic Search in embedded or in remote mode # - In embedded mode, Elastic Search runs inside Tatami : this is useful for development, test, and small installations