Skip to content

Commit 3586cba

Browse files
committed
lab7 & 8 swap
1 parent e25beba commit 3586cba

32 files changed

+265
-260
lines changed

labs/lab4/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,4 +306,4 @@ This ends lab4.
306306

307307
---
308308

309-
Navigate to ([LabGuide](../readme.md))
309+
Navigate to ([Lab5](../lab5/readme.md) | [LabGuide](../readme.md))

labs/lab5/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,4 +1247,4 @@ With NGINX, there are several configuration options for this, but in this next l
12471247
12481248
-------------
12491249
1250-
Navigate to ([Lab6](../lab6/readme.md) | [Main Menu](../readme.md))
1250+
Navigate to ([Lab6](../lab6/readme.md) | [LabGuide](../readme.md))
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

labs/lab7/readme.md

Lines changed: 259 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,276 @@
1-
# Upgrade Dataplane NGINX Plus Instances to R33
1+
# Monitoring NGINX Plus with Prometheus and Grafana
22

33
## Introduction
44

5+
In this lab, you will be exploring the integration between NGINX Plus, Prometheus and Grafana.
56

7+
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.
68

9+
NGINX Plus | Prometheus | Grafana
10+
:-------------------------:|:-------------------------:|:-----:
11+
![NGINX Plus](media/nginx-plus-icon.png) |![Prom](media/prometheus-icon.png) |![Grafana](media/grafana-icon.png)
12+
713
## Learning Objectives
814

15+
By the end of the lab you will be able to:
916

17+
- Enable and configure NGINX Java Script
18+
- Create Prometheus Exporter configuration
19+
- Test the Prometheus Server
20+
- Test the Grafana Server
21+
- View Grafana Dashboard
1022

11-
## Prerequisites
23+
## Pre-Requisites
1224

25+
- Nginx-Plus container from Lab1
26+
- You must have Docker installed and running
27+
- You must have Docker-compose installed
28+
- See `Lab0` for instructions on setting up your system for this Workshop
29+
- Familiarity with basic Linux commands and commandline tools
30+
- Familiarity with basic Docker concepts and commands
31+
- Familiarity with basic HTTP protocol
32+
- Familiarity with Prometheus
33+
- Familiartiy with Grafana
34+
35+
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.
36+
37+
1. Ensure you are in the `lab7` folder. Using a Terminal, run Docker Compose to build and run all the containers.
38+
39+
```bash
40+
cd lab6
41+
docker compose up --force-recreate -d
42+
43+
```
44+
45+
1. Edit your `nginx.conf` file, you will make 2 changes.
46+
47+
- Uncomment Line #8 to enable the `ngx_http_js_module` module.
48+
- Uncomment Line #37 to set a parameter for an NGINX buffer called `subrequest_output_buffer_size`.
49+
50+
```nginx
51+
...snip
52+
53+
user nginx;
54+
worker_processes auto;
55+
56+
error_log /var/log/nginx/error.log info;
57+
pid /var/run/nginx.pid;
58+
59+
# Uncomment to enable NGINX JavaScript module
60+
load_module modules/ngx_http_js_module.so; # Added for Prometheus
61+
62+
...snip
63+
64+
# Uncomment for Prometheus scraper page output
65+
subrequest_output_buffer_size 32k; # Added for Prometheus
66+
67+
...snip
68+
69+
```
70+
71+
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.
72+
73+
```nginx
74+
# NGINX Plus Prometheus configuration, for HTTP scraper page
75+
# Chris Akker, Shouvik Dutta - Feb 2024
76+
# https://www.nginx.com/blog/how-to-visualize-nginx-plus-with-prometheus-and-grafana/
77+
# Nginx Basics
78+
#
79+
# Uncomment all lines below
80+
js_import /usr/share/nginx-plus-module-prometheus/prometheus.js;
81+
82+
server {
83+
84+
listen 9113; # This is the default port for Prometheus scraper page
85+
86+
location = /metrics {
87+
js_content prometheus.metrics;
88+
}
89+
90+
location /api {
91+
api;
92+
}
93+
94+
}
95+
96+
```
97+
98+
1. Once the contents of both files has been updated and saved, Docker Exec into the nginx-plus container.
99+
100+
```bash
101+
docker exec -it nginx-plus bin/bash
102+
103+
```
104+
105+
1. Test and reload your NGINX config by running `nginx -t` and `nginx -s reload` commands respectively from within the container.
106+
107+
1. Start the WRK load generation tool. This will provide some traffic to the nginx-plus container, so the statistics will be increasing.
108+
109+
```bash
110+
docker run --name wrk --network=lab6_default --rm williamyeh/wrk -t4 -c200 -d20m -H 'Host: cafe.example.com' --timeout 2s http://nginx-plus/coffee
111+
112+
```
113+
114+
1. Test the Prometheus scraper page. Open your browser to <http://localhost:9113/metrics>. 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.
115+
116+
Click refresh a couple times, and some of the metrics should increment.
117+
118+
![Scraper page](media/lab7_scraper_page1.png)
119+
120+
<br/>
121+
122+
## Prometheus and Grafana Server Docker containers
123+
124+
<br/>
125+
126+
![prometheus](media/prometheus-icon.png) |![grafana](media/grafana-icon.png)
127+
--- | ---
128+
129+
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.
130+
131+
```bash
132+
...snip
133+
134+
prometheus:
135+
hostname: prometheus
136+
container_name: prometheus
137+
image: prom/prometheus
138+
volumes:
139+
- ./nginx-plus/etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
140+
ports:
141+
- "9090:9090"
142+
restart: always
143+
depends_on:
144+
- nginx-plus
145+
grafana:
146+
hostname: grafana
147+
container_name: grafana
148+
volumes:
149+
- grafana-storage:/var/lib/grafana
150+
image: grafana/grafana
151+
ports:
152+
- "3000:3000"
153+
restart: always
154+
depends_on:
155+
- nginx-plus
156+
volumes:
157+
grafana-storage:
158+
name: "grafana-storage"
159+
external: false
160+
161+
```
162+
163+
1. Verify these 2 containers are running.
164+
165+
```bash
166+
docker ps -a
167+
168+
```
169+
170+
```bash
171+
##Sample output##
172+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
173+
8a61c66fc511 prom/prometheus "/bin/prometheus --c…" 36 minutes ago Up 36 minutes 0.0.0.0:9090->9090/tcp prometheus
174+
4d38710ed4ec grafana/grafana "/run.sh" 36 minutes ago Up 36 minutes 0.0.0.0:3000->3000/tcp grafana
175+
176+
...snip
177+
178+
```
179+
180+
<br/>
181+
182+
### Prometheus
183+
184+
<br/>
185+
186+
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.
187+
188+
<br/>
189+
190+
1. Using Chrome, navigate to <http://localhost:9090>. 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:
191+
192+
![Prom Graph](media/lab7_prometheus-graph.png)
193+
194+
Take a few minutes to explore other metrics available from NGINX Plus. What are the Upstream Response Times of your 3 backend web servers???
195+
196+
<br/>
197+
198+
### Grafana
199+
200+
<br/>
201+
202+
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.
203+
204+
1. Log into the Web console access for Grafana at <http://localhost:3000>. The default Login should be user/pass of `admin/admin`. This will present the main Grafana page.
205+
206+
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.
207+
208+
1. Set the Connection URL to `http://prometheus:9090` as shown:
209+
210+
![Prom Datasource](media/lab7_prometheus-datasource.png)
211+
212+
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.
213+
214+
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.
215+
216+
- Click on Create New Dashboard from Home page and then `Import dashboard`.
217+
- Copy and Paste the `labs/lab7/NGINX-Basics.json` file provided.
218+
- Click on the `Load` button.
219+
- Set the data source to `prometheus` and then click on the `Import` button.
220+
- Sometimes you have change the datasource, Dashboard ID, Name, or other settings for it to Import properly.
221+
222+
You should see a Grafana Dashboard like this one:
223+
224+
![Grafana Dashboard](media/lab7_grafana-dashboard.png)
225+
226+
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.
227+
228+
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".
229+
230+
<br/>
231+
232+
## Wrap Up
233+
234+
1. If the `wrk` load generation tool is still running, then you can stop it by pressing `Ctrl + C`.
235+
236+
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:
237+
238+
```bash
239+
cd lab7
240+
docker compose down
241+
242+
```
243+
244+
```bash
245+
##Sample output##
246+
Running 5/5
247+
Container nginx-plus Removed
248+
Container web2 Removed
249+
Container prometheus Removed
250+
Container web3 Removed
251+
Container web1 Removed
252+
Container grafana Removed
253+
Network lab7_default Removed
254+
255+
```
256+
257+
<br/>
13258
14259
**This completes Lab7.**
15260
16-
## References
261+
<br/>
262+
263+
## References:
17264
265+
- [NGINX Plus](https://www.nginx.com/products/nginx/)
266+
- [NGINX Admin Guide](https://docs.nginx.com/nginx/admin-guide/)
267+
- [NGINX Technical Specs](https://docs.nginx.com/nginx/technical-specs/)
268+
- [NGINX Prometheus Exporter Metrics](https://github.com/nginxinc/nginx-prometheus-exporter?tab=readme-ov-file#exported-metrics)
269+
- [Prometheus](prometheus.io)
270+
- [Grafana](grafana.com)
271+
- [NGINX Prometheus/Grafana Blog](https://www.f5.com/company/blog/nginx/how-to-visualize-nginx-plus-with-prometheus-and-grafana)
18272
273+
<br/>
19274
20275
### Authors
21276
@@ -25,4 +280,4 @@
25280
26281
-------------
27282
28-
Navigate to ([Lab8](../lab8/readme.md) | [Main Menu](../readme.md))
283+
Navigate to ([Lab8](../lab8/readme.md) | [LabGuide](../readme.md))

0 commit comments

Comments
 (0)