-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use web configuration from exporter-toolkit
Replaces manual implementation of TLS and adds Basic Auth.
- Loading branch information
Showing
10 changed files
with
203 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# NGINX Prometheus Exporter with Web Configuration for Basic Authentication | ||
|
||
This example shows how to run NGINX Prometheus Exporter with web configuration. In this folder you will find an example configuration `web-config.yml` that enables basic authentication. It is configured to have a single user `alice` with password `password`. | ||
|
||
The full documentation for the web configuration can be found [here](https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md). | ||
|
||
## Prerequisites | ||
|
||
* NGINX Prometheus Exporter binary. See the [main README](../../README.md) for installation instructions. | ||
* NGINX or NGINX Plus running on the same machine. | ||
|
||
## Running NGINX Prometheus Exporter with Web Configuration in Basic Authentication mode | ||
|
||
You can run NGINX Prometheus Exporter with web configuration in Basic Authentication mode using the following command: | ||
|
||
```console | ||
nginx-prometheus-exporter --web.config.file=web-config.yml --nginx.scrape-uri="http://127.0.0.1:8080/stub_status" | ||
``` | ||
|
||
Depending on your environment, you may need to specify the full path to the binary or change the path to the web configuration file. | ||
|
||
## Verification | ||
|
||
Run `curl -u alice:password http://localhost:9113/metrics` to see the metrics exposed by the exporter. Without the `-u` flag, the request will fail with `401 Unauthorized`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
basic_auth_users: | ||
alice: $2y$10$6xfhlaIhUDCUl60zPxkqLudN3QjL3Lfjg5gPAWiqElTLErpxAxJbC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# NGINX Prometheus Exporter with systemd-activated socket | ||
|
||
This example shows how to run NGINX Prometheus Exporter with systemd-activated socket. | ||
|
||
## Prerequisites | ||
|
||
* Linux machine with [systemd](https://www.freedesktop.org/wiki/Software/systemd/). | ||
* NGINX Prometheus Exporter binary in `/usr/local/bin/nginx-prometheus-exporter` or a location of your choice. See the [main README](../../README.md) for installation instructions. | ||
* NGINX or NGINX Plus running on the same machine. | ||
|
||
## Customization | ||
|
||
Modify `nginx_exporter.service` and `nginx_exporter.socket` to match your environment. | ||
|
||
The default configuration assumes that NGINX Prometheus Exporter binary is located in `/usr/local/bin/nginx-prometheus-exporter`. | ||
|
||
The `ExecStart` directive has the flag `--web.systemd-socket` which tells the exporter to listen on the socket specified in the `nginx_exporter.socket` file. | ||
|
||
The `ListenStream` directive in `nginx_exporter.socket` specifies the socket to listen on. The default configuration uses `9113` port, but the address can be written in various formats, for example `/run/nginx_exporter.sock`. To see the full list of supported formats, run `man systemd.socket`. | ||
|
||
## Installation | ||
|
||
1. Copy `nginx_exporter.service` and `nginx_exporter.socket` to `/etc/systemd/system/` | ||
2. Run `systemctl daemon-reload` | ||
3. Run `systemctl start nginx_exporter` | ||
4. Run `systemctl status nginx_exporter` to check the status of the service | ||
|
||
## Verification | ||
|
||
1. Run `curl http://localhost:9113/metrics` to see the metrics exposed by the exporter. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[Unit] | ||
Description=NGINX Prometheus Exporter | ||
Requires=nginx_exporter.socket | ||
|
||
[Service] | ||
User=nginx_exporter | ||
ExecStart=/usr/local/bin/nginx-prometheus-exporter --nginx.scrape-uri="http://127.0.0.1:8080/stub_status" --web.systemd-socket | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[Unit] | ||
Description=NGINX Prometheus Exporter | ||
|
||
[Socket] | ||
ListenStream=9113 | ||
|
||
[Install] | ||
WantedBy=sockets.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# NGINX Prometheus Exporter with Web Configuration for TLS | ||
|
||
This example shows how to run NGINX Prometheus Exporter with web configuration. In this folder you will find an example configuration `web-config.yml` that enables TLS and specifies the path to the TLS certificate and key files. Additionally, there are two example TLS files `server.crt` and `server.key` that are used in the configuration. | ||
|
||
The full documentation for the web configuration can be found [here](https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md). | ||
|
||
## Prerequisites | ||
|
||
* NGINX Prometheus Exporter binary. See the [main README](../../README.md) for installation instructions. | ||
* NGINX or NGINX Plus running on the same machine. | ||
|
||
## Running NGINX Prometheus Exporter with Web Configuration in TLS mode | ||
|
||
You can run NGINX Prometheus Exporter with web configuration in TLS mode using the following command: | ||
|
||
```console | ||
nginx-prometheus-exporter --web.config.file=web-config.yml --nginx.scrape-uri="http://127.0.0.1:8080/stub_status" | ||
``` | ||
|
||
you should see an output similar to this: | ||
|
||
```console | ||
... | ||
ts=2023-07-20T02:00:26.932Z caller=tls_config.go:274 level=info msg="Listening on" address=[::]:9113 | ||
ts=2023-07-20T02:00:26.936Z caller=tls_config.go:310 level=info msg="TLS is enabled." http2=true address=[::]:9113 | ||
``` | ||
|
||
Depending on your environment, you may need to specify the full path to the binary or change the path to the web configuration file. | ||
|
||
## Verification | ||
|
||
Run `curl -k https://localhost:9113/metrics` to see the metrics exposed by the exporter. The `-k` flag is needed because the certificate is self-signed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
tls_server_config: | ||
cert_file: server.crt | ||
key_file: server.key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.