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

[activemq58] Proper prefix on service check #53

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<properties>
<commons-io.version>2.4</commons-io.version>
<commons-lang.version>2.6</commons-lang.version>
<guava.version>17.0</guava.version>
<java-dogstatsd-client.version>2.1.0</java-dogstatsd-client.version>
<jcommander.version>1.35</jcommander.version>
Expand Down Expand Up @@ -52,6 +53,11 @@
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>${commons-lang.version}</version>
</dependency>
<dependency>
<groupId>com.datadoghq</groupId>
<artifactId>java-dogstatsd-client</artifactId>
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/datadog/jmxfetch/reporter/Reporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.datadog.jmxfetch.App;
import org.datadog.jmxfetch.Instance;
import org.datadog.jmxfetch.JMXAttribute;
import org.apache.commons.lang.StringUtils;

import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -106,6 +107,16 @@ private void postProcessCassandra(HashMap<String, Object> metric) {
metric.put("alias", ((String) metric.get("alias")).replace("jmx.org.apache.", ""));
}

public static String formatDataName(String name){
String[] chunks = name.split("\\.");

// Escaping the prefix name
chunks[0] = chunks[0].replaceAll("[A-Z0-9:_\\-]", "");

// Putting the chunks together
return StringUtils.join(chunks, ".");
}

protected abstract void sendMetricPoint(String metricName, double value, String[] tags);

public abstract void sendServiceCheck(String checkName, String status, String message, String hostname, String[] tags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ public void sendServiceCheck(String checkName, String status, String message,
init();
}

ServiceCheck sc = new ServiceCheck(String.format("%s.can_connect", checkName),
this.statusToInt(status), message, hostname, tags);
String dataName = Reporter.formatDataName(String.format("%s.can_connect", checkName));
ServiceCheck sc = new ServiceCheck(dataName, this.statusToInt(status), message, hostname, tags);

statsDClient.serviceCheck(sc);
}

Expand Down
15 changes: 15 additions & 0 deletions src/test/java/org/datadog/jmxfetch/TestApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.apache.log4j.Level;
import org.datadog.jmxfetch.reporter.ConsoleReporter;
import org.datadog.jmxfetch.reporter.Reporter;
import org.datadog.jmxfetch.util.CustomLogger;
import org.junit.BeforeClass;
import org.junit.Test;
Expand Down Expand Up @@ -388,6 +389,20 @@ public void testServiceCheckCRITICAL() throws Exception {
mbs.unregisterMBean(objectName);
}

@Test
public void testPrefixFormatter() throws Exception {
// Let's get a list of Strings to test (add real versionned check names
// here when you add new versionned check)
String[][] data = {
{"activemq_58.foo.bar12", "activemq.foo.bar12"},
{"test_package-X86_64-VER1:0.weird.metric_name", "testpackage.weird.metric_name" }
};

// Let's test them all
for(int i=0; i<data.length; ++i)
assertEquals(data[i][1], Reporter.formatDataName(data[i][0]));
}

@Test
public void testApp() throws Exception {
// We expose a few metrics through JMX
Expand Down