nginx nginx-module-vts 监控模块

nginx nginx-module-vts 监控模块

大纲

  • nginx-module-vts 安装
  • nginx-module-vts 配置
  • 监控字段总结
  • 配置参数总结
  • vhost_traffic_status_filter_by_host 使用
  • vhost_traffic_status_filter_by_set_key 使用

nginx-module-vts 安装

nginx-module-vts 可以实现对nginx 各个虚拟主机,upstream等的请求 流量监控

官网地址:https://github.com/vozlt/nginx-module-vts

下载地址:https://github.com/vozlt/nginx-module-vts/tags

本次测试使用:

  • nginx 版本 openresty-1.17.8.2.tar.gz
  • nginx-module-vts 版本 v0.1.17 nginx-module-vts-0.1.17.tar.gz

使用 ./nginx -V 查看安装的模块

nginx nginx-module-vts 监控模块_第1张图片

安装nginx-module-vts

1 解压nginx-module-vts

tar -zxvf nginx-module-vts-0.1.17.tar.gz
#pwd 得到解压后的model文件位置
/ops/openresty/model/nginx-module-vts-0.1.17

2 解压openresty-1.17.8.2.tar.gz

tar -zxvf openresty-1.17.8.2.tar.gz
#使用--add-module 添加nginx-module-vts
./configure --prefix=/ops/openresty/nginx --add-module=/ops/openresty/model/nginx-module-vts-0.1.17

make && make install

安装完成后出现nginx-module-vts

nginx nginx-module-vts 监控模块_第2张图片

配置 nginx-module-vts

使用nginx-module-vts 最小配置需要在http块中加入vhost_traffic_status_zone;
并且配置一个server 来暴露监控的页面

以下为开启vts的最小配置

http {
   
   #开启vts模块
   vhost_traffic_status_zone;

   #配置一个虚拟主机暴露 /status 展示监控的数据
   server {
      listen       8080;
      server_name  localhost;

    location /status {
       vhost_traffic_status_display;
       vhost_traffic_status_display_format html;
    }

   }

}

配置完成后启动nginx 访问 IP:8080/status

nginx nginx-module-vts 监控模块_第3张图片

其他数据格式:

  • /status/format/json

访问 IP:8080/status/format/json 输出json字符串各式的监控数据

nginx nginx-module-vts 监控模块_第4张图片

  • /status/format/jsonp

访问 IP:8080/status/format/jsonp 输出json字符串各式的监控数据,注意包含jsonp所需 callback

nginx nginx-module-vts 监控模块_第5张图片

  • /status/format/html

访问 IP:8080/status 与 /status/format/html效果一样 输出html监控管理界面

  • /status/format/prometheus

访问 IP:8080/status/format/prometheus 输出prometheus监控需要的数据格式

nginx nginx-module-vts 监控模块_第6张图片

  • /status/control

监控字段总结

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:总数

配置参数总结

nginx-module-vts 配置参数:

1 vhost_traffic_status

vhost_traffic_status  默认值off
可配置在 http, server, location块中

作用:控制开启或关闭vts模块工作,如果配置了vhost_traffic_status_zone 则默认开启

2 vhost_traffic_status_zone

vhost_traffic_status_zone [shared:name:size] 默认为:shared:vhost_traffic_status:1m
可配置在 http 块中

作用:为共享内存区域设置参数,该共享内存区域将保留各种key的状态,配置此参数默认开启vts模块,
注意:如果使用vhost_traffic_status_filter_by_set_key配置,则需要配置大于32m内存

例如:

nginx nginx-module-vts 监控模块_第7张图片

在这里插入图片描述

3 vhost_traffic_status_dump

vhost_traffic_status_dump path [period] 默认没有此配置
可配置在 http 块中

作用:保存统计数据,默认period为60s
例如:vhost_traffic_status_dump /data/tmp/vts.db 32

4 vhost_traffic_status_display 和 vhost_traffic_status_display_format

vhost_traffic_status_display和vhost_traffic_status_display_format都可以可配置在 http, server, location块中
作用:
vhost_traffic_status_display 表示开启模块监控数据展示
vhost_traffic_status_display_format 配置数据格式可以是

nginx nginx-module-vts 监控模块_第8张图片

5 vhost_traffic_status_display_jsonp

vhost_traffic_status_display_jsonp 【callback的js方法名称】
可配置在 http, server, location块中

作用:修改使用jsonp展示数据的时候那个callback js方法的名称

例如:

nginx nginx-module-vts 监控模块_第9张图片
在这里插入图片描述

6 vhost_traffic_status_display_sum_key

vhost_traffic_status_display_sum_key 【sum key的名称】默认是*
可配置在 server块中

作用:
配置sum key的名称

例如默认是*

nginx nginx-module-vts 监控模块_第10张图片

添加配置

 server {
      listen       8080;
      server_name  localhost;
      #使用自定义字符串jim
      vhost_traffic_status_display_sum_key jim;

    location /status {
       vhost_traffic_status_display;
       vhost_traffic_status_display_format html;
    }
}

nginx nginx-module-vts 监控模块_第11张图片

7 vhost_traffic_status_filter

vhost_traffic_status_filter  默认值on
可配置在 http, server, location块中
	
作用:控制是否开启过滤功能

8 vhost_traffic_status_filter_by_host

vhost_traffic_status_filter_by_host  默认值off
可配置在 http, server, location块中
	
作用:控制是否使用请求中的 host字段作为key 进行展示

注意:是对通配符配置的虚拟主机进行分组过滤

例如server_name这样配置 使用*通配符

   server {
      listen       80;
      server_name  *.liuyijiang.com;

      location / {
            root   html;
            index  index.html index.htm;
        }

   }

nginx nginx-module-vts 监控模块_第12张图片

9 vhost_traffic_status_filter_by_set_key

vhost_traffic_status_filter_by_set_key 自定义key
可配置在 http, server, location块中

作用:配置自定义的key名称

例如

nginx nginx-module-vts 监控模块_第13张图片

效果

nginx nginx-module-vts 监控模块_第14张图片

你可能感兴趣的:(nginx解决方案,nginx,运维,服务器)