private static GMetricType getType ( final Object obj ) { // FIXME This is far from covering all cases. // FIXME Wasteful use of high capacity types (eg Short => INT32) // Direct mapping when possible if ( obj instanceof Long || obj instanceof Integer || obj instanceof Byte || obj instanceof Short ) return GMetricType . INT32 ; if ( obj instanceof Float ) return GMetricType . FLOAT ; if ( obj instanceof Double ) return GMetricType . DOUBLE ; // Convert to double or int if possible try { Double . parseDouble ( obj . toString ( ) ) ; return GMetricType . DOUBLE ; } catch ( NumberFormatException e ) { // Not a double } try { Integer . parseInt ( obj . toString ( ) ) ; return GMetricType . UINT32 ; } catch ( NumberFormatException e ) { // Not an int } return GMetricType . STRING ; }
Guess the Ganglia gmetric type to use for a given object .