2018-09-18 02:45:08 +08:00
|
|
|
# JSON
|
|
|
|
|
|
|
|
|
|
The `json` output data format converts metrics into JSON documents.
|
|
|
|
|
|
2021-11-25 02:47:23 +08:00
|
|
|
## Configuration
|
2018-09-18 02:45:08 +08:00
|
|
|
|
|
|
|
|
```toml
|
|
|
|
|
[[outputs.file]]
|
|
|
|
|
## Files to write to, "stdout" is a specially handled file.
|
|
|
|
|
files = ["stdout", "/tmp/metrics.out"]
|
|
|
|
|
|
|
|
|
|
## Data format to output.
|
|
|
|
|
## Each data format has its own unique set of configuration options, read
|
|
|
|
|
## more about them here:
|
|
|
|
|
## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_OUTPUT.md
|
|
|
|
|
data_format = "json"
|
|
|
|
|
|
|
|
|
|
## The resolution to use for the metric timestamp. Must be a duration string
|
|
|
|
|
## such as "1ns", "1us", "1ms", "10ms", "1s". Durations are truncated to
|
|
|
|
|
## the power of 10 less than the specified units.
|
|
|
|
|
json_timestamp_units = "1s"
|
2021-09-21 23:12:44 +08:00
|
|
|
|
|
|
|
|
## The default timestamp format is Unix epoch time, subject to the
|
|
|
|
|
# resolution configured in json_timestamp_units.
|
|
|
|
|
# Other timestamp layout can be configured using the Go language time
|
|
|
|
|
# layout specification from https://golang.org/pkg/time/#Time.Format
|
|
|
|
|
# e.g.: json_timestamp_format = "2006-01-02T15:04:05Z07:00"
|
|
|
|
|
#json_timestamp_format = ""
|
2018-09-18 02:45:08 +08:00
|
|
|
```
|
|
|
|
|
|
2021-11-25 02:47:23 +08:00
|
|
|
## Examples
|
2018-09-18 02:45:08 +08:00
|
|
|
|
|
|
|
|
Standard form:
|
2021-11-25 02:47:23 +08:00
|
|
|
|
2018-09-18 02:45:08 +08:00
|
|
|
```json
|
|
|
|
|
{
|
|
|
|
|
"fields": {
|
|
|
|
|
"field_1": 30,
|
|
|
|
|
"field_2": 4,
|
|
|
|
|
"field_N": 59,
|
|
|
|
|
"n_images": 660
|
|
|
|
|
},
|
|
|
|
|
"name": "docker",
|
|
|
|
|
"tags": {
|
|
|
|
|
"host": "raynor"
|
|
|
|
|
},
|
|
|
|
|
"timestamp": 1458229140
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
When an output plugin needs to emit multiple metrics at one time, it may use
|
|
|
|
|
the batch format. The use of batch format is determined by the plugin,
|
|
|
|
|
reference the documentation for the specific plugin.
|
2021-11-25 02:47:23 +08:00
|
|
|
|
2018-09-18 02:45:08 +08:00
|
|
|
```json
|
|
|
|
|
{
|
|
|
|
|
"metrics": [
|
|
|
|
|
{
|
|
|
|
|
"fields": {
|
|
|
|
|
"field_1": 30,
|
|
|
|
|
"field_2": 4,
|
|
|
|
|
"field_N": 59,
|
|
|
|
|
"n_images": 660
|
|
|
|
|
},
|
|
|
|
|
"name": "docker",
|
|
|
|
|
"tags": {
|
|
|
|
|
"host": "raynor"
|
|
|
|
|
},
|
|
|
|
|
"timestamp": 1458229140
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"fields": {
|
|
|
|
|
"field_1": 30,
|
|
|
|
|
"field_2": 4,
|
|
|
|
|
"field_N": 59,
|
|
|
|
|
"n_images": 660
|
|
|
|
|
},
|
|
|
|
|
"name": "docker",
|
|
|
|
|
"tags": {
|
|
|
|
|
"host": "raynor"
|
|
|
|
|
},
|
|
|
|
|
"timestamp": 1458229140
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|