davidB / metrics-influxdb

A reporter for metrics which announces measurements to an InfluxDB server.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Timestamp issue with InfluxDB 0.9

cemo opened this issue · comments

Hey, thanks for the library.

The documention of InfluxDB states a timestamp:

The timestamp - supplied at the end of the line in Unix time in nanoseconds 
since January 1, 1970 UTC - is optional. If you do not specify a timestamp InfluxDB 
uses the server’s local nanosecond timestamp in Unix epoch. Anything that has to 
do with time in InfluxDB is always UTC.

However MeasurementReporter is using getTime which is equals to System.currentTimeMillis. Am I missing something?

A quick fix might be adding precision to url. I have added precision=ms below in HttpInlinerSender.

        try {
            if (protocol.isSecured()) {
                toJoin = new URL("http", protocol.getHost(), protocol.getPort(), "/write?&precision=ms&db=" + Miscellaneous.urlEncode(protocol.getDatabase()) + "&u="
                        + Miscellaneous.urlEncode(protocol.getUser()) + "&p=" + Miscellaneous.urlEncode(protocol.getPassword()));
            } else {
                toJoin = new URL("http", protocol.getHost(), protocol.getPort(), "/write?precision=ms&db=" + Miscellaneous.urlEncode(protocol.getDatabase()));
            }
        } catch (MalformedURLException | UnsupportedEncodingException e) {
            toJoin = null;
        }

I missed this ticket, sorry