httpjson: support configurable response_timeout (#1651)
* httpjson: support configurable response_timeout * make default ResponseTimeout in init * Update CHANGELOG.md
This commit is contained in:
parent
38d877165a
commit
32aa1cc814
|
@ -101,6 +101,7 @@ consistent with the behavior of `collection_jitter`.
|
||||||
- [#1278](https://github.com/influxdata/telegraf/pull/1278) & [#1288](https://github.com/influxdata/telegraf/pull/1288) & [#1295](https://github.com/influxdata/telegraf/pull/1295): RabbitMQ/Apache/InfluxDB inputs: made url(s) parameter optional by using reasonable input defaults if not specified
|
- [#1278](https://github.com/influxdata/telegraf/pull/1278) & [#1288](https://github.com/influxdata/telegraf/pull/1288) & [#1295](https://github.com/influxdata/telegraf/pull/1295): RabbitMQ/Apache/InfluxDB inputs: made url(s) parameter optional by using reasonable input defaults if not specified
|
||||||
- [#1296](https://github.com/influxdata/telegraf/issues/1296): Refactor of flush_jitter argument.
|
- [#1296](https://github.com/influxdata/telegraf/issues/1296): Refactor of flush_jitter argument.
|
||||||
- [#1213](https://github.com/influxdata/telegraf/issues/1213): Add inactive & active memory to mem plugin.
|
- [#1213](https://github.com/influxdata/telegraf/issues/1213): Add inactive & active memory to mem plugin.
|
||||||
|
- [#1650](https://github.com/influxdata/telegraf/issues/1650): Ability to configure response_timeout in httpjson input.
|
||||||
- [#1543](https://github.com/influxdata/telegraf/pull/1543): Official Windows service.
|
- [#1543](https://github.com/influxdata/telegraf/pull/1543): Official Windows service.
|
||||||
- [#1414](https://github.com/influxdata/telegraf/pull/1414): Forking sensors command to remove C package dependency.
|
- [#1414](https://github.com/influxdata/telegraf/pull/1414): Forking sensors command to remove C package dependency.
|
||||||
- [#1389](https://github.com/influxdata/telegraf/pull/1389): Add a new SNMP plugin.
|
- [#1389](https://github.com/influxdata/telegraf/pull/1389): Add a new SNMP plugin.
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
|
|
||||||
The httpjson plugin can collect data from remote URLs which respond with JSON. Then it flattens JSON and finds all numeric values, treating them as floats.
|
The httpjson plugin can collect data from remote URLs which respond with JSON. Then it flattens JSON and finds all numeric values, treating them as floats.
|
||||||
|
|
||||||
For example, if you have a service called _mycollector_, which has HTTP endpoint for gathering stats at http://my.service.com/_stats, you would configure the HTTP JSON
|
For example, if you have a service called _mycollector_, which has HTTP endpoint for gathering stats at http://my.service.com/_stats, you would configure the HTTP JSON plugin like this:
|
||||||
plugin like this:
|
|
||||||
|
|
||||||
```
|
```
|
||||||
[[inputs.httpjson]]
|
[[inputs.httpjson]]
|
||||||
|
@ -15,12 +14,17 @@ plugin like this:
|
||||||
|
|
||||||
# HTTP method to use (case-sensitive)
|
# HTTP method to use (case-sensitive)
|
||||||
method = "GET"
|
method = "GET"
|
||||||
|
|
||||||
|
# Set response_timeout (default 5 seconds)
|
||||||
|
response_timeout = "5s"
|
||||||
```
|
```
|
||||||
|
|
||||||
`name` is used as a prefix for the measurements.
|
`name` is used as a prefix for the measurements.
|
||||||
|
|
||||||
`method` specifies HTTP method to use for requests.
|
`method` specifies HTTP method to use for requests.
|
||||||
|
|
||||||
|
`response_timeout` specifies timeout to wait to get the response
|
||||||
|
|
||||||
You can also specify which keys from server response should be considered tags:
|
You can also specify which keys from server response should be considered tags:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -94,8 +98,7 @@ httpjson_mycollector_b_e,service='service01',server='http://my.service.com/_stat
|
||||||
|
|
||||||
# Example 2, Multiple Services:
|
# Example 2, Multiple Services:
|
||||||
|
|
||||||
There is also the option to collect JSON from multiple services, here is an
|
There is also the option to collect JSON from multiple services, here is an example doing that.
|
||||||
example doing that.
|
|
||||||
|
|
||||||
```
|
```
|
||||||
[[inputs.httpjson]]
|
[[inputs.httpjson]]
|
||||||
|
|
|
@ -16,11 +16,13 @@ import (
|
||||||
"github.com/influxdata/telegraf/plugins/parsers"
|
"github.com/influxdata/telegraf/plugins/parsers"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// HttpJson struct
|
||||||
type HttpJson struct {
|
type HttpJson struct {
|
||||||
Name string
|
Name string
|
||||||
Servers []string
|
Servers []string
|
||||||
Method string
|
Method string
|
||||||
TagKeys []string
|
TagKeys []string
|
||||||
|
ResponseTimeout internal.Duration
|
||||||
Parameters map[string]string
|
Parameters map[string]string
|
||||||
Headers map[string]string
|
Headers map[string]string
|
||||||
|
|
||||||
|
@ -79,6 +81,8 @@ var sampleConfig = `
|
||||||
"http://localhost:9999/stats/",
|
"http://localhost:9999/stats/",
|
||||||
"http://localhost:9998/stats/",
|
"http://localhost:9998/stats/",
|
||||||
]
|
]
|
||||||
|
## Set response_timeout (default 5 seconds)
|
||||||
|
response_timeout = "5s"
|
||||||
|
|
||||||
## HTTP method to use: GET or POST (case-sensitive)
|
## HTTP method to use: GET or POST (case-sensitive)
|
||||||
method = "GET"
|
method = "GET"
|
||||||
|
@ -126,12 +130,12 @@ func (h *HttpJson) Gather(acc telegraf.Accumulator) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
tr := &http.Transport{
|
tr := &http.Transport{
|
||||||
ResponseHeaderTimeout: time.Duration(3 * time.Second),
|
ResponseHeaderTimeout: h.ResponseTimeout.Duration,
|
||||||
TLSClientConfig: tlsCfg,
|
TLSClientConfig: tlsCfg,
|
||||||
}
|
}
|
||||||
client := &http.Client{
|
client := &http.Client{
|
||||||
Transport: tr,
|
Transport: tr,
|
||||||
Timeout: time.Duration(4 * time.Second),
|
Timeout: h.ResponseTimeout.Duration,
|
||||||
}
|
}
|
||||||
h.client.SetHTTPClient(client)
|
h.client.SetHTTPClient(client)
|
||||||
}
|
}
|
||||||
|
@ -291,6 +295,9 @@ func init() {
|
||||||
inputs.Add("httpjson", func() telegraf.Input {
|
inputs.Add("httpjson", func() telegraf.Input {
|
||||||
return &HttpJson{
|
return &HttpJson{
|
||||||
client: &RealHTTPClient{},
|
client: &RealHTTPClient{},
|
||||||
|
ResponseTimeout: internal.Duration{
|
||||||
|
Duration: 5 * time.Second,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue