Skip to content

Commit

Permalink
[activemq58] Proper prefix on service check
Browse files Browse the repository at this point in the history
I hacked the StatsDReporter to send the status of activemq.can_connect
instead of activemq_58.can_connect.

It's a bit better than a simple Hack. We decided that the prefix name
shouldn't contain any number, underscore or capital letter (should we
add the dash to this list ?). This way we can have version dependant
configuration in the .yaml config files for JMXFetch without having
multiple and dirty metrics and service check names in the HQ.
  • Loading branch information
Etienne LAFARGE committed Apr 22, 2015
1 parent 56d092f commit 7218b33
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/main/java/org/datadog/jmxfetch/reporter/StatsdReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected void sendMetricPoint(String metricName, double value, String[] tags) {
this.statsDClient.stop();
init();
}
statsDClient.gauge(metricName, value, tags);
statsDClient.gauge(StatsdReporter.formatDataName(metricName), value, tags);
}

private int statusToInt(String status) {
Expand All @@ -50,11 +50,29 @@ 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);
//ActiveMQ > 5.8 hack
String dataName = StatsdReporter.formatDataName(String.format("%s.can_connect", checkName));
ServiceCheck sc = new ServiceCheck(dataName, this.statusToInt(status), message, hostname, tags);

statsDClient.serviceCheck(sc);
}

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 (there's nothing in the standard library to do that :o )
String res = "";
for(int i = 0; i < chunks.length; ++i){
if(i > 0)
res += ".";
res += chunks[i];
}
return res;
}

public void displayMetricReached() {
throw new UnsupportedOperationException();
}
Expand Down

0 comments on commit 7218b33

Please sign in to comment.