From eb4c000d4fcff47c9c5274989d334bfa7ccc0de0 Mon Sep 17 00:00:00 2001 From: Pierre Tessier Date: Mon, 7 Nov 2016 11:34:02 -0500 Subject: [PATCH] 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 8298b9d27..859e69977 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 12f7fd38e..e56f63a95 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} }) }