Skip to content

Commit 180d0df

Browse files
authored
Merge pull request #1465 from gianrubio/prometheus-docs
review prometheus docs
2 parents 88e6af5 + 0813704 commit 180d0df

File tree

9 files changed

+128
-63
lines changed

9 files changed

+128
-63
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Deploying the Nginx Ingress controller
2+
3+
This example aims to demonstrate the deployment of an nginx ingress controller and use a ConfigMap to enable [nginx vts module](github.com/vozlt/nginx-module-vts
4+
) to export metrics in prometheus format.
5+
6+
# vts-metrics
7+
8+
Vts-metrics export NGINX metrics. To deploy all the files simply run `kubectl apply -f nginx`. A deployment and service will be
9+
created which already has a `prometheus.io/scrape: 'true'` annotation and if you added
10+
the recommended Prometheus service-endpoint scraping [configuration](https://raw.githubusercontent.com/prometheus/prometheus/master/documentation/examples/prometheus-kubernetes.yml),
11+
Prometheus will scrape it automatically and you start using the generated metrics right away.
12+
13+
## Default Backend
14+
15+
The default backend is a Service capable of handling all url paths and hosts the
16+
nginx controller doesn't understand. This most basic implementation just returns
17+
a 404 page:
18+
19+
```console
20+
$ kubectl apply -f default-backend.yaml
21+
deployment "default-http-backend" created
22+
service "default-http-backend" created
23+
24+
$ kubectl -n kube-system get po
25+
NAME READY STATUS RESTARTS AGE
26+
default-http-backend-2657704409-qgwdd 1/1 Running 0 28s
27+
```
28+
29+
## Custom configuration
30+
31+
```console
32+
$ cat nginx-vts-metrics-conf.yaml
33+
apiVersion: v1
34+
data:
35+
enable-vts-status: "true"
36+
kind: ConfigMap
37+
metadata:
38+
name: nginx-vts-metrics-conf
39+
namespace: kube-system
40+
```
41+
42+
```console
43+
$ kubectl create -f nginx-vts-metrics-conf.yaml
44+
```
45+
46+
## Controller
47+
48+
You can deploy the controller as follows:
49+
50+
```console
51+
$ kubectl apply -f nginx-ingress-controller.yaml
52+
deployment "nginx-ingress-controller" created
53+
54+
$ kubectl -n kube-system get po
55+
NAME READY STATUS RESTARTS AGE
56+
default-http-backend-2657704409-qgwdd 1/1 Running 0 2m
57+
nginx-ingress-controller-873061567-4n3k2 1/1 Running 0 42s
58+
```
59+
60+
## Result
61+
Check whether the ingress controller successfully generated the NGINX vts status:
62+
```console
63+
$ kubectl exec nginx-ingress-controller-873061567-4n3k2 -n kube-system cat /etc/nginx/nginx.conf|grep vhost_traffic_status_display
64+
vhost_traffic_status_display;
65+
vhost_traffic_status_display_format html;
66+
```
67+
### NGINX vts dashboard
68+
The vts dashboard provides real time metrics.
69+
70+
![vts dashboard](imgs/vts-dashboard.png)
71+
72+
Because the vts port it's not yet exposed, you should forward the controller port to see it.
73+
74+
```console
75+
$ kubectl port-forward $(kubectl get pods --selector=k8s-app=nginx-ingress-controller -n kube-system --output=jsonpath={.items..metadata.name}) -n kube-system 18080
76+
```
77+
78+
Now open the url [http://localhost:18080/nginx_status](http://localhost:18080/nginx_status) in your browser.
79+
80+
81+
### Prometheus metrics output
82+
NGINX Ingress controller already has a parser to convert vts metrics to Prometheus format. It exports prometheus metrics to the address `:10254/metrics`.
83+
84+
```console
85+
$ kubectl exec -ti -n kube-system $(kubectl get pods --selector=k8s-app=nginx-ingress-controller -n kube-system --output=jsonpath={.items..metadata.name}) curl localhost:10254/metrics
86+
ingress_controller_ssl_expire_time_seconds{host="foo.bar.com"} -6.21355968e+10
87+
# HELP ingress_controller_success Cumulative number of Ingress controller reload operations
88+
# TYPE ingress_controller_success counter
89+
ingress_controller_success{count="reloads"} 3
90+
# HELP nginx_bytes_total Nginx bytes count
91+
# TYPE nginx_bytes_total counter
92+
nginx_bytes_total{direction="in",ingress_class="nginx",namespace="",server_zone="*"} 3708
93+
nginx_bytes_total{direction="in",ingress_class="nginx",namespace="",server_zone="_"} 3708
94+
nginx_bytes_total{direction="out",ingress_class="nginx",namespace="",server_zone="*"} 5256
95+
nginx_bytes_total{direction="out",ingress_class="nginx",namespace="",server_zone="_"} 5256
96+
```
97+
98+
### Customize metrics
99+
100+
The default [vts vhost key](https://github.com/vozlt/nginx-module-vts#vhost_traffic_status_filter_by_set_key) is `$geoip_country_code country::*` that expose metrics groupped by server and country code. The example below show how to have metrics grouped by server and server path.
101+
102+
![vts dashboard](imgs/vts-dashboard-filter-key-path.png)
103+
104+
## NGINX custom configuration ( http level )
105+
106+
```
107+
apiVersion: v1
108+
kind: ConfigMap
109+
data:
110+
enable-vts-status: "true"
111+
vts-default-filter-key: "$server_name"
112+
...
113+
```
114+
115+
## Customize ingress
116+
117+
```
118+
apiVersion: extensions/v1beta1
119+
kind: Ingress
120+
metadata:
121+
annotations:
122+
ingress.kubernetes.io/vts-filter-key: $uri $server_name
123+
name: ingress
124+
```
125+
126+
## Result
127+
128+
![prometheus filter key path](imgs/prometheus-filter-key-path.png)
Loading

examples/customization/custom-vts-metrics/nginx/README.md

-63
This file was deleted.

0 commit comments

Comments
 (0)