influxdata / telegraf

Agent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.
https://influxdata.com/telegraf
MIT License
14.59k stars 5.56k forks source link

Timestamp always results in seconds #5332

Closed asdptkt closed 5 years ago

asdptkt commented 5 years ago

Relevant telegraf.conf:

[global_tags]

[agent]
  interval = "5s"
  round_interval = true
  metric_batch_size = 1000
  metric_buffer_limit = 10000
  collection_jitter = "1s"
  flush_interval = "5s"
  flush_jitter = "1s"
  precision = "1ms"
  debug = false
  quiet = false
  logfile = ""
  hostname = ""
  omit_hostname = false

[[outputs.http]]
  url = "http://recorder:8080/v1/data"
  timeout = "5s"
  method = "POST"
  data_format = "json"

  [outputs.http.headers]
    Content-Type = "application/json"
    Authorization = "Bearer mytoken"

[[inputs.mqtt_consumer]]
  servers = ["tcp://mqtt:1883"]
  qos = 2
  connection_timeout = "5s"
  topics = [
    "$share/telegraf/data",
  ]
  persistent_session = true
  client_id = "admin"
  username = "admin"
  password = "admintoken"
  data_format = "json"
  tag_keys = [
    "id"
  ]

System info:

Telegraf 1.9.2-Alpine via Docker

Steps to reproduce:

Expected behavior:

Timestamp in milliseconds.

Actual behavior:

Timestamp in seconds.

Additional info:

I think this is parser problem because if I change the output data format to influx the resulting timestamp will be in nanoseconds.

danielnelson commented 5 years ago

You can use json_timestamp_units on the output data_format:

[[outputs.http]]
  url = "http://recorder:8080/v1/data"
  timeout = "5s"
  method = "POST"
  data_format = "json"
  json_timestamp_units = "1ms"

  [outputs.http.headers]
    Content-Type = "application/json"
    Authorization = "Bearer mytoken"
asdptkt commented 5 years ago

@danielnelson I think this should be added to the parser documentation.

danielnelson commented 5 years ago

Since converting to JSON is done in an output plugin, the data_format option is selecting the json serializer.