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
安装nginx-vts-exporter之前,nginx必须安装第三方的nginx virtual host traffic status模块,提供对虚拟主机状态信息的访问,它包含当前状态,如服务器、upstreams、缓存,即进行模块加载操作!
1)安装nginx服务
#安装依赖软件
[root@localhost ~] yum -y install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
- 1
- 2
#二进制包安装nginx-module-vts
[root@localhost opt]# unzip nginx-module-vts-master.zip
[root@localhost opt]# cp -r nginx-module-vts-master /usr/local/nginx-module-vts
- 1
- 2
#解压并编译安装
[root@localhost opt] tar -zxvf nginx-1.9.6.tar.gz
[root@localhost opt] cd nginx-1.9.6
[root@localhost nginx-1.9.6] ./configure --prefix=/usr/local/nginx --add-module=/usr/local/nginx-module-vts/
[root@localhost nginx-1.9.6] make && make install
- 1
- 2
- 3
- 4
2)配置nginx
[root@localhost nginx-1.9.6]# vi /usr/local/nginx/conf/nginx.conf
vhost_traffic_status_zone;
- 1
server {
location /status {
root html;
index index.html index.htm
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
启动服务
[root@localhost nginx-1.9.6] /usr/local/nginx/sbin/nginx
- 1
ip::9913/
3)安装nginx-vts-exporter
[root@localhost opt] tar -zxvf nginx-vts-exporter-0.10.3.linux-amd64.tar.gz
[root@localhost opt] cp -r nginx-vts-exporter-0.10.3.linux-amd64 /usr/local/nginx-vts-exporter
- 1
- 2
4)开启nginx-vts-exporter服务
[root@localhost opt] cd /usr/local/nginx-vts-exporter/
[root@localhost nginx-vts-exporter] ./nginx-vts-exporter -nginx.scrape_uri http://localhost/status/format/json
[root@localhost ~] netstat -tlunp | grep nginx-vts-exp
tcp6 0 0 :::9913 :::* LISTEN 19676/nginx-vts-exp
- 1
- 2
- 3
- 4
nginx-vts-exporter第三方模块显示的分析图
web查看 ip/status 其中status就是nginx.conf里的server中的【location /status】
5)添加redis_exporter为系统服务开机启动配置文件nginx-vts-exporter.service
[root@localhost ~] vi /usr/lib/systemd/system/nginx-vts-exporter.service
- 1
[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
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
[root@localhost ~] systemctl daemon-reload
[root@localhost ~] systemctl restart nginx-vts-exporter
- 1
- 2
6)与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
[root@localhost ~] systemctl restart prometheus
- 1
- 2
- 3
- 4
- 5
- 6
- 7
7)web测试
数学命令行:nginx_server_connections
accepts:接收到的客户端发来的连接数
Active connections:当前的活动连接数,包含处于等待状态的连接。
handled:已经处理完成的连接数,一般情况下它的accepts值相同,如果不同说明nginx性能出现瓶颈。
reading:正在读取请求头信息的连接数
requests:客户端请求总数
waiting:处于闲置状态正等待客户端发送请求的连接数
writing:正在发送相应报文的连接数