jmxtrans / jmxtrans-agent

Java Agent based JMX metrics exporter.
MIT License
178 stars 110 forks source link

Float values causes agent to crash when sent via InfluxDbOutputWriter #91

Closed GitImpulseIt closed 7 years ago

GitImpulseIt commented 7 years ago

Hello Guys,

I encountered a problem with the InfluxDbOutputWriter. The floating point metrics, for example : java.lang:type=OperatingSystem > ProcessCpuLoad causes jmxtrans-agent to crash.

Try this : <query objectName="java.lang:type=OperatingSystem" attribute="ProcessCpuLoad" resultAlias="ProcessCpuLoad"/>

You will obtain : WARNING [jmxtrans-agent-1] org.jmxtrans.agent.JmxTransExporter - Ignore exception flushing metrics java.lang.RuntimeException: Failed to write metrics, response code: 400, response message: Bad Request ...

My environment : jmxtrans-agent : 1.2.4 InfluxDB : 1.1 Tomcat : 7.0.73 JRE : Oracle 1.8.0_72-b15

Thank you for your help

cyrille-leclerc commented 7 years ago

Hello @BriacRONDI , I just discover your message, I had a notification issue.

Could you capture more details? I suspect that InfluxMetric.valueAsStr() could be more strict about float / decimal conversions. I see a risk with the locale of the JVM where valueAsStr() could emit a "," instead of a ".".

cyrille-leclerc commented 7 years ago

I have identified a potential issue: big float values in java get formatted with an exponent

float value = 123_456_789.012_345;
System.out.println("value: " + value);

will return 1.23456789012345E8

See https://github.com/jmxtrans/jmxtrans-agent/pull/95

cyrille-leclerc commented 7 years ago

@kerlandsson can I get your feedback on this issue and on my PR #95 ? I suspect that we should be more strict than invoking Float.toString() to format floats.

I found in the official java client https://github.com/influxdata/influxdb-java/blob/influxdb-java-2.5/src/main/java/org/influxdb/dto/Point.java#L321

NumberFormat numberFormat = NumberFormat.getInstance(Locale.ENGLISH);
numberFormat.setMaximumFractionDigits(MAX_FRACTION_DIGITS);
numberFormat.setGroupingUsed(false);
numberFormat.setMinimumFractionDigits(1);
GitImpulseIt commented 7 years ago

Thank you for working on this issue. I will test your PR as soon as possible and will give you a feedback.

cyrille-leclerc commented 7 years ago

According to https://github.com/influxdata/influxdb-java/blob/influxdb-java-2.5/src/main/java/org/influxdb/dto/Point.java#L321

The expected string for 123_456_789.012_345 is 123456789.012345 and is NOT 1.23456789012345E8 as we generate today.

cyrille-leclerc commented 7 years ago

Fix should be ready at #95