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

Added response_timeout property to prometheus input plugin #2006

Closed
wants to merge 2 commits into from
Closed
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
11 changes: 11 additions & 0 deletions plugins/inputs/prometheus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ Example for Kubernetes apiserver
urls = ["http://my-kube-apiserver:8080/metrics"]
```

Specify a 10 second timeout for slower/over-loaded clients
```toml
# Get all metrics from Kube-apiserver
[[inputs.prometheus]]
# An array of urls to scrape metrics from.
urls = ["http://my-kube-apiserver:8080/metrics"]

# Specify timeout duration for slower prometheus clients (default is 3s)
response_timeout = 10s
```

You can use more complex configuration
to filter and some tags

Expand Down
9 changes: 7 additions & 2 deletions plugins/inputs/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type Prometheus struct {
// Bearer Token authorization file path
BearerToken string `toml:"bearer_token"`

ResponseTimeout internal.Duration `toml:"response_timeout"`

// Path to CA file
SSLCA string `toml:"ssl_ca"`
// Path to host cert file
Expand All @@ -38,6 +40,9 @@ var sampleConfig = `
## Use bearer token for authorization
# bearer_token = /path/to/bearer/token

## Specify timeout duration for slower prometheus clients (default is 3s)
# response_timeout = 3s

## Optional SSL Config
# ssl_ca = /path/to/cafile
# ssl_cert = /path/to/certfile
Expand Down Expand Up @@ -105,7 +110,7 @@ func (p *Prometheus) gatherURL(url string, acc telegraf.Accumulator) error {
}).Dial,
TLSHandshakeTimeout: 5 * time.Second,
TLSClientConfig: tlsCfg,
ResponseHeaderTimeout: time.Duration(3 * time.Second),
ResponseHeaderTimeout: p.ResponseTimeout.Duration,
DisableKeepAlives: true,
}

Expand Down Expand Up @@ -148,6 +153,6 @@ func (p *Prometheus) gatherURL(url string, acc telegraf.Accumulator) error {

func init() {
inputs.Add("prometheus", func() telegraf.Input {
return &Prometheus{}
return &Prometheus{ResponseTimeout: "3s"}
})
}