博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Nginx内置状态信息(http_stub_status)
阅读量:6962 次
发布时间:2019-06-27

本文共 3096 字,大约阅读时间需要 10 分钟。

Nginx提供了一个内置的状态信息监控页面,可用于监控Nginx的整体访问情况。这个内置功能由模块ngx_http_stub_status_module实现。如果在安装的过程中没有启用该模块,则无法使用其状态信息。本文主要描述这个状态页面的启用以及相关状态值描述。

一、环境信息

# more /etc/redhat-releaseCentOS release 6.7 (Final)# /u01/app/nginx/sbin/nginx -vnginx version: nginx/1.8.1查看是否启用了with-http_stub_status_module模块,如果没有重新编译一次,增加该模块即可# /u01/app/nginx/sbin/nginx -Vnginx version: nginx/1.8.1built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC)built with OpenSSL 1.0.1e-fips 11 Feb 2013TLS SNI support enabledconfigure 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.confserver {    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 -tnginx: the configuration file /u01/app/nginx/conf/nginx.conf syntax is oknginx: configuration file /u01/app/nginx/conf/nginx.conf test is successful重载nginx# /u01/app/nginx/sbin/nginx -s reload

三、状态信息描述

打开网站首页,多几次点击,然后在服务器端查看nginx状态信息

# curl
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

五、模块详细描述参考链接

你可能感兴趣的文章
传入含中文的字符串 返回中文首字母
查看>>
thinkphp5 下 Linux 定时任务
查看>>
IOS 动画组
查看>>
数据库模型设计——关系的实现,主键的设计
查看>>
webistrano的安装方法和一些用法
查看>>
Memcache集群高可用方案
查看>>
mysql数据据存储引擎InnoDB和MyISAM的优势及区别
查看>>
PowerShell中iso8601格式日期和DateTime对象互转实例
查看>>
MySQL Cluster, Fabric, Cobar 三大集群特性对比
查看>>
SpringBoot(八):测试组件-junit
查看>>
Mysql命令
查看>>
使用chmod命令改变权限
查看>>
java程序使用cmd备份和恢复数据库
查看>>
item点击变色
查看>>
tomcat的配置及负载均衡
查看>>
android基本控件及表单(3)
查看>>
Sharepoint多站点通过apache进行多域名访问
查看>>
Windows Azure 安全控制-ACL
查看>>
linux vsftp配置大全—超完整版
查看>>
ActionBar的移除与显示
查看>>