diff --git a/labs/lab1/media/lab1_none-dataplane-key-new.png b/labs/lab1/media/lab1_none-dataplane-key-new.png index 09c8919..b8aadba 100644 Binary files a/labs/lab1/media/lab1_none-dataplane-key-new.png and b/labs/lab1/media/lab1_none-dataplane-key-new.png differ diff --git a/labs/lab1/media/lab1_none-dataplane-key-save.png b/labs/lab1/media/lab1_none-dataplane-key-save.png index 8bf3d5c..0d9587f 100644 Binary files a/labs/lab1/media/lab1_none-dataplane-key-save.png and b/labs/lab1/media/lab1_none-dataplane-key-save.png differ diff --git a/labs/lab4/readme.md b/labs/lab4/readme.md index a349388..2bd32b7 100644 --- a/labs/lab4/readme.md +++ b/labs/lab4/readme.md @@ -306,4 +306,4 @@ This ends lab4. --- -Navigate to ([LabGuide](../readme.md)) +Navigate to ([Lab5](../lab5/readme.md) | [LabGuide](../readme.md)) diff --git a/labs/lab5/final/keepalive.conf b/labs/lab5/final/keepalive.conf new file mode 100644 index 0000000..b31f371 --- /dev/null +++ b/labs/lab5/final/keepalive.conf @@ -0,0 +1,11 @@ +# Nginx Basics keepalive.conf +# Nov 2024 - Chris Akker, Shouvik Dutta, Adam Currier +# +# Default is HTTP/1.0 to upstreams, HTTP keepalives needed for HTTP/1.1 +proxy_http_version 1.1; + +# Set the Connection header to empty +proxy_set_header Connection ""; + +# Host request header field, or the server name matching a request +proxy_set_header Host $host; \ No newline at end of file diff --git a/labs/lab5/final/proxy_headers.conf b/labs/lab5/final/proxy_headers.conf new file mode 100644 index 0000000..2e3e8ad --- /dev/null +++ b/labs/lab5/final/proxy_headers.conf @@ -0,0 +1,13 @@ +# Nginx Basics proxy_headers.conf +# Nov 2024 - Chris Akker, Shouvik Dutta, Adam Currier +# +## Set Headers to the proxied servers ## + +# client address in binary format +proxy_set_header X-Real-IP $remote_addr; + +# X-Forwarded-For client request header +proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + +# request scheme, “http” or “https” +proxy_set_header X-Forwarded-Proto $scheme; \ No newline at end of file diff --git a/labs/lab5/readme.md b/labs/lab5/readme.md index 03c4246..ac6ac69 100644 --- a/labs/lab5/readme.md +++ b/labs/lab5/readme.md @@ -280,7 +280,7 @@ This will require a new NGINX config file, for the Server and Location Blocks. F 1. Time to Test!!! Go back to Visual Studio Terminal and run below commands to test if your new `proxy_pass` configuration is working as expected. Run this command several times. ```bash - docker exec -it $NAME-nginx-plus curl -s http://cafe.example.com |grep Server + curl -s http://cafe.example.com |grep Server ``` ```bash @@ -1247,4 +1247,4 @@ With NGINX, there are several configuration options for this, but in this next l ------------- -Navigate to ([Lab6](../lab6/readme.md) | [Main Menu](../readme.md)) +Navigate to ([Lab6](../lab6/readme.md) | [LabGuide](../readme.md)) diff --git a/labs/lab8/NGINX-Basics.json b/labs/lab7/NGINX-Basics.json similarity index 100% rename from labs/lab8/NGINX-Basics.json rename to labs/lab7/NGINX-Basics.json diff --git a/labs/lab8/docker-compose.yml b/labs/lab7/docker-compose.yml similarity index 100% rename from labs/lab8/docker-compose.yml rename to labs/lab7/docker-compose.yml diff --git a/labs/lab8/media/grafana-icon.png b/labs/lab7/media/grafana-icon.png similarity index 100% rename from labs/lab8/media/grafana-icon.png rename to labs/lab7/media/grafana-icon.png diff --git a/labs/lab8/media/lab6_grafana-dashboard.png b/labs/lab7/media/lab7_grafana-dashboard.png similarity index 100% rename from labs/lab8/media/lab6_grafana-dashboard.png rename to labs/lab7/media/lab7_grafana-dashboard.png diff --git a/labs/lab8/media/lab6_prometheus-datasource.png b/labs/lab7/media/lab7_prometheus-datasource.png similarity index 100% rename from labs/lab8/media/lab6_prometheus-datasource.png rename to labs/lab7/media/lab7_prometheus-datasource.png diff --git a/labs/lab8/media/lab6_prometheus-graph.png b/labs/lab7/media/lab7_prometheus-graph.png similarity index 100% rename from labs/lab8/media/lab6_prometheus-graph.png rename to labs/lab7/media/lab7_prometheus-graph.png diff --git a/labs/lab8/media/lab6_scraper_page1.png b/labs/lab7/media/lab7_scraper_page1.png similarity index 100% rename from labs/lab8/media/lab6_scraper_page1.png rename to labs/lab7/media/lab7_scraper_page1.png diff --git a/labs/lab8/media/nginx-plus-icon.png b/labs/lab7/media/nginx-plus-icon.png similarity index 100% rename from labs/lab8/media/nginx-plus-icon.png rename to labs/lab7/media/nginx-plus-icon.png diff --git a/labs/lab8/media/prometheus-icon.png b/labs/lab7/media/prometheus-icon.png similarity index 100% rename from labs/lab8/media/prometheus-icon.png rename to labs/lab7/media/prometheus-icon.png diff --git a/labs/lab8/nginx-plus/Dockerfile b/labs/lab7/nginx-plus/Dockerfile similarity index 100% rename from labs/lab8/nginx-plus/Dockerfile rename to labs/lab7/nginx-plus/Dockerfile diff --git a/labs/lab8/nginx-plus/etc/nginx/conf.d/cafe.example.com.conf b/labs/lab7/nginx-plus/etc/nginx/conf.d/cafe.example.com.conf similarity index 100% rename from labs/lab8/nginx-plus/etc/nginx/conf.d/cafe.example.com.conf rename to labs/lab7/nginx-plus/etc/nginx/conf.d/cafe.example.com.conf diff --git a/labs/lab8/nginx-plus/etc/nginx/conf.d/dashboard.conf b/labs/lab7/nginx-plus/etc/nginx/conf.d/dashboard.conf similarity index 100% rename from labs/lab8/nginx-plus/etc/nginx/conf.d/dashboard.conf rename to labs/lab7/nginx-plus/etc/nginx/conf.d/dashboard.conf diff --git a/labs/lab8/nginx-plus/etc/nginx/conf.d/prometheus.conf b/labs/lab7/nginx-plus/etc/nginx/conf.d/prometheus.conf similarity index 100% rename from labs/lab8/nginx-plus/etc/nginx/conf.d/prometheus.conf rename to labs/lab7/nginx-plus/etc/nginx/conf.d/prometheus.conf diff --git a/labs/lab8/nginx-plus/etc/nginx/conf.d/status_ok.conf b/labs/lab7/nginx-plus/etc/nginx/conf.d/status_ok.conf similarity index 100% rename from labs/lab8/nginx-plus/etc/nginx/conf.d/status_ok.conf rename to labs/lab7/nginx-plus/etc/nginx/conf.d/status_ok.conf diff --git a/labs/lab8/nginx-plus/etc/nginx/conf.d/upstreams.conf b/labs/lab7/nginx-plus/etc/nginx/conf.d/upstreams.conf similarity index 100% rename from labs/lab8/nginx-plus/etc/nginx/conf.d/upstreams.conf rename to labs/lab7/nginx-plus/etc/nginx/conf.d/upstreams.conf diff --git a/labs/lab8/nginx-plus/etc/nginx/includes/keepalive.conf b/labs/lab7/nginx-plus/etc/nginx/includes/keepalive.conf similarity index 100% rename from labs/lab8/nginx-plus/etc/nginx/includes/keepalive.conf rename to labs/lab7/nginx-plus/etc/nginx/includes/keepalive.conf diff --git a/labs/lab8/nginx-plus/etc/nginx/includes/log_formats/main_ext.conf b/labs/lab7/nginx-plus/etc/nginx/includes/log_formats/main_ext.conf similarity index 100% rename from labs/lab8/nginx-plus/etc/nginx/includes/log_formats/main_ext.conf rename to labs/lab7/nginx-plus/etc/nginx/includes/log_formats/main_ext.conf diff --git a/labs/lab8/nginx-plus/etc/nginx/includes/proxy_headers.conf b/labs/lab7/nginx-plus/etc/nginx/includes/proxy_headers.conf similarity index 100% rename from labs/lab8/nginx-plus/etc/nginx/includes/proxy_headers.conf rename to labs/lab7/nginx-plus/etc/nginx/includes/proxy_headers.conf diff --git a/labs/lab8/nginx-plus/etc/nginx/nginx.conf b/labs/lab7/nginx-plus/etc/nginx/nginx.conf similarity index 100% rename from labs/lab8/nginx-plus/etc/nginx/nginx.conf rename to labs/lab7/nginx-plus/etc/nginx/nginx.conf diff --git a/labs/lab8/nginx-plus/etc/prometheus/prometheus.yml b/labs/lab7/nginx-plus/etc/prometheus/prometheus.yml similarity index 100% rename from labs/lab8/nginx-plus/etc/prometheus/prometheus.yml rename to labs/lab7/nginx-plus/etc/prometheus/prometheus.yml diff --git a/labs/lab8/nginx-plus/usr/share/nginx/html/dashboard.html b/labs/lab7/nginx-plus/usr/share/nginx/html/dashboard.html similarity index 100% rename from labs/lab8/nginx-plus/usr/share/nginx/html/dashboard.html rename to labs/lab7/nginx-plus/usr/share/nginx/html/dashboard.html diff --git a/labs/lab8/nginx-plus/usr/share/nginx/html/gtr.html b/labs/lab7/nginx-plus/usr/share/nginx/html/gtr.html similarity index 100% rename from labs/lab8/nginx-plus/usr/share/nginx/html/gtr.html rename to labs/lab7/nginx-plus/usr/share/nginx/html/gtr.html diff --git a/labs/lab8/nginx-plus/usr/share/nginx/html/gtr.jpg b/labs/lab7/nginx-plus/usr/share/nginx/html/gtr.jpg similarity index 100% rename from labs/lab8/nginx-plus/usr/share/nginx/html/gtr.jpg rename to labs/lab7/nginx-plus/usr/share/nginx/html/gtr.jpg diff --git a/labs/lab8/nginx-plus/usr/share/nginx/html/index.html b/labs/lab7/nginx-plus/usr/share/nginx/html/index.html similarity index 100% rename from labs/lab8/nginx-plus/usr/share/nginx/html/index.html rename to labs/lab7/nginx-plus/usr/share/nginx/html/index.html diff --git a/labs/lab8/nginx-plus/usr/share/nginx/html/nsx.html b/labs/lab7/nginx-plus/usr/share/nginx/html/nsx.html similarity index 100% rename from labs/lab8/nginx-plus/usr/share/nginx/html/nsx.html rename to labs/lab7/nginx-plus/usr/share/nginx/html/nsx.html diff --git a/labs/lab8/nginx-plus/usr/share/nginx/html/nsx.jpg b/labs/lab7/nginx-plus/usr/share/nginx/html/nsx.jpg similarity index 100% rename from labs/lab8/nginx-plus/usr/share/nginx/html/nsx.jpg rename to labs/lab7/nginx-plus/usr/share/nginx/html/nsx.jpg diff --git a/labs/lab8/nginx-plus/usr/share/nginx/html/rcf.html b/labs/lab7/nginx-plus/usr/share/nginx/html/rcf.html similarity index 100% rename from labs/lab8/nginx-plus/usr/share/nginx/html/rcf.html rename to labs/lab7/nginx-plus/usr/share/nginx/html/rcf.html diff --git a/labs/lab8/nginx-plus/usr/share/nginx/html/rcf.jpg b/labs/lab7/nginx-plus/usr/share/nginx/html/rcf.jpg similarity index 100% rename from labs/lab8/nginx-plus/usr/share/nginx/html/rcf.jpg rename to labs/lab7/nginx-plus/usr/share/nginx/html/rcf.jpg diff --git a/labs/lab7/readme.md b/labs/lab7/readme.md index f2e7322..c4c2c44 100644 --- a/labs/lab7/readme.md +++ b/labs/lab7/readme.md @@ -1,21 +1,276 @@ -# Upgrade Dataplane NGINX Plus Instances to R33 +# Monitoring NGINX Plus with Prometheus and Grafana ## Introduction +In this lab, you will be exploring the integration between NGINX Plus, Prometheus and Grafana. +This Solution requires the use of the NGINX provided Javascript and Prometheus modules to collect metrics from the NGINX Plus API, and export those metrics as an HTTP html/text page, commonly called the `scaper page` because it scrapes statistics for publication. The metrics on this export page are then read and imported into Prometheus and Grafana's time-series database. Once these metrics are in the database, you can create many different Dashboards, Thresholds, Alerts, and other types of graphs for Visualization and Reporting. As you can imagine, there are literally hundreds of Grafana dashboards written by users of NGINX that you can try out for free. Grafana also allows you to create and edit your own Dashboards. +NGINX Plus | Prometheus | Grafana +:-------------------------:|:-------------------------:|:-----: +![NGINX Plus](media/nginx-plus-icon.png) |![Prom](media/prometheus-icon.png) |![Grafana](media/grafana-icon.png) + ## Learning Objectives +By the end of the lab you will be able to: +- Enable and configure NGINX Java Script +- Create Prometheus Exporter configuration +- Test the Prometheus Server +- Test the Grafana Server +- View Grafana Dashboard -## Prerequisites +## Pre-Requisites +- Nginx-Plus container from Lab1 +- You must have Docker installed and running +- You must have Docker-compose installed +- See `Lab0` for instructions on setting up your system for this Workshop +- Familiarity with basic Linux commands and commandline tools +- Familiarity with basic Docker concepts and commands +- Familiarity with basic HTTP protocol +- Familiarity with Prometheus +- Familiartiy with Grafana + +As part of your Dockerfile, your NGINX Plus container already has the added `NGINX Java Script and NGINX Prometheus dynamic module` installed during the build process. Refer to the /lab1/nginx-plus/Dockerfile if you want to check it out. + +1. Ensure you are in the `lab7` folder. Using a Terminal, run Docker Compose to build and run all the containers. + + ```bash + cd lab6 + docker compose up --force-recreate -d + + ``` + +1. Edit your `nginx.conf` file, you will make 2 changes. + + - Uncomment Line #8 to enable the `ngx_http_js_module` module. + - Uncomment Line #37 to set a parameter for an NGINX buffer called `subrequest_output_buffer_size`. + + ```nginx + ...snip + + user nginx; + worker_processes auto; + + error_log /var/log/nginx/error.log info; + pid /var/run/nginx.pid; + + # Uncomment to enable NGINX JavaScript module + load_module modules/ngx_http_js_module.so; # Added for Prometheus + + ...snip + + # Uncomment for Prometheus scraper page output + subrequest_output_buffer_size 32k; # Added for Prometheus + + ...snip + + ``` + +1. Inspect the `prometheus.conf` file in the `labs/lab6/nginx-plus/etc/nginx/conf.d` folder. This is the NGINX config file which opens up port 9113, and provides access to the scraper page. Uncomment all the lines to enable this. + + ```nginx + # NGINX Plus Prometheus configuration, for HTTP scraper page + # Chris Akker, Shouvik Dutta - Feb 2024 + # https://www.nginx.com/blog/how-to-visualize-nginx-plus-with-prometheus-and-grafana/ + # Nginx Basics + # + # Uncomment all lines below + js_import /usr/share/nginx-plus-module-prometheus/prometheus.js; + + server { + + listen 9113; # This is the default port for Prometheus scraper page + + location = /metrics { + js_content prometheus.metrics; + } + + location /api { + api; + } + + } + + ``` + +1. Once the contents of both files has been updated and saved, Docker Exec into the nginx-plus container. + + ```bash + docker exec -it nginx-plus bin/bash + + ``` + +1. Test and reload your NGINX config by running `nginx -t` and `nginx -s reload` commands respectively from within the container. + +1. Start the WRK load generation tool. This will provide some traffic to the nginx-plus container, so the statistics will be increasing. + + ```bash + docker run --name wrk --network=lab6_default --rm williamyeh/wrk -t4 -c200 -d20m -H 'Host: cafe.example.com' --timeout 2s http://nginx-plus/coffee + + ``` + +1. Test the Prometheus scraper page. Open your browser to . You should see an html/text page like this one. You will notice there are MANY statistcs available, this page is like a text version of the NGINX Plus dashboard. This page can be easily imported into your existing Performance Management and Monitoring tools. You will see how to do this in the next section with Prometheus and Grafana. + + Click refresh a couple times, and some of the metrics should increment. + + ![Scraper page](media/lab7_scraper_page1.png) + +
+ +## Prometheus and Grafana Server Docker containers + +
+ +![prometheus](media/prometheus-icon.png) |![grafana](media/grafana-icon.png) +--- | --- + +1. Inspect your `docker-compose.yml` file, you will see it includes 2 additional Docker containers for this lab, one for a Prometheus server, and one for a Grafana server. These have been configured to run for you, but the images will be pulled from public repos. + + ```bash + ...snip + + prometheus: + hostname: prometheus + container_name: prometheus + image: prom/prometheus + volumes: + - ./nginx-plus/etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml + ports: + - "9090:9090" + restart: always + depends_on: + - nginx-plus + grafana: + hostname: grafana + container_name: grafana + volumes: + - grafana-storage:/var/lib/grafana + image: grafana/grafana + ports: + - "3000:3000" + restart: always + depends_on: + - nginx-plus + volumes: + grafana-storage: + name: "grafana-storage" + external: false + + ``` + +1. Verify these 2 containers are running. + + ```bash + docker ps -a + + ``` + + ```bash + ##Sample output## + CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES + 8a61c66fc511 prom/prometheus "/bin/prometheus --c…" 36 minutes ago Up 36 minutes 0.0.0.0:9090->9090/tcp prometheus + 4d38710ed4ec grafana/grafana "/run.sh" 36 minutes ago Up 36 minutes 0.0.0.0:3000->3000/tcp grafana + + ...snip + + ``` + +
+ +### Prometheus + +
+ +Prometheus is a software package that can watch and collect statistics from many different NGINX instances. The Prometheus server will collect the statistics from the scraper page that you enabled in the previous section. + +
+ +1. Using Chrome, navigate to . You should see a Prometheus webpage like this one. Search for `nginxplus_` in the query box to see a list of all the Nginx Plus statistics that Prometheus is collecting for you. Select `nginxplus_http_requests_total` from the list, click on Graph, and then click the "Execute" Button. Change the Time window if needed. This will provide a graph similar to this one: + + ![Prom Graph](media/lab7_prometheus-graph.png) + + Take a few minutes to explore other metrics available from NGINX Plus. What are the Upstream Response Times of your 3 backend web servers??? + +
+ +### Grafana + +
+ +Grafana is a data visualization tool, which contains a time series database and graphical web presentation tools. Grafana imports the Prometheus scraper page statistics into it's database, and allows you to create Dashboards of the statistics that are important to you. + +1. Log into the Web console access for Grafana at . The default Login should be user/pass of `admin/admin`. This will present the main Grafana page. + +1. Create a Prometheus Data Source. In the middle of the Grafana Welcome page, click on `Add your first Data Source`, and Select the Prometheus icon. + +1. Set the Connection URL to `http://prometheus:9090` as shown: + + ![Prom Datasource](media/lab7_prometheus-datasource.png) + +1. Scroll to the bottom and click `Save and Test`. You should see a green `Successfully queried the Prometheus API` message. Click the Home page link to return the main menu. + +1. Import the provided `labs/lab7/NGINX-Basics.json` file to see statistics like the NGINX Plus HTTP Requests Per Second and Upstream Response Times. + + - Click on Create New Dashboard from Home page and then `Import dashboard`. + - Copy and Paste the `labs/lab7/NGINX-Basics.json` file provided. + - Click on the `Load` button. + - Set the data source to `prometheus` and then click on the `Import` button. + - Sometimes you have change the datasource, Dashboard ID, Name, or other settings for it to Import properly. + + You should see a Grafana Dashboard like this one: + + ![Grafana Dashboard](media/lab7_grafana-dashboard.png) + + There are many different Grafana Dashboards available, and you have the option to create and build dashboards to suite your needs. NGINX Plus provides over 240 metrics for TCP, HTTP, SSL, Virtual Servers, Locations, Rate Limits, and Upstreams. + + Take a few minutes to explore Grafana, and you can also import Dashboards that other people have created, by exploring the Grafana website and searching for "nginx". + +
+ +## Wrap Up + +1. If the `wrk` load generation tool is still running, then you can stop it by pressing `Ctrl + C`. + +1. If you are finished with this lab, you can use Docker Compose to shut down your test environment. Make sure you are in the `lab7` folder: + + ```bash + cd lab7 + docker compose down + + ``` + + ```bash + ##Sample output## + Running 5/5 + Container nginx-plus Removed + Container web2 Removed + Container prometheus Removed + Container web3 Removed + Container web1 Removed + Container grafana Removed + Network lab7_default Removed + + ``` + +
**This completes Lab7.** -## References +
+ +## References: +- [NGINX Plus](https://www.nginx.com/products/nginx/) +- [NGINX Admin Guide](https://docs.nginx.com/nginx/admin-guide/) +- [NGINX Technical Specs](https://docs.nginx.com/nginx/technical-specs/) +- [NGINX Prometheus Exporter Metrics](https://github.com/nginxinc/nginx-prometheus-exporter?tab=readme-ov-file#exported-metrics) +- [Prometheus](prometheus.io) +- [Grafana](grafana.com) +- [NGINX Prometheus/Grafana Blog](https://www.f5.com/company/blog/nginx/how-to-visualize-nginx-plus-with-prometheus-and-grafana) +
### Authors @@ -25,4 +280,4 @@ ------------- -Navigate to ([Lab8](../lab8/readme.md) | [Main Menu](../readme.md)) +Navigate to ([Lab8](../lab8/readme.md) | [LabGuide](../readme.md)) \ No newline at end of file diff --git a/labs/lab8/readme.md b/labs/lab8/readme.md index 42b6f43..3ae2538 100644 --- a/labs/lab8/readme.md +++ b/labs/lab8/readme.md @@ -1,271 +1,21 @@ -# Monitoring NGINX Plus with Prometheus and Grafana +# Upgrade Dataplane NGINX Plus Instances to R33 ## Introduction -In this lab, you will be exploring the integration between NGINX Plus, Prometheus and Grafana. -This Solution requires the use of the NGINX provided Javascript and Prometheus modules to collect metrics from the NGINX Plus API, and export those metrics as an HTTP html/text page, commonly called the `scaper page` because it scrapes statistics for publication. The metrics on this export page are then read and imported into Prometheus and Grafana's time-series database. Once these metrics are in the database, you can create many different Dashboards, Thresholds, Alerts, and other types of graphs for Visualization and Reporting. As you can imagine, there are literally hundreds of Grafana dashboards written by users of NGINX that you can try out for free. Grafana also allows you to create and edit your own Dashboards. -NGINX Plus | Prometheus | Grafana -:-------------------------:|:-------------------------:|:-----: -![NGINX Plus](media/nginx-plus-icon.png) |![Prom](media/prometheus-icon.png) |![Grafana](media/grafana-icon.png) - ## Learning Objectives -By the end of the lab you will be able to: -- Enable and configure NGINX Java Script -- Create Prometheus Exporter configuration -- Test the Prometheus Server -- Test the Grafana Server -- View Grafana Dashboard -## Pre-Requisites +## Prerequisites -- Nginx-Plus container from Lab1 -- You must have Docker installed and running -- You must have Docker-compose installed -- See `Lab0` for instructions on setting up your system for this Workshop -- Familiarity with basic Linux commands and commandline tools -- Familiarity with basic Docker concepts and commands -- Familiarity with basic HTTP protocol -- Familiarity with Prometheus -- Familiartiy with Grafana - -As part of your Dockerfile, your NGINX Plus container already has the added `NGINX Java Script and NGINX Prometheus dynamic module` installed during the build process. Refer to the /lab1/nginx-plus/Dockerfile if you want to check it out. - -1. Ensure you are in the `lab6` folder. Using a Terminal, run Docker Compose to build and run all the containers. - - ```bash - cd lab6 - docker compose up --force-recreate -d - - ``` - -1. Edit your `nginx.conf` file, you will make 2 changes. - - - Uncomment Line #8 to enable the `ngx_http_js_module` module. - - Uncomment Line #37 to set a parameter for an NGINX buffer called `subrequest_output_buffer_size`. - - ```nginx - ...snip - - user nginx; - worker_processes auto; - - error_log /var/log/nginx/error.log info; - pid /var/run/nginx.pid; - - # Uncomment to enable NGINX JavaScript module - load_module modules/ngx_http_js_module.so; # Added for Prometheus - - ...snip - - # Uncomment for Prometheus scraper page output - subrequest_output_buffer_size 32k; # Added for Prometheus - - ...snip - - ``` - -1. Inspect the `prometheus.conf` file in the `labs/lab6/nginx-plus/etc/nginx/conf.d` folder. This is the NGINX config file which opens up port 9113, and provides access to the scraper page. Uncomment all the lines to enable this. - - ```nginx - # NGINX Plus Prometheus configuration, for HTTP scraper page - # Chris Akker, Shouvik Dutta - Feb 2024 - # https://www.nginx.com/blog/how-to-visualize-nginx-plus-with-prometheus-and-grafana/ - # Nginx Basics - # - # Uncomment all lines below - js_import /usr/share/nginx-plus-module-prometheus/prometheus.js; - - server { - - listen 9113; # This is the default port for Prometheus scraper page - - location = /metrics { - js_content prometheus.metrics; - } - - location /api { - api; - } - - } - - ``` - -1. Once the contents of both files has been updated and saved, Docker Exec into the nginx-plus container. - - ```bash - docker exec -it nginx-plus bin/bash - - ``` - -1. Test and reload your NGINX config by running `nginx -t` and `nginx -s reload` commands respectively from within the container. - -1. Start the WRK load generation tool. This will provide some traffic to the nginx-plus container, so the statistics will be increasing. - - ```bash - docker run --name wrk --network=lab6_default --rm williamyeh/wrk -t4 -c200 -d20m -H 'Host: cafe.example.com' --timeout 2s http://nginx-plus/coffee - - ``` - -1. Test the Prometheus scraper page. Open your browser to . You should see an html/text page like this one. You will notice there are MANY statistcs available, this page is like a text version of the NGINX Plus dashboard. This page can be easily imported into your existing Performance Management and Monitoring tools. You will see how to do this in the next section with Prometheus and Grafana. - - Click refresh a couple times, and some of the metrics should increment. - - ![Scraper page](media/lab6_scraper_page1.png) - -
- -## Prometheus and Grafana Server Docker containers - -
- -![prometheus](media/prometheus-icon.png) |![grafana](media/grafana-icon.png) ---- | --- - -1. Inspect your `docker-compose.yml` file, you will see it includes 2 additional Docker containers for this lab, one for a Prometheus server, and one for a Grafana server. These have been configured to run for you, but the images will be pulled from public repos. - - ```bash - ...snip - - prometheus: - hostname: prometheus - container_name: prometheus - image: prom/prometheus - volumes: - - ./nginx-plus/etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml - ports: - - "9090:9090" - restart: always - depends_on: - - nginx-plus - grafana: - hostname: grafana - container_name: grafana - volumes: - - grafana-storage:/var/lib/grafana - image: grafana/grafana - ports: - - "3000:3000" - restart: always - depends_on: - - nginx-plus - volumes: - grafana-storage: - name: "grafana-storage" - external: false - - ``` - -1. Verify these 2 containers are running. - - ```bash - docker ps -a - - ``` - - ```bash - ##Sample output## - CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES - 8a61c66fc511 prom/prometheus "/bin/prometheus --c…" 36 minutes ago Up 36 minutes 0.0.0.0:9090->9090/tcp prometheus - 4d38710ed4ec grafana/grafana "/run.sh" 36 minutes ago Up 36 minutes 0.0.0.0:3000->3000/tcp grafana - - ...snip - - ``` - -
- -### Prometheus - -
- -Prometheus is a software package that can watch and collect statistics from many different NGINX instances. The Prometheus server will collect the statistics from the scraper page that you enabled in the previous section. - -
- -1. Using Chrome, navigate to . You should see a Prometheus webpage like this one. Search for `nginxplus_` in the query box to see a list of all the Nginx Plus statistics that Prometheus is collecting for you. Select `nginxplus_http_requests_total` from the list, click on Graph, and then click the "Execute" Button. Change the Time window if needed. This will provide a graph similar to this one: - - ![Prom Graph](media/lab6_prometheus-graph.png) - - Take a few minutes to explore other metrics available from NGINX Plus. What are the Upstream Response Times of your 3 backend web servers??? - -
- -### Grafana - -
- -Grafana is a data visualization tool, which contains a time series database and graphical web presentation tools. Grafana imports the Prometheus scraper page statistics into it's database, and allows you to create Dashboards of the statistics that are important to you. - -1. Log into the Web console access for Grafana at . The default Login should be user/pass of `admin/admin`. This will present the main Grafana page. - -1. Create a Prometheus Data Source. In the middle of the Grafana Welcome page, click on `Add your first Data Source`, and Select the Prometheus icon. - -1. Set the Connection URL to `http://prometheus:9090` as shown: - - ![Prom Datasource](media/lab6_prometheus-datasource.png) - -1. Scroll to the bottom and click `Save and Test`. You should see a green `Successfully queried the Prometheus API` message. Click the Home page link to return the main menu. - -1. Import the provided `labs/lab6/NGINX-Basics.json` file to see statistics like the NGINX Plus HTTP Requests Per Second and Upstream Response Times. -- Click on Create New Dashboard from Home page and then `Import dashboard`. -- Copy and Paste the `labs/lab6/NGINX-Basics.json` file provided. -- Click on the `Load` button. -- Set the data source to `prometheus` and then click on the `Import` button. -- Sometimes you have change the datasource, Dashboard ID, Name, or other settings for it to Import properly. - -You should see a Grafana Dashboard like this one: - - ![Grafana Dashboard](media/lab6_grafana-dashboard.png) - - There are many different Grafana Dashboards available, and you have the option to create and build dashboards to suite your needs. NGINX Plus provides over 240 metrics for TCP, HTTP, SSL, Virtual Servers, Locations, Rate Limits, and Upstreams. - - Take a few minutes to explore Grafana, and you can also import Dashboards that other people have created, by exploring the Grafana website and searching for "nginx". - -> If the `wrk` load generation tool is still running, then you can stop it by pressing `Ctrl + C`. - ->If you are finished with this lab, you can use Docker Compose to shut down your test environment. Make sure you are in the `lab6` folder: - -```bash -cd lab6 -docker compose down - -``` - -```bash -##Sample output## -Running 5/5 -Container nginx-plus Removed -Container web2 Removed -Container prometheus Removed -Container web3 Removed -Container web1 Removed -Container grafana Removed -Network lab6_default Removed - -``` - -
**This completes Lab8.** -
- -## References: +## References -- [NGINX Plus](https://www.nginx.com/products/nginx/) -- [NGINX Admin Guide](https://docs.nginx.com/nginx/admin-guide/) -- [NGINX Technical Specs](https://docs.nginx.com/nginx/technical-specs/) -- [NGINX Prometheus Exporter Metrics](https://github.com/nginxinc/nginx-prometheus-exporter?tab=readme-ov-file#exported-metrics) -- [Prometheus](prometheus.io) -- [Grafana](grafana.com) -- [NGINX Prometheus/Grafana Blog](https://www.f5.com/company/blog/nginx/how-to-visualize-nginx-plus-with-prometheus-and-grafana) -
### Authors @@ -275,4 +25,4 @@ Network lab6_default Removed ------------- -Navigate to ([Main Menu](../readme.md)) \ No newline at end of file +Navigate to ([LabGuide](../readme.md)) diff --git a/labs/readme.md b/labs/readme.md index cca96bd..89f6505 100644 --- a/labs/readme.md +++ b/labs/readme.md @@ -72,11 +72,12 @@ Choose one of the [Lab 0: Workshop pre-work](#lab-0-workshop-pre-work-choose-any ### Lab 6: NGINX Plus Logs, Logging and Troubleshooting - [Lab 6: NGINX Plus Logs, Logging and Troubleshooting](lab6/readme.md) -### Lab 7: Upgrade Dataplane NGINX Plus Instances to R33 -- [Lab 7: Upgrade Dataplane NGINX Plus Instances to R33](lab7/readme.md) +### Lab 7: Monitoring NGINX Plus with Prometheus and Grafana +- [Lab 7: Monitoring NGINX Plus with Prometheus and Grafana](lab7/readme.md) + +### Lab 8: Upgrade Dataplane NGINX Plus Instances to R33 +- [Lab 8: Upgrade Dataplane NGINX Plus Instances to R33](lab8/readme.md) -### Lab 8: Monitoring NGINX Plus with Prometheus and Grafana -- [Lab 8: Monitoring NGINX Plus with Prometheus and Grafana](lab8/readme.md)