diff --git a/README.md b/README.md index 322c4c38..3a813be4 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,9 @@ Usage of ./nginx-prometheus-exporter: A URI for scraping NGINX or NGINX Plus metrics. For NGINX, the stub_status page must be available through the URI. For NGINX Plus -- the API. The default value can be overwritten by SCRAPE_URI environment variable. (default "http://127.0.0.1:8080/stub_status") -nginx.ssl-verify - Perform SSL certificate verification. The default value can be overwritten by SSL_VERIFY environment variable. + Perform SSL certificate verification. The default value can be overwritten by SSL_VERIFY environment variable. (default true) + -nginx.timeout duration + A timeout for scraping metrics from NGINX or NGINX Plus. (default 5s) -web.listen-address string An address to listen on for web interface and telemetry. The default value can be overwritten by LISTEN_ADDRESS environment variable. (default ":9113") -web.telemetry-path string diff --git a/exporter.go b/exporter.go index 7152ec33..6d9c853d 100644 --- a/exporter.go +++ b/exporter.go @@ -7,6 +7,7 @@ import ( "net/http" "os" "strconv" + "time" plusclient "github.com/nginxinc/nginx-plus-go-sdk/client" "github.com/nginxinc/nginx-prometheus-exporter/client" @@ -59,6 +60,7 @@ var ( For NGINX, the stub_status page must be available through the URI. For NGINX Plus -- the API. The default value can be overwritten by SCRAPE_URI environment variable.`) sslVerify = flag.Bool("nginx.ssl-verify", defaultSslVerify, "Perform SSL certificate verification. The default value can be overwritten by SSL_VERIFY environment variable.") + timeout = flag.Duration("nginx.timeout", 5*time.Second, "A timeout for scraping metrics from NGINX or NGINX Plus.") ) func main() { @@ -68,19 +70,22 @@ func main() { registry := prometheus.NewRegistry() - tr := &http.Transport{ - TLSClientConfig: &tls.Config{InsecureSkipVerify: !*sslVerify}, + httpClient := &http.Client{ + Timeout: *timeout, + Transport: &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: !*sslVerify}, + }, } if *nginxPlus { - client, err := plusclient.NewNginxClient(&http.Client{Transport: tr}, *scrapeURI) + client, err := plusclient.NewNginxClient(httpClient, *scrapeURI) if err != nil { log.Fatalf("Could not create Nginx Plus Client: %v", err) } registry.MustRegister(collector.NewNginxPlusCollector(client, "nginxplus")) } else { - client, err := client.NewNginxClient(&http.Client{Transport: tr}, *scrapeURI) + client, err := client.NewNginxClient(httpClient, *scrapeURI) if err != nil { log.Fatalf("Could not create Nginx Client: %v", err) }