Skip to content

Commit

Permalink
Add nginx.timeout cli argument
Browse files Browse the repository at this point in the history
Add -nginx.timeout cli argument for setting a timeout for scrapping
metrics from NGINX or NGINX Plus.
  • Loading branch information
pleshakov committed Jan 11, 2019
1 parent 59be0a4 commit 65bb6a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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() {
Expand All @@ -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)
}
Expand Down

0 comments on commit 65bb6a5

Please sign in to comment.