Hello
I hope using my timestamp in my data for metics’ time . At the same time, using the system time when the data was received ,the system time will be a tag or a field .
I parse my json message by “json_v2”
please help me how to set the telegraf.conf or which plugins should I use?
Hello @liuyang0716,
It depends on your json. Can you please share it?
By default the file plugin (with the json format) will write the system time when data was recieved as the timestamp if NOTHING is specified for:
json_time_key = ""
If you have another timestamp in the json data from when the metric was collected, then you can include it as another tag in the following option:
tag_keys = [
"my_tag_1",
"my_tag_2"
]
Thanks for your reply.this is my json :{“fId”:125,“time”:1632968483,“items”:[{“n”:“T_125_0”,“v”:8.915515060884404}]}
I have setted the json_time_key like this :
[[inputs.mqtt_consumer.json_v2]]
measurement_name = “test_warning”
timestamp_path = “time”
timestamp_format = “unix”
timestamp_timezone = “Asia/Shanghai”
[[inputs.mqtt_consumer.json_v2.object]]
disable_prepend_keys = true
path = “@this”
included_keys = [
“fId”,
“items_n”,
“items_v”
]
tags = [“fId”, “items_n”]
and I also need create a new field to record the system time .over the documentation , I found processors.starlark , like this:
[[processors.starlark]]
order = 1
source = ‘’’
def apply(metric):
metric.fields[“createtime”] = time.now()
return metric
Is that right?
Hello @liuyang0716,
I always suggest using the --test
flag to print your converted line protocol to stdout so you can debug anything you need from your telegraf plugin.
I also recommend setting degub=true
in the agent portion of your config to get detail logs.
I believe you need to supply a timestamp in unix format with nanosecond precision like:
1465839830100400200
But I could be wrong I can’t remember exactly. However there are other options for the timestamp, see the comments in the json file input plugin:
Time format is the time layout that should be used to interpret the json_time_key.
The time must beunix
,unix_ms
,unix_us
,unix_ns
, or a time in the
“reference time”.