目录
nginx中的vts模块是非常好用的一款监控模块,能让我们清晰的观测到服务器当下状态
首先我们准备好nginx和vts的安装包

然后对其进行解压
tar -zxvf nginx-1.22.0.tar.gz
unzip nginx-module-vts-master.zip
mv nginx-module-vts-master /usr/local
二、安装依赖的编译软件yum -y install gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel make

这里我是已经全部安装过了
useradd -M -s /sbin/nologin nginx
#创建用户是为了让nginx更灵活,赋予更多的权限
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --add-module=/opt/nginx-module-vts-master/

make && make install


这样就安装完成了
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/

nginx -V #查看nginx安装信息

这里vts模块也加载上了
nginx -t #测试一下

vim /usr/local/nginx/conf/nginx.conf #配置文件如下
- #user nobody;
- worker_processes 1;
-
- #error_log logs/error.log;
- #error_log logs/error.log notice;
- #error_log logs/error.log info;
-
- #pid logs/nginx.pid;
-
-
- events {
- worker_connections 1024;
- }
-
-
- http {
- include mime.types;
- default_type application/octet-stream;
- vhost_traffic_status_zone; #流量状态监控
- #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
- # '$status $body_bytes_sent "$http_referer" '
- # '"$http_user_agent" "$http_x_forwarded_for"';
-
- #access_log logs/access.log main;
- log_format main '{ "@timestamp": "$time_local", '
- '"@fields": { '
- '"uri":"$request_uri",'
- '"url":"$uri",'
- '"upstream_addr":"$upstream_addr",'
- '"remote_addr": "$remote_addr", '
- '"remote_user": "$remote_user", '
- '"body_bytes_sent": "$body_bytes_sent", '
- '"host":"$host",'
- '"server_addr":"$server_addr",'
- '"request_time": "$request_time", '
- '"request_time":"$request_time",'
- '"status":"$status",'
- '"request": "$request", '
- '"request_method": "$request_method", '
- '"size":$body_bytes_sent,'
- '"upstream_time":"$upstream_response_time"'
- '"http_referrer": "$http_referer", '
- '"body_bytes_sent":"$body_bytes_sent", '
- '"http_x_forwarded_for": "$http_x_forwarded_for", '
- '"http_user_agent": "$http_user_agent" } }';
- sendfile on;
- #tcp_nopush on;
-
- #keepalive_timeout 0;
- keepalive_timeout 65;
-
- #gzip on;
-
- server {
- listen 80;
- server_name localhost;
-
- #charset koi8-r;
-
- #access_log logs/host.access.log main;
-
- location / {
- root html;
- index index.html index.htm;
- }
- location /status {
- vhost_traffic_status_display;
- vhost_traffic_status_display_format html;
- }
- #error_page 404 /404.html;
-
- # redirect server error pages to the static page /50x.html
- #
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root html;
- }
-
- # proxy the PHP scripts to Apache listening on 127.0.0.1:80
- #
- #location ~ \.php$ {
- # proxy_pass http://127.0.0.1;
- #}
-
- # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
- #
- #location ~ \.php$ {
- # root html;
- # fastcgi_pass 127.0.0.1:9000;
- # fastcgi_index index.php;
- # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
- # include fastcgi_params;
- #}
-
- # deny access to .htaccess files, if Apache's document root
- # concurs with nginx's one
- #
- #location ~ /\.ht {
- # deny all;
- #}
- }
-
-
- # another virtual host using mix of IP-, name-, and port-based configuration
- #
- #server {
- # listen 8000;
- # listen somename:8080;
- # server_name somename alias another.alias;
-
- # location / {
- # root html;
- # index index.html index.htm;
- # }
- #}
-
-
- # HTTPS server
- #
- #server {
- # listen 443 ssl;
- # server_name localhost;
-
- # ssl_certificate cert.pem;
- # ssl_certificate_key cert.key;
-
- # ssl_session_cache shared:SSL:1m;
- # ssl_session_timeout 5m;
-
- # ssl_ciphers HIGH:!aNULL:!MD5;
- # ssl_prefer_server_ciphers on;
-
- # location / {
- # root html;
- # index index.html index.htm;
- # }
- #}
-
- }
nginx #开启服务
nginx reload #重新加载配置文件


这样模块就成功添加完毕了
- 监控列表各项信息
- Server main 主服务器
- **Host:**主机名
- **Version:**版本号
- **Uptime:**服务器运行时间
- Connections active:当前客户端的连接数 reading:读取客户端连接的总数 writing:写入客户端连接的总数
- Requsts accepted:接收客户端的连接总数 handled:已处理客户端的连接总数 Total:请求总数 Req/s:每秒请求的数量
- Shared memory:共享内存 name:配置中指定的共享内存名称 maxSize:配置中指定的共享内存的最大限制 usedSize:共享内存的当前大小 usedNode:共享内存中当前使用的节点数
- Server zones 服务器区域
- zone:当前区域
- Requests Total:请求总数 Req/s:每秒请求数 time:时间
- Responses:状态码数量 1xx、2xx、3xx、4xx、5xx:表示响应不同状态码数量 Total:响应状态码的总数
- Traffic表示流量 Sent:发送的流量 Rcvd:接收的流量 Sent/s:每秒发送的流量 Rcvd/s:每秒接收的流量
- Cache表示缓存 Miss:未命中的缓存数 Bypass:避开的缓存数 Expirde:过期的缓存数 Stale:生效的缓存数 Updating:缓存更新的次数 Revalidated:重新验证的缓存书 Hit:缓存命中数 Scarce:未达缓存要求的请求次数Total:总数