docs-v2/content/telegraf/v1/processor-plugins/timestamp/_index.md

4.0 KiB

description menu tags introduced os_support related
Telegraf plugin for transforming metrics using Timestamp
telegraf_v1_ref
parent name identifier
processor_plugins_reference Timestamp processor-timestamp
Timestamp
processor-plugins
configuration
transformation
v1.31.0 freebsd, linux, macos, solaris, windows
/telegraf/v1/configure_plugins/
https://github.com/influxdata/telegraf/tree/v1.36.1/plugins/processors/timestamp/README.md, Timestamp Plugin Source

Timestamp Processor Plugin

This plugin allows to parse fields containing timestamps into timestamps of other format.

Introduced in: Telegraf v1.31.0 Tags: transformation OS support: all

Global configuration options

In addition to the plugin-specific configuration settings, plugins support additional global and plugin configuration settings. These settings are used to modify metrics, tags, and field or create aliases and configure ordering, etc. See the CONFIGURATION.md for more details.

Configuration

# Convert a timestamp field to other timestamp format
[[processors.timestamp]]
  ## Timestamp key to convert
  ## Specify the field name that contains the timestamp to convert. The result
  ## will replace the current field value.
  field = ""

  ## Timestamp Format
  ## This defines the time layout used to interpret the source timestamp field.
  ## The time must be `unix`, `unix_ms`, `unix_us`, `unix_ns`, or a time in Go
  ## "reference time". For more information on Go "reference time". For more
  ## see: https://golang.org/pkg/time/#Time.Format
  source_timestamp_format = ""

  ## Timestamp Timezone
  ## Source timestamp timezone. If not set, assumed to be in UTC.
  ## Options are as follows:
  ##   1. UTC                 -- or unspecified will return timestamp in UTC
  ##   2. Local               -- interpret based on machine localtime
  ##   3. "America/New_York"  -- Unix TZ values like those found in
  ##        https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  # source_timestamp_timezone = ""

  ## Target timestamp format
  ## This defines the destination timestamp format. It also can accept either
  ## `unix`, `unix_ms`, `unix_us`, `unix_ns`, or a time in Go "reference time".
  destination_timestamp_format = ""

  ## Target Timestamp Timezone
  ## Source timestamp timezone. If not set, assumed to be in UTC.
  ## Options are as follows:
  ##   1. UTC                 -- or unspecified will return timestamp in UTC
  ##   2. Local               -- interpret based on machine localtime
  ##   3. "America/New_York"  -- Unix TZ values like those found in
  ##        https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  # destination_timestamp_timezone = ""

Example

Convert a timestamp to unix timestamp:

[[processors.timestamp]]
  source_timestamp_field = "timestamp"
  source_timestamp_format = "2006-01-02T15:04:05.999999999Z"
  destination_timestamp_format = "unix"
- metric value=42i,timestamp="2024-03-04T10:10:32.123456Z" 1560540094000000000
+ metric value=42i,timestamp=1709547032 1560540094000000000

Convert the same timestamp to a nanosecond unix timestamp:

[[processors.timestamp]]
  source_timestamp_field = "timestamp"
  source_timestamp_format = "2006-01-02T15:04:05.999999999Z"
  destination_timestamp_format = "unix_ns"
- metric value=42i,timestamp="2024-03-04T10:10:32.123456789Z" 1560540094000000000
+ metric value=42i,timestamp=1709547032123456789 1560540094000000000

Convert the timestamp to another timestamp format:

[[processors.timestamp]]
  source_timestamp_field = "timestamp"
  source_timestamp_format = "2006-01-02T15:04:05.999999999Z"
  destination_timestamp_format = "2006-01-02T15:04"
- metric value=42i,timestamp="2024-03-04T10:10:32.123456Z" 1560540094000000000
+ metric value=42i,timestamp="2024-03-04T10:10" 1560540094000000000