From eb4c000d4fcff47c9c5274989d334bfa7ccc0de0 Mon Sep 17 00:00:00 2001 From: Pierre Tessier Date: Mon, 7 Nov 2016 11:34:02 -0500 Subject: [PATCH 1/2] Added response_timeout property --- plugins/inputs/prometheus/README.md | 11 +++++++++++ plugins/inputs/prometheus/prometheus.go | 9 +++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/plugins/inputs/prometheus/README.md b/plugins/inputs/prometheus/README.md index 8298b9d2738b3..859e69977e066 100644 --- a/plugins/inputs/prometheus/README.md +++ b/plugins/inputs/prometheus/README.md @@ -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 in seconds for slower prometheus clients (default is 3) + response_timeout = 10 +``` + You can use more complex configuration to filter and some tags diff --git a/plugins/inputs/prometheus/prometheus.go b/plugins/inputs/prometheus/prometheus.go index 12f7fd38e67bf..e56f63a957eaf 100644 --- a/plugins/inputs/prometheus/prometheus.go +++ b/plugins/inputs/prometheus/prometheus.go @@ -21,6 +21,8 @@ type Prometheus struct { // Bearer Token authorization file path BearerToken string `toml:"bearer_token"` + ResponseTimeout int `toml:"response_timeout"` + // Path to CA file SSLCA string `toml:"ssl_ca"` // Path to host cert file @@ -38,6 +40,9 @@ var sampleConfig = ` ## Use bearer token for authorization # bearer_token = /path/to/bearer/token + ## Specify timeout in seconds for slower prometheus clients (default is 3) + # response_timeout = 3 + ## Optional SSL Config # ssl_ca = /path/to/cafile # ssl_cert = /path/to/certfile @@ -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: time.Duration(time.Duration(p.ResponseTimeout) * time.Second), DisableKeepAlives: true, } @@ -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: 3} }) } From e87d95d50925fc41a54ae024bdfdf4f4f73744b2 Mon Sep 17 00:00:00 2001 From: Pierre Tessier Date: Fri, 16 Dec 2016 14:16:53 -0500 Subject: [PATCH 2/2] Changed response_timeout property to use Duration instead of int --- plugins/inputs/prometheus/README.md | 4 ++-- plugins/inputs/prometheus/prometheus.go | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/inputs/prometheus/README.md b/plugins/inputs/prometheus/README.md index 859e69977e066..d4144d97d1625 100644 --- a/plugins/inputs/prometheus/README.md +++ b/plugins/inputs/prometheus/README.md @@ -20,8 +20,8 @@ Specify a 10 second timeout for slower/over-loaded clients # An array of urls to scrape metrics from. urls = ["http://my-kube-apiserver:8080/metrics"] - # Specify timeout in seconds for slower prometheus clients (default is 3) - response_timeout = 10 + # Specify timeout duration for slower prometheus clients (default is 3s) + response_timeout = 10s ``` You can use more complex configuration diff --git a/plugins/inputs/prometheus/prometheus.go b/plugins/inputs/prometheus/prometheus.go index e56f63a957eaf..54cdfd92a0683 100644 --- a/plugins/inputs/prometheus/prometheus.go +++ b/plugins/inputs/prometheus/prometheus.go @@ -21,7 +21,7 @@ type Prometheus struct { // Bearer Token authorization file path BearerToken string `toml:"bearer_token"` - ResponseTimeout int `toml:"response_timeout"` + ResponseTimeout internal.Duration `toml:"response_timeout"` // Path to CA file SSLCA string `toml:"ssl_ca"` @@ -40,8 +40,8 @@ var sampleConfig = ` ## Use bearer token for authorization # bearer_token = /path/to/bearer/token - ## Specify timeout in seconds for slower prometheus clients (default is 3) - # response_timeout = 3 + ## Specify timeout duration for slower prometheus clients (default is 3s) + # response_timeout = 3s ## Optional SSL Config # ssl_ca = /path/to/cafile @@ -110,7 +110,7 @@ func (p *Prometheus) gatherURL(url string, acc telegraf.Accumulator) error { }).Dial, TLSHandshakeTimeout: 5 * time.Second, TLSClientConfig: tlsCfg, - ResponseHeaderTimeout: time.Duration(time.Duration(p.ResponseTimeout) * time.Second), + ResponseHeaderTimeout: p.ResponseTimeout.Duration, DisableKeepAlives: true, } @@ -153,6 +153,6 @@ func (p *Prometheus) gatherURL(url string, acc telegraf.Accumulator) error { func init() { inputs.Add("prometheus", func() telegraf.Input { - return &Prometheus{ResponseTimeout: 3} + return &Prometheus{ResponseTimeout: "3s"} }) }