From c4c68362caa8c9f71f9082a58f08840942b751f0 Mon Sep 17 00:00:00 2001 From: Greg Linton Date: Thu, 11 Apr 2019 10:47:25 -0600 Subject: [PATCH 1/4] Enhance HTTP connection options for phpfpm input plugin --- plugins/inputs/phpfpm/README.md | 11 ++++++++++- plugins/inputs/phpfpm/phpfpm.go | 32 ++++++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/plugins/inputs/phpfpm/README.md b/plugins/inputs/phpfpm/README.md index 531edae241f32..5f4db02ed47fd 100644 --- a/plugins/inputs/phpfpm/README.md +++ b/plugins/inputs/phpfpm/README.md @@ -27,7 +27,16 @@ Get phpfpm stats using either HTTP status page or fpm socket. ## Example of multiple gathering from local socket and remote host ## urls = ["http://192.168.1.20/status", "/tmp/fpm.sock"] urls = ["http://localhost/status"] -``` + + ## Set response timeout for http[s] urls (default 5 seconds) + # response_timeout = "5s" + + ## Optional TLS Config + # tls_ca = "/etc/telegraf/ca.pem" + # tls_cert = "/etc/telegraf/cert.pem" + # tls_key = "/etc/telegraf/key.pem" + ## Use TLS but skip chain & host verification + # insecure_skip_verify = false``` When using `unixsocket`, you have to ensure that telegraf runs on same host, and socket path is accessible to telegraf user. diff --git a/plugins/inputs/phpfpm/phpfpm.go b/plugins/inputs/phpfpm/phpfpm.go index e40dae174fa83..e9f6f77dc08cc 100644 --- a/plugins/inputs/phpfpm/phpfpm.go +++ b/plugins/inputs/phpfpm/phpfpm.go @@ -13,6 +13,8 @@ import ( "sync" "github.com/influxdata/telegraf" + "github.com/influxdata/telegraf/internal" + "github.com/influxdata/telegraf/internal/tls" "github.com/influxdata/telegraf/plugins/inputs" ) @@ -35,7 +37,9 @@ type metric map[string]int64 type poolStat map[string]metric type phpfpm struct { - Urls []string + Urls []string + ResponseTimeout internal.Duration + tls.ClientConfig client *http.Client } @@ -58,9 +62,19 @@ var sampleConfig = ` ## "fcgi://10.0.0.12:9000/status" ## "cgi://10.0.10.12:9001/status" ## - ## Example of multiple gathering from local socket and remove host + ## Example of multiple gathering from local socket and remote host ## urls = ["http://192.168.1.20/status", "/tmp/fpm.sock"] urls = ["http://localhost/status"] + + ## Set response timeout for http[s] urls (default 5 seconds) + # response_timeout = "5s" + + ## Optional TLS Config + # tls_ca = "/etc/telegraf/ca.pem" + # tls_cert = "/etc/telegraf/cert.pem" + # tls_key = "/etc/telegraf/key.pem" + ## Use TLS but skip chain & host verification + # insecure_skip_verify = false ` func (r *phpfpm) SampleConfig() string { @@ -96,8 +110,18 @@ func (g *phpfpm) Gather(acc telegraf.Accumulator) error { // Request status page to get stat raw data and import it func (g *phpfpm) gatherServer(addr string, acc telegraf.Accumulator) error { if g.client == nil { - client := &http.Client{} - g.client = client + tlsCfg, err := g.ClientConfig.TLSConfig() + if err != nil { + return err + } + tr := &http.Transport{ + ResponseHeaderTimeout: g.ResponseTimeout.Duration, + TLSClientConfig: tlsCfg, + } + g.client = &http.Client{ + Transport: tr, + Timeout: g.ResponseTimeout.Duration, + } } if strings.HasPrefix(addr, "http://") || strings.HasPrefix(addr, "https://") { From 866709932510906b88c4db252330d5511d90e672 Mon Sep 17 00:00:00 2001 From: Greg Linton Date: Thu, 11 Apr 2019 10:50:32 -0600 Subject: [PATCH 2/4] Correct type error --- plugins/inputs/phpfpm/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/inputs/phpfpm/README.md b/plugins/inputs/phpfpm/README.md index 5f4db02ed47fd..1864b7cdacc1b 100644 --- a/plugins/inputs/phpfpm/README.md +++ b/plugins/inputs/phpfpm/README.md @@ -36,7 +36,8 @@ Get phpfpm stats using either HTTP status page or fpm socket. # tls_cert = "/etc/telegraf/cert.pem" # tls_key = "/etc/telegraf/key.pem" ## Use TLS but skip chain & host verification - # insecure_skip_verify = false``` + # insecure_skip_verify = false +``` When using `unixsocket`, you have to ensure that telegraf runs on same host, and socket path is accessible to telegraf user. From defac4b60e3c40f1b6198255249faed7be660a07 Mon Sep 17 00:00:00 2001 From: Greg Linton Date: Mon, 15 Apr 2019 18:06:37 -0600 Subject: [PATCH 3/4] Remove redundant timeout --- plugins/inputs/phpfpm/phpfpm.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/inputs/phpfpm/phpfpm.go b/plugins/inputs/phpfpm/phpfpm.go index e9f6f77dc08cc..e5b8fa45c9e81 100644 --- a/plugins/inputs/phpfpm/phpfpm.go +++ b/plugins/inputs/phpfpm/phpfpm.go @@ -115,8 +115,7 @@ func (g *phpfpm) gatherServer(addr string, acc telegraf.Accumulator) error { return err } tr := &http.Transport{ - ResponseHeaderTimeout: g.ResponseTimeout.Duration, - TLSClientConfig: tlsCfg, + TLSClientConfig: tlsCfg, } g.client = &http.Client{ Transport: tr, From 675b693fbd4fb39f32775f9b044138b18eacfb70 Mon Sep 17 00:00:00 2001 From: Greg Linton Date: Tue, 16 Apr 2019 16:34:32 -0600 Subject: [PATCH 4/4] Simplify timeout verbage --- plugins/inputs/phpfpm/README.md | 4 ++-- plugins/inputs/phpfpm/phpfpm.go | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/inputs/phpfpm/README.md b/plugins/inputs/phpfpm/README.md index 1864b7cdacc1b..e2f4e0c2ff574 100644 --- a/plugins/inputs/phpfpm/README.md +++ b/plugins/inputs/phpfpm/README.md @@ -28,8 +28,8 @@ Get phpfpm stats using either HTTP status page or fpm socket. ## urls = ["http://192.168.1.20/status", "/tmp/fpm.sock"] urls = ["http://localhost/status"] - ## Set response timeout for http[s] urls (default 5 seconds) - # response_timeout = "5s" + ## Duration allowed to complete HTTP requests. + # timeout = "5s" ## Optional TLS Config # tls_ca = "/etc/telegraf/ca.pem" diff --git a/plugins/inputs/phpfpm/phpfpm.go b/plugins/inputs/phpfpm/phpfpm.go index e5b8fa45c9e81..ed205e6e70775 100644 --- a/plugins/inputs/phpfpm/phpfpm.go +++ b/plugins/inputs/phpfpm/phpfpm.go @@ -37,8 +37,8 @@ type metric map[string]int64 type poolStat map[string]metric type phpfpm struct { - Urls []string - ResponseTimeout internal.Duration + Urls []string + Timeout internal.Duration tls.ClientConfig client *http.Client @@ -66,8 +66,8 @@ var sampleConfig = ` ## urls = ["http://192.168.1.20/status", "/tmp/fpm.sock"] urls = ["http://localhost/status"] - ## Set response timeout for http[s] urls (default 5 seconds) - # response_timeout = "5s" + ## Duration allowed to complete HTTP requests. + # timeout = "5s" ## Optional TLS Config # tls_ca = "/etc/telegraf/ca.pem" @@ -119,7 +119,7 @@ func (g *phpfpm) gatherServer(addr string, acc telegraf.Accumulator) error { } g.client = &http.Client{ Transport: tr, - Timeout: g.ResponseTimeout.Duration, + Timeout: g.Timeout.Duration, } }