Nginx内置状态信息(http_stub_status)
Nginx提供了一个内置的状态信息监控页面,可用于监控Nginx的整体访问情况。这个内置功能由模块ngx_http_stub_status_module实现。如果在安装的过程中没有启用该模块,则无法使用其状态信息。本文主要描述这个状态页面的启用以及相关状态值描述。
一、环境信息
# more /etc/redhat-release
CentOS release 6.7 (Final)
# /u01/app/nginx/sbin/nginx -v
nginx version: nginx/1.8.1
查看是否启用了with-http_stub_status_module模块,如果没有重新编译一次,增加该模块即可
# /u01/app/nginx/sbin/nginx -V
nginx version: nginx/1.8.1
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/u01/app/nginx --sbin-path=/u01/app/nginx/sbin
--conf-path=/u01/app/nginx/conf/nginx.conf --error-log-path=/u01/log/nginx/error.log
--http-log-path=/u01/log/nginx/access.log --pid-path=/var/run/nginx.pid
--lock-path=/var/run/nginx.lock --http-client-body-temp-path=/tmp/client_temp
--http-proxy-temp-path=/tmp/proxy_temp --http-fastcgi-temp-path=/tmp/fastcgi_temp
--http-uwsgi-temp-path=/tmp/uwsgi_temp --http-scgi-temp-path=/tmp/scgi_temp
--user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module
--with-http_addition_module --with-http_sub_module --with-http_dav_module
--with-http_flv_module --with-http_mp4_module --with-http_gunzip_module
--with-http_gzip_static_module --with-http_random_index_module
--with-http_secure_link_module --with-http_stub_status_module
--with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio
--with-http_spdy_module --with-ipv6
--add-module=/usr/local/src/nginx_mod_h264_streaming-2.2.7
二、配置Nginx启用状态功能
下面我们添加一个单独的配置文件以启用该功能
# vim /u01/app/nginx/conf/conf.d/nginx_status.conf
server {
listen 10061;
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
}
## Author : Leshami
## Blog : http://blog.csdn.net/leshami
语法检查
# /u01/app/nginx/sbin/nginx -t
nginx: the configuration file /u01/app/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /u01/app/nginx/conf/nginx.conf test is successful
重载nginx
# /u01/app/nginx/sbin/nginx -s reload
三、状态信息描述
打开网站首页,多几次点击,然后在服务器端查看nginx状态信息 # curl http://127.0.0.1:10061/nginx_status Active connections: 19 server accepts handled requests 943 943 4651 Reading: 0 Writing: 1 Waiting: 18
当前的活动连接数为19个 共总接受了943个连接,处理的连接数为943,客户端请求总数为4651
提供以下状态信息:
Active connections 当前活动客户端连接的数量,包括Waiting连接。
accepts 接受的客户端连接总数。
handled 处理的连接总数。通常情况下该值等于accepts的值,除非达到某个资源限制(例如, worker_connections限制)。
requests 客户端请求的总数。
Reading nginx正在读取请求头的当前连接数。
Writing nginx将响应写回客户端的当前连接数。
Waiting 当前等待请求的空闲客户端连接数。
嵌入式变量
该ngx_http_stub_status_module模块支持以下嵌入式变量(1.3.14):
$connections_active 与Active connections值相同;
$connections_reading 与Reading值相同;
$connections_writing 与Writing值相同;
$connections_waiting 与Waiting值相同。
四、一些常用的Nginx日志命令
1.根据访问IP统计UV # awk ‘{print $1}’ /tmp/http-access.log.0919|sort | uniq -c |wc -l 355
2.统计访问URL统计PV # awk ‘{print $7}’ /tmp/http-access.log.0919|wc -l
3.查询访问最频繁的URL # awk ‘{print $7}’ /tmp/http-access.log.0919|sort | uniq -c |sort -n -k 1 -r|more
4.查询访问最频繁的IP # awk ‘{print $1}’ /tmp/http-access.log.0919|sort | uniq -c |sort -n -k 1 -r|more
5.根据时间段统计查看日志 # cat access.log| sed -n ‘/14/Mar/2015:21/,/14/Mar/2015:22/p’|more
五、模块详细描述参考链接
http://nginx.org/en/docs/http/ngx_http_stub_status_module.html
- 第四次工业革命
- 每周.NET前沿技术文章摘要(2017-06-07)
- 再谈Silverlight中的对象序列化/反序列化
- jQuery打造智能提示插件
- 每周.NET前沿技术文章摘要(2017-05-17)
- 每周.NET前沿技术文章摘要(2017-05-24)
- ruby学习笔记(10)-puts,p,print的区别
- Linux下的Mongodb部署应用梳理
- Ocelot API网关的实现剖析
- ruby学习笔记(9)-别名(alias)与方法取消(undef,remove_method)
- Pupet自动化管理环境部署记录
- ruby学习笔记(8)-"静态方法的4种写法"与"单例方法的2种写法"
- Puppet常识梳理
- linux下增加磁盘改变指定文件路径分区挂载点和迁移数据
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 图论——Tarjan 初步 DFS序+时间戳+欧拉序
- POJ 1330 Nearest Common Ancestors(裸LCA)
- 数学--数论--广义欧拉降幂(模板)
- 图论--LCA--在线RMQ ST
- 微信小程序-基于高德地图API实现天气组件(动态效果)
- PG13 B-tree索引去重
- egg中 controller 调用controller如何实现
- CF思维联系– CodeForces -CodeForces - 992C Nastya and a Wardrobe(欧拉降幂+快速幂)
- 数学--数论--欧拉降幂--P5091 欧拉定理
- 重学巩固你的Vuejs知识(上)
- js原生模态登录框
- 客户决策 | 我的代码没有else
- LeetCode 1595 Minimum Cost to Connect Two Groups of Points (动态规划)
- js DOM系统
- css的radial-gradient大详解