Permalink
Browse files

Fixed non-int gauges in GangliaReporter.

  • Loading branch information...
1 parent 5e65c20 commit ae0ee1d7b6b0539aee03847b228f02df2868b16e @codahale codahale committed Feb 26, 2012
@@ -16,6 +16,7 @@ v2.1.0-SNAPSHOT
* Opened ``GraphiteReporter`` up for extension.
* Added ``group`` and ``type`` to ``metrics-annotations``, ``metrics-guice``, ``metrics-jersey``,
and ``metrics-spring``.
+* Fixed handling of non-int gauges in ``GangliaReporter``.
.. _rel-2.0.3:
@@ -32,6 +32,7 @@
private static final int GANGLIA_DMAX = 0;
private static final String GANGLIA_INT_TYPE = "int32";
private static final String GANGLIA_DOUBLE_TYPE = "double";
+ private static final String GANGLIA_STRING_TYPE = "string";
private final MetricPredicate predicate;
private final VirtualMachineMetrics vm;
private final Locale locale = Locale.US;
@@ -320,8 +321,20 @@ private void sendMetricData(String metricType, String metricName, String metricV
@Override
public void processGauge(MetricName name, Gauge<?> gauge, String x) throws IOException {
+ final Object value = gauge.value();
+ final Class<?> klass = value.getClass();
+
+ final String type;
+ if (klass == Integer.class || klass == Long.class) {
+ type = GANGLIA_INT_TYPE;
+ } else if (klass == Float.class || klass == Double.class) {
+ type = GANGLIA_DOUBLE_TYPE;
+ } else {
+ type = GANGLIA_STRING_TYPE;
+ }
+
sendToGanglia(sanitizeName(name),
- GANGLIA_INT_TYPE,
+ type,
String.format(locale, "%s", gauge.value()),
"gauge");
}
@@ -2,7 +2,7 @@ addInt(128)
addString(localhost)
addString(java.lang.Object.metric)
addInt(0)
-addString(int32)
+addString(string)
addString(java.lang.Object.metric)
addString()
addInt(3)

0 comments on commit ae0ee1d

Please sign in to comment.