Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

httpjson: support configurable response_timeout #1651

Merged
merged 4 commits into from
Aug 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ consistent with the behavior of `collection_jitter`.
- [#1278](https:/influxdata/telegraf/pull/1278) & [#1288](https:/influxdata/telegraf/pull/1288) & [#1295](https:/influxdata/telegraf/pull/1295): RabbitMQ/Apache/InfluxDB inputs: made url(s) parameter optional by using reasonable input defaults if not specified
- [#1296](https:/influxdata/telegraf/issues/1296): Refactor of flush_jitter argument.
- [#1213](https:/influxdata/telegraf/issues/1213): Add inactive & active memory to mem plugin.
- [#1650](https:/influxdata/telegraf/issues/1650): Ability to configure response_timeout in httpjson input.
- [#1543](https:/influxdata/telegraf/pull/1543): Official Windows service.
- [#1414](https:/influxdata/telegraf/pull/1414): Forking sensors command to remove C package dependency.
- [#1389](https:/influxdata/telegraf/pull/1389): Add a new SNMP plugin.
Expand Down
11 changes: 7 additions & 4 deletions plugins/inputs/httpjson/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

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:
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:

```
[[inputs.httpjson]]
Expand All @@ -15,12 +14,17 @@ plugin like this:

# HTTP method to use (case-sensitive)
method = "GET"

# Set response_timeout (default 5 seconds)
response_timeout = "5s"
```

`name` is used as a prefix for the measurements.

`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:

```
Expand Down Expand Up @@ -94,8 +98,7 @@ httpjson_mycollector_b_e,service='service01',server='http://my.service.com/_stat

# Example 2, Multiple Services:

There is also the option to collect JSON from multiple services, here is an
example doing that.
There is also the option to collect JSON from multiple services, here is an example doing that.

```
[[inputs.httpjson]]
Expand Down
23 changes: 15 additions & 8 deletions plugins/inputs/httpjson/httpjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ import (
"github.com/influxdata/telegraf/plugins/parsers"
)

// HttpJson struct
type HttpJson struct {
Name string
Servers []string
Method string
TagKeys []string
Parameters map[string]string
Headers map[string]string
Name string
Servers []string
Method string
TagKeys []string
ResponseTimeout internal.Duration
Parameters map[string]string
Headers map[string]string

// Path to CA file
SSLCA string `toml:"ssl_ca"`
Expand Down Expand Up @@ -79,6 +81,8 @@ var sampleConfig = `
"http://localhost:9999/stats/",
"http://localhost:9998/stats/",
]
## Set response_timeout (default 5 seconds)
response_timeout = "5s"

## HTTP method to use: GET or POST (case-sensitive)
method = "GET"
Expand Down Expand Up @@ -126,12 +130,12 @@ func (h *HttpJson) Gather(acc telegraf.Accumulator) error {
return err
}
tr := &http.Transport{
ResponseHeaderTimeout: time.Duration(3 * time.Second),
ResponseHeaderTimeout: h.ResponseTimeout.Duration,
TLSClientConfig: tlsCfg,
}
client := &http.Client{
Transport: tr,
Timeout: time.Duration(4 * time.Second),
Timeout: h.ResponseTimeout.Duration,
}
h.client.SetHTTPClient(client)
}
Expand Down Expand Up @@ -291,6 +295,9 @@ func init() {
inputs.Add("httpjson", func() telegraf.Input {
return &HttpJson{
client: &RealHTTPClient{},
ResponseTimeout: internal.Duration{
Duration: 5 * time.Second,
},
}
})
}