Skip to content

Commit 4641a69

Browse files
committed
Add nginx.timeout cli argument
Add -nginx.timeout cli argument for setting a timeout for scrapping metrics from NGINX or NGINX Plus.
1 parent 5ee605a commit 4641a69

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ Usage of ./nginx-prometheus-exporter:
6868
A URI for scraping NGINX or NGINX Plus metrics.
6969
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")
7070
-nginx.ssl-verify
71-
Perform SSL certificate verification. The default value can be overwritten by SSL_VERIFY environment variable.
71+
Perform SSL certificate verification. The default value can be overwritten by SSL_VERIFY environment variable. (default true)
72+
-nginx.timeout duration
73+
A timeout for scraping metrics from NGINX or NGINX Plus. (default 5s)
7274
-web.listen-address string
7375
An address to listen on for web interface and telemetry. The default value can be overwritten by LISTEN_ADDRESS environment variable. (default ":9113")
7476
-web.telemetry-path string

exporter.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88
"os"
99
"strconv"
10+
"time"
1011

1112
plusclient "github.com/nginxinc/nginx-plus-go-sdk/client"
1213
"github.com/nginxinc/nginx-prometheus-exporter/client"
@@ -59,6 +60,7 @@ var (
5960
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.`)
6061
sslVerify = flag.Bool("nginx.ssl-verify", defaultSslVerify,
6162
"Perform SSL certificate verification. The default value can be overwritten by SSL_VERIFY environment variable.")
63+
timeout = flag.Duration("nginx.timeout", 5*time.Second, "A timeout for scraping metrics from NGINX or NGINX Plus.")
6264
)
6365

6466
func main() {
@@ -68,19 +70,22 @@ func main() {
6870

6971
registry := prometheus.NewRegistry()
7072

71-
tr := &http.Transport{
72-
TLSClientConfig: &tls.Config{InsecureSkipVerify: !*sslVerify},
73+
httpClient := &http.Client{
74+
Timeout: *timeout,
75+
Transport: &http.Transport{
76+
TLSClientConfig: &tls.Config{InsecureSkipVerify: !*sslVerify},
77+
},
7378
}
7479

7580
if *nginxPlus {
76-
client, err := plusclient.NewNginxClient(&http.Client{Transport: tr}, *scrapeURI)
81+
client, err := plusclient.NewNginxClient(httpClient, *scrapeURI)
7782
if err != nil {
7883
log.Fatalf("Could not create Nginx Plus Client: %v", err)
7984
}
8085

8186
registry.MustRegister(collector.NewNginxPlusCollector(client, "nginxplus"))
8287
} else {
83-
client, err := client.NewNginxClient(&http.Client{Transport: tr}, *scrapeURI)
88+
client, err := client.NewNginxClient(httpClient, *scrapeURI)
8489
if err != nil {
8590
log.Fatalf("Could not create Nginx Client: %v", err)
8691
}

0 commit comments

Comments
 (0)