Skip to content

Commit 90107cb

Browse files
author
Raza Jhaveri
committed
add option to skip tls verify
1 parent e393d61 commit 90107cb

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ To start the exporter we use the [docker run](https://docs.docker.com/engine/ref
4545
4646
## Usage
4747
48-
### Command-line Arguments
48+
### Command-line Arguments
4949
5050
```
5151
Usage of ./nginx-prometheus-exporter:
@@ -54,13 +54,15 @@ Usage of ./nginx-prometheus-exporter:
5454
-nginx.scrape-uri string
5555
A URI for scraping NGINX or NGINX Plus metrics.
5656
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")
57+
-nginx.ssl-verify
58+
Perform SSL certificate verification. The default value can be overwritten by SSL_VERIFY environment variable.
5759
-web.listen-address string
5860
An address to listen on for web interface and telemetry. The default value can be overwritten by LISTEN_ADDRESS environment variable. (default ":9113")
5961
-web.telemetry-path string
6062
A path under which to expose metrics. The default value can be overwritten by TELEMETRY_PATH environment variable. (default "/metrics")
6163
```
6264
63-
### Exported Metrics
65+
### Exported Metrics
6466
6567
* For NGINX, all stub_status metrics are exported. Connect to the `/metrics` page of the running exporter to see the complete list of metrics along with their descriptions.
6668
* For NGINX Plus, the following metrics are exported:
@@ -69,7 +71,7 @@ Usage of ./nginx-prometheus-exporter:
6971
* [SSL](http://nginx.org/en/docs/http/ngx_http_api_module.html#def_nginx_ssl_object).
7072
* [HTTP Server Zones](http://nginx.org/en/docs/http/ngx_http_api_module.html#def_nginx_http_server_zone).
7173
* [HTTP Upsteams](http://nginx.org/en/docs/http/ngx_http_api_module.html#def_nginx_http_upstream). Note: for the `state` metric, the string values are converted to float64 using the following rule: `"up"` -> `1.0`, `"draining"` -> `2.0`, `"down"` -> `3.0`, `"unavail"` –> `4.0`, `"checking"` –> `5.0`, `"unhealthy"` -> `6.0`.
72-
74+
7375
Connect to the `/metrics` page of the running exporter to see the complete list of metrics along with their descriptions. Note: to see server zones related metrics you must configure [status zones](https://nginx.org/en/docs/http/ngx_http_status_module.html#status_zone) and to see upstream related metrics you must configure upstreams with a [shared memory zone](http://nginx.org/en/docs/http/ngx_http_upstream_module.html#zone).
7476
7577
### Troubleshooting
@@ -86,10 +88,10 @@ You can build the exporter image using the provided Makefile. Before building th
8688
* make
8789
* Docker
8890
* git
89-
91+
9092
To build the image, run:
9193
```
92-
$ make container
94+
$ make container
9395
```
9496
9597
Note:

exporter.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"crypto/tls"
45
"flag"
56
"log"
67
"net/http"
@@ -44,6 +45,7 @@ var (
4445
defaultMetricsPath = getEnv("TELEMETRY_PATH", "/metrics")
4546
defaultNginxPlus = getEnvBool("NGINX_PLUS", false)
4647
defaultScrapeURI = getEnv("SCRAPE_URI", "http://127.0.0.1:8080/stub_status")
48+
defaultSslVerify = getEnvBool("SSL_VERIFY", true)
4749

4850
// Command-line flags
4951
listenAddr = flag.String("web.listen-address", defaultListenAddress,
@@ -55,6 +57,8 @@ var (
5557
scrapeURI = flag.String("nginx.scrape-uri", defaultScrapeURI,
5658
`A URI for scraping NGINX or NGINX Plus metrics.
5759
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.`)
60+
sslVerify = flag.Bool("nginx.ssl-verify", defaultSslVerify,
61+
"Perform SSL certificate verification. The default value can be overwritten by SSL_VERIFY environment variable.")
5862
)
5963

6064
func main() {
@@ -64,15 +68,19 @@ func main() {
6468

6569
registry := prometheus.NewRegistry()
6670

71+
tr := &http.Transport{
72+
TLSClientConfig: &tls.Config{InsecureSkipVerify: !*sslVerify},
73+
}
74+
6775
if *nginxPlus {
68-
client, err := plusclient.NewNginxClient(&http.Client{}, *scrapeURI)
76+
client, err := plusclient.NewNginxClient(&http.Client{Transport: tr}, *scrapeURI)
6977
if err != nil {
7078
log.Fatalf("Could not create Nginx Plus Client: %v", err)
7179
}
7280

7381
registry.MustRegister(collector.NewNginxPlusCollector(client, "nginxplus"))
7482
} else {
75-
client, err := client.NewNginxClient(&http.Client{}, *scrapeURI)
83+
client, err := client.NewNginxClient(&http.Client{Transport: tr}, *scrapeURI)
7684
if err != nil {
7785
log.Fatalf("Could not create Nginx Client: %v", err)
7886
}

0 commit comments

Comments
 (0)