Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature riemann metrics #621

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,9 @@
<tatami.automatic.registration>false</tatami.automatic.registration>
<tatami.metrics.graphite.host></tatami.metrics.graphite.host>
<tatami.metrics.graphite.port>2003</tatami.metrics.graphite.port>
<tatami.metrics.riemann.host></tatami.metrics.riemann.host>
<tatami.metrics.riemann.port>5555</tatami.metrics.riemann.port>
<tatami.metrics.riemann.tags></tatami.metrics.riemann.tags>

<!-- Configuration -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -457,6 +460,10 @@
<name>Sonatype Releases Repository</name>
<url>http://oss.sonatype.org/content/repositories/releases/</url>
</repository>
<repository>
<id>clojars.org</id>
<url>http://clojars.org/repo</url>
</repository>
</repositories>
<prerequisites>
<maven>3.0.0</maven>
Expand Down Expand Up @@ -788,6 +795,11 @@
<artifactId>rome</artifactId>
<version>${rome.version}</version>
</dependency>
<dependency>
<groupId>com.aphyr</groupId>
<artifactId>riemann-java-client</artifactId>
<version>0.2.8</version>
</dependency>

<!-- Test dependencies -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
69 changes: 58 additions & 11 deletions src/main/java/fr/ippon/tatami/config/MetricsConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
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;

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.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.TimeUnit;

@Configuration
Expand All @@ -36,17 +49,51 @@ public void initMetrics() {
HealthChecks.register(new CassandraHealthCheck(keyspaceOperator));
HealthChecks.register(new JavaMailHealthCheck(mailService));

String graphiteHost = env.getProperty("tatami.metrics.graphite.host");
if (graphiteHost != null) {
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(Metrics.defaultRegistry(), 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);
builder.metricsRegistry(Metrics.defaultRegistry());

Integer riemannPort = env.getProperty("tatami.metrics.riemann.port", Integer.class);
if (riemannPort != null)
builder.port(riemannPort);

List<String> tagsList = new ArrayList<String>();
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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"
profile="metrics">

<metrics:metrics-registry id="metrics"/>
<metrics:health-check-registry id="health"/>

<metrics:annotation-driven proxy-target-class="true" health-check-registry="health" metrics-registry="metrics"/>
<metrics:annotation-driven proxy-target-class="true" health-check-registry="health"/>

<metrics:jmx-reporter id="metricsJmxReporter" metrics-registry="metrics"/>
</beans>
4 changes: 4 additions & 0 deletions src/main/resources/META-INF/tatami/tatami.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
[email protected],[email protected],[email protected],[email protected]
Expand Down Expand Up @@ -42,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
Expand Down