prometheus监控nginx
添加nginx-module-vts模块
# git clone https://github.com/vozlt/nginx-module-vts.git
# mv nginx-module-vts /usr/local/src
配置nginx
# wget http://nginx.org/download/nginx-1.20.2.tar.gz
# tar xvf nginx-1.20.2.tar.gz
# cd nginx-1.20.2/
# yum -y install openssl openssl-devel make zlib zlib-devel gcc gcc-c++ libtool pcre pcre-devel
# ./configure --prefix=/apps/nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
--with-file-aio \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module \
--add-module=/usr/local/src/nginx-module-vts/
# make
# make install
添加nginx状态页
vim /apps/nginx/conf/nginx.conf
vhost_traffic_status_zone;
location /status {
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
}
检测配置文件,没有问题直接启动
/apps/nginx/sbin/nginx -t
/apps/nginx/sbin/nginx
访问状态页
配置nginx-vts-exporter并启动,转换数据为key value格式
https://github.com/hnlq715/nginx-vts-exporter/releases/download/v0.10.3/nginx-vts-exporter-0.10.3.linux-amd64.tar.gz
cp nginx-vts-exporter-0.10.3.linux-amd64/nginx-vts-exporter /usr/local/bin/
nginx-vts-exporter -nginx.scrape_uri http://10.211.55.20/status/format/json
配置prometheus.yml
- job_name: "prometheus-nginx-metrics"
static_configs:
- targets: ["10.211.55.20:9913"]
导入模板