欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

12)nginx实时记录请求状态信息( ngx_realtime_request_module)

关于

ngx_realtime_request是nginx用来统计虚拟主机流量的模块, 首先和大家说下这个模块是基于域名的,将会记录这个域名的请求量、发送字节、返回http状态码的数量,特性如下:

  • 基于域名记录
  • 记录请求数据量
  • 记录发送、响应流量
  • 记录返回各种http状态码统计数据

1.  安装

1 # cd /usr/local/src/
3 # tar -xzvf nginx-1.4.2.tar.gz
5 # unzip ngx_realtime_request.zip
6 # cd nginx-1.4.2/
7 # ./configure --prefix=/usr/local/nginx-1.4.2 --add-module=../ngx_realtime_request_module-master
8 # make
9 # make install

2.  指令(directives)

realtime_zonesize
语法: realtime_zonesize size
默认值: 4m
配置块: http
设置slab大小

realtime_request
语法: realtime_request [on/off]
默认值: none
配置块: location
开启统计

3.  配置实例

1 http {
2     realtime_zonesize  16m;
3  
4     server {
5         server_name www.ttlsa.com
6         location ~ /ttlsa-rt-status {
7             realtime_request on;
8         }
9     }
10 }

4. 测试

访问http://www.ttlsa.com几次,制造几个404和200等等

查看状态http://www.ttlsa.com/ttlsa-rt-status如下图

nginx

ngx_realtime_request

上图解释:

uptime:18 ->nginx运行了18秒
version:0.5 -> 当前插件版本
host:当前统计的域名,如果这台服务器有多个域名,会显示多行
request:请求量8个
recv:接收5294字节
send:发送2043字节
20x:响应了7次20x的状态码
30x:返回了0次30x
40x:返回了1次40xhttp状态码(我测试的404)
50x:返回了0次50x

5. 兼容性

如下版本已做测试
1.3.x (tested with 1.3.6 to 1.3.15).
1.4.2 运维时间用这个版本做了测试

6. 参考文章

项目地址:https://github.com/magicbear/ngx_realtime_request_module
参考文档:http://www.ttlsa.com/nginx/nginx-modules-ngx_realtime_request_module/

网站:运维生存时间 

版权说明

文章标题: nginx实时记录请求状态信息( ngx_realtime_request_module)
本文地址: http://www.ttlsa.com/nginx/nginx-modules-ngx_realtime_request_module/
除非注明,博客文章均为"运维生存时间"原创,转载请标明本文地址
交流群:①群39514058(满)、②群6690706(满)、③群168085569(新)
来自 http://www.ttlsa.com/nginx/nginx-modules-ngx_realtime_request_module/
普通分类: