Имеется два експортёра для NGINX — discordianfish/nginx_exporter и hnlq715/nginx-vts-exporter.
Второй предоставляет больше возможностей, но мне сейчас нужны самые базовые, поэтому использую discordianfish/nginx_exporter.
Содержание
NGINX status
Сначала — добавим /nginx_status
в NGINX.
Проверяем — собран ли NGINX со статус-модулем:
[simterm]
root@bm-backed-app-dev:/opt/prometheus-client# nginx -V 2>&1 | grep -o with-http_stub_status_module with-http_stub_status_module
[/simterm]
Я добавил отдельный конфиг /etc/nginx/conf.d/status.conf
с default_server
, который принимает запросы на статус:
server { charset utf-8; listen 80 default_server; server_name _; location /nginx_status { stub_status on; access_log off; allow 127.0.0.1; deny all; } }
Проверяем конфиг, перезапускаем:
[simterm]
root@bm-backed-app-dev:/opt/prometheus-client# nginx -t && service nginx reload nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
[/simterm]
Проверяем статус:
[simterm]
root@bm-backed-app-dev:/opt/prometheus-client# curl -s localhost/nginx_status Active connections: 2 server accepts handled requests 41306 41306 42275 Reading: 0 Writing: 1 Waiting: 1
[/simterm]
nginx_exporter
Запускаем екпортёр:
[simterm]
root@bm-backed-app-dev:/opt/prometheus-client# docker run -p 9113:9113 fish/nginx-exporter -nginx.scrape_uri=http://localhost/nginx_status Unable to find image 'fish/nginx-exporter:latest' locally latest: Pulling from fish/nginx-exporter 91d086a909e1: Pull complete a3ed95caeb02: Pull complete 8d6a08280da7: Pull complete 8ba3ebf9e0b6: Pull complete Digest: sha256:208acc68a1ac581be6d101264445bde55ebbda11e6607dd699cb1015822f2dd1 Status: Downloaded newer image for fish/nginx-exporter:latest time="2018-07-19T09:19:55Z" level=info msg="Starting Server: :9113" source="nginx_exporter.go:185"
[/simterm]
Проверяем метрики:
[simterm]
admin@bm-backed-app-dev:~$ curl -s localhost:9113/metrics | grep -v \# | grep nginx_ nginx_connections_current{state="active"} 1 nginx_connections_current{state="reading"} 0 nginx_connections_current{state="waiting"} 0 nginx_connections_current{state="writing"} 1 nginx_connections_processed_total{stage="accepted"} 41322 nginx_connections_processed_total{stage="any"} 42294 nginx_connections_processed_total{stage="handled"} 41322 nginx_up 1
[/simterm]
Добавляем его в Compose файл к остальным експортёрам:
... nginx_exporter: image: fish/nginx-exporter network_mode: "host" command: - 'nginx.scrape_uri=http://localhost/nginx_status'
Готово.