Prometheus监控Nginx
nginx-vts-exporter下载地址:https://github.com/hnlq715/nginx-vts-exporter/releases
Nginx下载地址:http://nginx.org/download/
nginx-module-vts下载地址:https://github.com/vozlt/nginx-module-vts
1、部署nginx
自行部署
2、在原有nginx上添加nginx-module-vts模块
下载并解压nginx wget http://nginx.org/download/nginx-1.20.1.tar.gz tar xf nginx-1.20.1.tar.gz mv nginx-1.20.1 /usr/local/nginx 安装依赖 yum -y install perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++ openssl-devel cmakepcre-develnanowget gcc gcc-c++ ncurses-devel per yum install gd gd-devel gperftools 编译和安装 nginx -V 把模块复制出来 ./configure --add-module=/usr/local/nginx-module-vts/ --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-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-compat --with-debug --with-file-aio --with-google_perftools_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_perl_module=dynamic --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_xslt_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads make && make install 替换原有nginx cp objs/nginx /usr/sbin/ 编写配置文件 http { vhost_traffic_status_zone;(添加) vhost_traffic_status_filter_by_host on; server{ location /status { root html; index index.html index.htm; vhost_traffic_status_display; vhost_traffic_status_display_format html; } } 重启nginx systemctl restart nginx
3、查看页面是否有数据
4、安装nginx-vts-exporter
解压移动 tar xf nginx-vts-exporter-0.10.3.linux-amd64.tar.gz mv nginx-vts-exporter-0.10.3.linux-amd64 /usr/local/nginx-vts-exporter 添加redis_exporter为系统服务开机启动配置文件nginx-vts-exporter.service [root@localhost ~]# vi /usr/lib/systemd/system/nginx-vts-exporter.service [Unit] Description=Prometheus Nginx VTS Exporter After=network.target User=nginx Group=nginx [Service] Type=simple Restart=always ExecStart=/usr/local/nginx-vts-exporter/nginx-vts-exporter \ -nginx.scrape_uri http://localhost/status/format/json [Install] WantedBy=multi-user.target [root@localhost ~]# systemctl daemon-reload [root@localhost ~]# systemctl restart nginx-vts-exporter 查看是否启动 netstat -tlnp | grep nginx-vts-exp
5、与prometheus集成
[root@localhost ~]# vi /usr/local/prometheus/prometheus.yml - job_name: 'nginx-vts-exporter' scrape_interval: 10s static_configs: - targets: ['192.168.1.20:9913'] #添加一个job 记得重启
6、web测试
数学命令行:nginx_server_connections
accepts:接收到的客户端发来的连接数
Active connections:当前的活动连接数,包含处于等待状态的连接。
handled:已经处理完成的连接数,一般情况下它的accepts值相同,如果不同说明nginx性能出现瓶颈。
reading:正在读取请求头信息的连接数
requests:客户端请求总数
waiting:处于闲置状态正等待客户端发送请求的连接数
writing:正在发送相应报文的连接数
7、配grafara模板2949
上面显示没有数据大多因为没有nginx没配置反正代理功能
仅是简单测试,有需求可以配上