ingress-nginx-helm/docs/examples/customization/custom-vts-metrics-prometheus/README.md

104 lines
3.7 KiB
Markdown
Raw Normal View History

2017-10-03 10:43:45 +00:00
# Deploying the Nginx Ingress controller
2017-10-09 06:05:57 +00:00
This example aims to demonstrate the deployment of an nginx ingress controller and use a ConfigMap to enable [nginx vts module](https://github.com/vozlt/nginx-module-vts
2017-10-03 10:43:45 +00:00
) to export metrics in prometheus format.
## vts-metrics
2017-10-03 10:43:45 +00:00
Vts-metrics export NGINX metrics. To deploy all the files simply run `kubectl apply -f nginx`. A deployment and service will be
created which already has a `prometheus.io/scrape: 'true'` annotation and if you added
the recommended Prometheus service-endpoint scraping [configuration](https://raw.githubusercontent.com/prometheus/prometheus/master/documentation/examples/prometheus-kubernetes.yml),
Prometheus will scrape it automatically and you start using the generated metrics right away.
## Custom configuration
```console
apiVersion: v1
data:
enable-vts-status: "true"
kind: ConfigMap
metadata:
name: nginx-configuration
namespace: ingress-nginx
labels:
app: ingress-nginx
2017-10-03 10:43:45 +00:00
```
```console
$ kubectl apply -f nginx-vts-metrics-conf.yaml
2017-10-03 10:43:45 +00:00
```
## Result
2017-10-03 10:43:45 +00:00
Check whether the ingress controller successfully generated the NGINX vts status:
2017-10-03 10:43:45 +00:00
```console
$ kubectl exec nginx-ingress-controller-873061567-4n3k2 -n ingress-nginx cat /etc/nginx/nginx.conf|grep vhost_traffic_status_display
2017-10-03 10:43:45 +00:00
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
```
2017-10-03 10:43:45 +00:00
### NGINX vts dashboard
2017-10-03 10:43:45 +00:00
The vts dashboard provides real time metrics.
![vts dashboard](imgs/vts-dashboard.png)
Because the vts port it's not yet exposed, you should forward the controller port to see it.
```console
$ kubectl port-forward $(kubectl get pods --selector=k8s-app=nginx-ingress-controller -n ingress-nginx --output=jsonpath={.items..metadata.name}) -n ingress-nginx 18080
2017-10-03 10:43:45 +00:00
```
Now open the url [http://localhost:18080/nginx_status](http://localhost:18080/nginx_status) in your browser.
### Prometheus metrics output
2017-10-03 10:43:45 +00:00
NGINX Ingress controller already has a parser to convert vts metrics to Prometheus format. It exports prometheus metrics to the address `:10254/metrics`.
```console
$ kubectl exec -ti -n ingress-nginx $(kubectl get pods --selector=k8s-app=nginx-ingress-controller -n kube-system --output=jsonpath={.items..metadata.name}) curl localhost:10254/metrics
2017-10-03 10:43:45 +00:00
ingress_controller_ssl_expire_time_seconds{host="foo.bar.com"} -6.21355968e+10
# HELP ingress_controller_success Cumulative number of Ingress controller reload operations
# TYPE ingress_controller_success counter
ingress_controller_success{count="reloads"} 3
# HELP nginx_bytes_total Nginx bytes count
# TYPE nginx_bytes_total counter
nginx_bytes_total{direction="in",ingress_class="nginx",namespace="",server_zone="*"} 3708
nginx_bytes_total{direction="in",ingress_class="nginx",namespace="",server_zone="_"} 3708
nginx_bytes_total{direction="out",ingress_class="nginx",namespace="",server_zone="*"} 5256
nginx_bytes_total{direction="out",ingress_class="nginx",namespace="",server_zone="_"} 5256
```
### Customize metrics
2017-11-19 17:25:50 +00:00
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 grouped by server and country code. The example below show how to have metrics grouped by server and server path.
2017-10-03 10:43:45 +00:00
![vts dashboard](imgs/vts-dashboard-filter-key-path.png)
## NGINX custom configuration ( http level )
```
apiVersion: v1
kind: ConfigMap
data:
enable-vts-status: "true"
vts-default-filter-key: "$server_name"
...
```
## Customize ingress
```
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
2017-11-24 18:46:51 +00:00
nginx.ingress.kubernetes.io/vts-filter-key: $uri $server_name
2017-10-03 10:43:45 +00:00
name: ingress
```
## Result
![prometheus filter key path](imgs/prometheus-filter-key-path.png)