nginx-vts-exporter
安装包下载,注意下载nginx版本需要和生产环境保持一致
wget https://github.com/vozlt/nginx-module-vts/archive/refs/tags/v0.2.2.tar.gz |
解压nginx-module-vts
tar xf nginx-module-vts-0.2.3.tar.gz -C /usr/local/src/ |
查看运行nginx编译参数
nginx -V |
./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_perl_module=dynamic --with-http_auth_request_module --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/generic-hardened-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/generic-hardened-ld -Wl,-E' |
创建nginx用户
useradd -r -M -s /usr/sbin/nologin nginx |
安装编译环境
yum install pcre-devel openssl-devel libxml2-devel libxslt-devel gd-devel gperftools gperftools-devel |
解压nginx源码
tar xf nginx-1.26.2.tar.gz |
再原来编译参数基础上添加vts模块,进行编译
./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_perl_module=dynamic --with-http_auth_request_module --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/generic-hardened-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/generic-hardened-ld -Wl,-E' --add-module=/usr/local/src/nginx-module-vts-0.2.2/ |
备份nginx配置文件
cd /usr/local/nginx/conf |
nginx配置文件添加配置
#在nginx.conf http块添加如下配置 |
将so文件替换
cd /usr/lib64/nginx/modules/ |
替换nginx二进制文件,并启动nginx
#先备份二进制文件 |
部署exporter
tar -xf nginx-vts-exporter-0.10.3.linux-amd64.tar.gz |
测试插件
curl http://x.x.x.x:9145/metrics |
配置Prometheus job
- job_name: nginx-exporter |
prometheus-nginxlog-exporter
通过读取nginx日志文件,解析日志,生成监控指标,并提供http接口供Prometheus拉取。
安装
创建目录
mkdir -p /usr/local/nginxlog-exporter |
下载安装包
wget https://github.com/martin-helmich/prometheus-nginxlog-exporter/releases/download/v1.11.0/prometheus-nginxlog-exporter_1.11.0_linux_amd64.tar.gz |
安装服务
tar xf prometheus-nginxlog-exporter_1.11.0_linux_amd64.tar.gz |
创建配置文件/usr/local/nginxlog-exporter/nginxlog_exporter.yml
cat > /usr/local/nginxlog-exporter/nginxlog_exporter.yml << 'EOF' |
创建systemd服务
cat > /etc/systemd/system/prometheus-nginxlog-exporter.service << EOF |
启动服务
systemctl start prometheus-nginxlog-exporter |
测试
curl http://localhost:4040/metrics |
配置Prometheus job
- job_name: nginxlog-exporter |