2017-04-04 09:34:04 +08:00
|
|
|
# HTTP JSON Input Plugin
|
2015-10-17 19:38:50 +08:00
|
|
|
|
2022-06-08 05:37:08 +08:00
|
|
|
**DEPRECATED in Telegraf v1.6: Use [HTTP input plugin][] as replacement**
|
2015-10-17 19:38:50 +08:00
|
|
|
|
2022-06-08 05:37:08 +08:00
|
|
|
The httpjson plugin collects data from HTTP URLs which respond with JSON. It
|
|
|
|
|
flattens the JSON and finds all numeric values, treating them as floats.
|
2018-02-16 10:51:32 +08:00
|
|
|
|
2021-11-25 02:56:55 +08:00
|
|
|
## Configuration
|
2015-10-17 19:38:50 +08:00
|
|
|
|
2022-05-24 21:49:47 +08:00
|
|
|
```toml @sample.conf
|
2022-04-12 21:29:02 +08:00
|
|
|
# Read flattened metrics from one or more JSON HTTP endpoints
|
2016-04-01 10:37:04 +08:00
|
|
|
[[inputs.httpjson]]
|
2017-04-04 09:34:04 +08:00
|
|
|
## NOTE This plugin only reads numerical measurements, strings and booleans
|
|
|
|
|
## will be ignored.
|
|
|
|
|
|
|
|
|
|
## Name for the service being polled. Will be appended to the name of the
|
|
|
|
|
## measurement e.g. "httpjson_webserver_stats".
|
|
|
|
|
##
|
|
|
|
|
## Deprecated (1.3.0): Use name_override, name_suffix, name_prefix instead.
|
|
|
|
|
name = "webserver_stats"
|
2015-10-17 19:38:50 +08:00
|
|
|
|
2017-04-04 09:34:04 +08:00
|
|
|
## URL of each server in the service's cluster
|
2015-10-17 19:38:50 +08:00
|
|
|
servers = [
|
2017-04-04 09:34:04 +08:00
|
|
|
"http://localhost:9999/stats/",
|
|
|
|
|
"http://localhost:9998/stats/",
|
2015-10-17 19:38:50 +08:00
|
|
|
]
|
2017-04-04 09:34:04 +08:00
|
|
|
## Set response_timeout (default 5 seconds)
|
2016-08-30 23:23:15 +08:00
|
|
|
response_timeout = "5s"
|
2015-10-17 19:38:50 +08:00
|
|
|
|
2017-04-04 09:34:04 +08:00
|
|
|
## HTTP method to use: GET or POST (case-sensitive)
|
|
|
|
|
method = "GET"
|
2015-10-17 19:38:50 +08:00
|
|
|
|
2017-04-04 09:34:04 +08:00
|
|
|
## Tags to extract from top-level of JSON server response.
|
|
|
|
|
# tag_keys = [
|
|
|
|
|
# "my_tag_1",
|
|
|
|
|
# "my_tag_2"
|
|
|
|
|
# ]
|
2016-08-30 23:23:15 +08:00
|
|
|
|
2018-05-05 07:33:23 +08:00
|
|
|
## Optional TLS Config
|
|
|
|
|
# tls_ca = "/etc/telegraf/ca.pem"
|
|
|
|
|
# tls_cert = "/etc/telegraf/cert.pem"
|
|
|
|
|
# tls_key = "/etc/telegraf/key.pem"
|
|
|
|
|
## Use TLS but skip chain & host verification
|
2018-01-09 07:06:58 +08:00
|
|
|
# insecure_skip_verify = false
|
|
|
|
|
|
2017-04-04 09:34:04 +08:00
|
|
|
## HTTP Request Parameters (all values must be strings). For "GET" requests, data
|
|
|
|
|
## will be included in the query. For "POST" requests, data will be included
|
|
|
|
|
## in the request body as "x-www-form-urlencoded".
|
|
|
|
|
# [inputs.httpjson.parameters]
|
|
|
|
|
# event_type = "cpu_spike"
|
|
|
|
|
# threshold = "0.75"
|
2015-10-17 19:38:50 +08:00
|
|
|
|
2017-04-04 09:34:04 +08:00
|
|
|
## HTTP Request Headers (all values must be strings).
|
|
|
|
|
# [inputs.httpjson.headers]
|
|
|
|
|
# X-Auth-Token = "my-xauth-token"
|
|
|
|
|
# apiVersion = "v1"
|
2015-10-17 19:38:50 +08:00
|
|
|
```
|
|
|
|
|
|
2021-11-25 02:56:55 +08:00
|
|
|
## Measurements & Fields
|
2016-11-16 02:02:55 +08:00
|
|
|
|
2017-04-04 09:34:04 +08:00
|
|
|
- httpjson
|
2021-11-25 02:56:55 +08:00
|
|
|
- response_time (float): Response time in seconds
|
2015-10-17 19:38:50 +08:00
|
|
|
|
2022-06-08 05:37:08 +08:00
|
|
|
Additional fields are dependant on the response of the remote service being
|
|
|
|
|
polled.
|
2015-10-17 19:38:50 +08:00
|
|
|
|
2021-11-25 02:56:55 +08:00
|
|
|
## Tags
|
2015-10-17 19:38:50 +08:00
|
|
|
|
2017-04-04 09:34:04 +08:00
|
|
|
- All measurements have the following tags:
|
2021-11-25 02:56:55 +08:00
|
|
|
- server: HTTP origin as defined in configuration as `servers`.
|
2015-10-17 19:38:50 +08:00
|
|
|
|
2022-06-08 05:37:08 +08:00
|
|
|
Any top level keys listed under `tag_keys` in the configuration are added as
|
|
|
|
|
tags. Top level keys are defined as keys in the root level of the object in a
|
|
|
|
|
single object response, or in the root level of each object within an array of
|
|
|
|
|
objects.
|
2016-01-26 21:18:22 +08:00
|
|
|
|
2021-11-25 02:56:55 +08:00
|
|
|
## Examples Output
|
2015-10-17 19:38:50 +08:00
|
|
|
|
2022-06-08 05:37:08 +08:00
|
|
|
This plugin understands responses containing a single JSON object, or a JSON
|
|
|
|
|
Array of Objects.
|
2015-11-03 07:19:37 +08:00
|
|
|
|
2017-04-04 09:34:04 +08:00
|
|
|
**Object Output:**
|
2015-11-03 07:19:37 +08:00
|
|
|
|
2017-04-04 09:34:04 +08:00
|
|
|
Given the following response body:
|
2021-11-25 02:56:55 +08:00
|
|
|
|
2015-11-03 07:19:37 +08:00
|
|
|
```json
|
|
|
|
|
{
|
|
|
|
|
"a": 0.5,
|
|
|
|
|
"b": {
|
|
|
|
|
"c": "some text",
|
|
|
|
|
"d": 0.1,
|
|
|
|
|
"e": 5
|
2017-04-04 09:34:04 +08:00
|
|
|
},
|
|
|
|
|
"service": "service01"
|
2015-11-03 07:19:37 +08:00
|
|
|
}
|
|
|
|
|
```
|
2021-11-25 02:56:55 +08:00
|
|
|
|
2017-04-04 09:34:04 +08:00
|
|
|
The following metric is produced:
|
2015-11-03 07:19:37 +08:00
|
|
|
|
2022-06-08 05:37:08 +08:00
|
|
|
```shell
|
|
|
|
|
httpjson,server=http://localhost:9999/stats/ b_d=0.1,a=0.5,b_e=5,response_time=0.001
|
|
|
|
|
```
|
2015-11-03 07:19:37 +08:00
|
|
|
|
2017-04-04 09:34:04 +08:00
|
|
|
Note that only numerical values are extracted and the type is float.
|
2015-11-03 07:19:37 +08:00
|
|
|
|
2017-04-04 09:34:04 +08:00
|
|
|
If `tag_keys` is included in the configuration:
|
2015-10-17 19:38:50 +08:00
|
|
|
|
2017-04-04 09:34:04 +08:00
|
|
|
```toml
|
2016-04-01 10:37:04 +08:00
|
|
|
[[inputs.httpjson]]
|
2017-04-04 09:34:04 +08:00
|
|
|
tag_keys = ["service"]
|
2015-11-03 07:19:37 +08:00
|
|
|
```
|
|
|
|
|
|
2017-04-04 09:34:04 +08:00
|
|
|
Then the `service` tag will also be added:
|
2015-11-03 07:19:37 +08:00
|
|
|
|
2022-06-08 05:37:08 +08:00
|
|
|
```shell
|
|
|
|
|
httpjson,server=http://localhost:9999/stats/,service=service01 b_d=0.1,a=0.5,b_e=5,response_time=0.001
|
|
|
|
|
```
|
2015-11-03 07:19:37 +08:00
|
|
|
|
2017-04-04 09:34:04 +08:00
|
|
|
**Array Output:**
|
2016-11-16 02:02:55 +08:00
|
|
|
|
2022-06-08 05:37:08 +08:00
|
|
|
If the service returns an array of objects, one metric is be created for each
|
|
|
|
|
object:
|
2016-11-16 02:02:55 +08:00
|
|
|
|
|
|
|
|
```json
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
"service": "service01",
|
|
|
|
|
"a": 0.5,
|
|
|
|
|
"b": {
|
|
|
|
|
"c": "some text",
|
|
|
|
|
"d": 0.1,
|
|
|
|
|
"e": 5
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"service": "service02",
|
|
|
|
|
"a": 0.6,
|
|
|
|
|
"b": {
|
|
|
|
|
"c": "some text",
|
|
|
|
|
"d": 0.2,
|
|
|
|
|
"e": 6
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
```
|
|
|
|
|
|
2022-06-08 05:37:08 +08:00
|
|
|
```shell
|
|
|
|
|
httpjson,server=http://localhost:9999/stats/,service=service01 a=0.5,b_d=0.1,b_e=5,response_time=0.003
|
|
|
|
|
httpjson,server=http://localhost:9999/stats/,service=service02 a=0.6,b_d=0.2,b_e=6,response_time=0.003
|
|
|
|
|
```
|
2021-11-25 03:59:41 +08:00
|
|
|
|
2022-06-08 05:37:08 +08:00
|
|
|
[HTTP input plugin]: ../http/README.md
|