Created
October 18, 2013 11:50
-
-
Save ms2scale/7040467 to your computer and use it in GitHub Desktop.
Diff to enable the conversion of boolean values to numeric 0 (false) or 1 (true) in the jmxtrans GraphiteWriter output model.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/com/googlecode/jmxtrans/model/output/GraphiteWriter.java b/src/com/googlecode/jmxtrans/model/output/GraphiteWriter.java | |
index 5d04014..ab52ca9 100644 | |
--- a/src/com/googlecode/jmxtrans/model/output/GraphiteWriter.java | |
+++ b/src/com/googlecode/jmxtrans/model/output/GraphiteWriter.java | |
@@ -155,7 +155,7 @@ public class GraphiteWriter extends BaseOutputWriter { | |
Map<String, Object> resultValues = result.getValues(); | |
if (resultValues != null) { | |
for (Entry<String, Object> values : resultValues.entrySet()) { | |
- Object value = values.getValue(); | |
+ Object value = convertToNumeric(values.getValue()); | |
if (JmxUtils.isNumeric(value)) { | |
StringBuilder sb = new StringBuilder(); | |
@@ -185,8 +185,18 @@ public class GraphiteWriter extends BaseOutputWriter { | |
pool.returnObject(address, socket); | |
} | |
} | |
- | |
- /** | |
+ | |
+ private Object convertToNumeric(Object value) { | |
+ if (value instanceof Boolean) { | |
+ Object newValue = Boolean.FALSE.equals(value) ? 0 : 1; | |
+ log.debug(String.format("Boolean value converted from %s to numeric %s", value, newValue)); | |
+ return newValue; | |
+ } else { | |
+ return value; | |
+ } | |
+ } | |
+ | |
+ /** | |
* Starts the pool and register it with JMX | |
* | |
* @throws LifecycleException |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment