概述
Prometheus 监控 nginx 需要用到两个模块
- nginx-module-vts 主要用于收集 nginx 各项指标.能提供 json 数据
- nginx-vts-exporter 向 prometheus 提供可以识别的数据结构
安装 nginx-module-vts 模块
需要对 nginx 进行重新编译, 对于正在运行的 nginx 需要热启动, 谨慎操作.
下载 nginx-module-vts
模块文件
|
|
重新编译 nginx
- 查看之前编译的参数, 重新编译时必须复用之前的参数,否则会影响业务
|
|
|
|
注意: 涉及到nginx引用其它包的插件,如--with-openssl=/root/lnmp1.7/src/openssl-1.1.1g
, 必须保证/root/lnmp1.7/src/openssl-1.1.1g
目录存在, 否则自己需要重新下载一个.
-
找到 nginx 安装原始包
如果找不到的话,需要重新下载一个.
1
cd /usr/local/src/nginx-1.19.1
复制
nginx -V
打印的参数,需要添加一下--add-module=/usr/local/src/nginx-module-vts
也就是第一步时下载的nginx-module-vts
目录1
./configure --add-module=/usr/local/src/nginx-module-vts --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-stream --with-stream_ssl_module --with-openssl=/root/lnmp1.7/src/openssl-1.1.1g --with-openssl-opt=enable-weak-ssl-ciphers
进行编译
1 2
# 不使用 make install make
-
复盖之前的
nginx
命令1 2 3 4 5 6 7
# 先查找 nginx 位置 whereis nginx # 对 nginx 命令进行重命令, 否则无法 cp mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak # 然后将编译好的命令进行复制 cd /usr/local/src/nginx-1.19.1 cp objs/nginx /usr/local/nginx/sbin/
-
热启动
1 2 3 4
# 找到 nginx 当前的进程ID号 netstat -nplt |grep -v grep |grep nginx # 使用 -USR2 热启动 kill -USR2 2520
-
验证是否安装成功
1 2
# 查看命令configure arguments字段 --add-module=/usr/local/src/nginx-module-vts 是否存在? nginx -V
配置 server 信息
-
添加 vhost_traffic_status_zone; 标识
1 2 3 4 5 6
vim /usr/local/nginx/conf/nginx.conf http { ... vhost_traffic_status_zone; ... }
-
添加 nginx-vts.conf
1 2 3 4 5 6 7
server { listen 9013; location /status { vhost_traffic_status_display; vhost_traffic_status_display_format html; } }
-
重启 nginx
1
nginx -t && nginx -s reload
-
查看是否收集到数据.
http://localhost:9088/status
访问:
curl -I http://localhost:9088/status
安装 nginx-vts-exporter
下载软件
|
|
解压&安装
|
|
制作 systemctl
|
|
管理 nginx-exporter
|
|
查看 metrics
http://127.0.0.1:9913/metrics
添加到 prometheus 数据源
添加到 scrape_configs 节点上 job_name: ‘nginx_vts_exporter’, 没有则添加
|
|
-
使用 prometool 工具检查配置是否成功
1
./promtool check config prometheus.yml
1 2
Checking prometheus.yml SUCCESS: 0 rule files found
-
重启 prometheus
1 2
systemctl daemon-reload systemctl restart prometheus
-
查看 prometheus 是否添加成功
http://127.0.0.1:9090/targets
MySQL Over 图表安装
选择 2949 具体操作参数 mysqld_exporter