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

这里的技术是共享的

You are here

10)nginx统计响应的http状态码信息(ngx-http-status-code-counter)

1. 介绍

ngx-http-status-code-counter是一个用来记录nginx响应状态码的统计信息,作者将这个模块与munin结合来分析网站的http状态,我们也可以将这个与nagioszabbix或者其他监控系统想结合,有这个模块运维可以不再使用脚本去分析日志了。

2. 安装

nginx的安装方式不再多说,请参考运维生存时间早期的《nginx安装》,我这边使用nginx-1.4.2做的测试。作者仅在0.8.50版本上使用,模块比较简单,新版本一般都会兼容,不过大家使用之前最好做一个测试。

# cd /usr/local/src/  # wget https://github.com/kennon/ngx_http_status_code_counter/archive/master.zip  # unzip master  # cd nginx-1.4.2   # ./configure --prefix=/usr/local/nginx-1.4.2 --add-module=../ngx_http_status_code_counter-master  # make  # make install

3. 配置NGINX

# for http_code_status  location /ttlsa_http_code_status/  {          show_status_code_count on;  }    location /ttlsa_http_code_status500/  {          return 500;  }    location /ttlsa_http_code_status502/  {          return 502;  }

4. 测试

分别访问http://test.ttlsa.com/ttlsa_http_code_status502/http://test.ttlsa.com/ttlsa_http_code_status500来制造一个500和502的状态码,以及随意访问一个页面制造404响应码,一切都是为了测试。
测试输出内容如下图

nginx

ngx_http_status_code_counter

5. 缺点

缺点也很明显,所有的数据都保存在nginx内存中,一旦nginx reload或者重开,数据就为空。还有一个缺点便是它统计的数据是持续叠加的,没有时段区分,如果你想统计各个时段的http 响应代码,你需要定时重启nginx。

5. 兼容性
兼容0.8.x,但是0.7.x为测试。我当前的版本是1.4.2运行OK

6. 结束语
有这个功能,将nginx统计出来的http响应码放入监控系统中,便于排除系统故障。后续再贴出整合到监控系统的案例,请继续关注运维生存时间。

站点:运维生存时间 网址:http://www.ttlsa.com/nginx/nginx-modules-ngx-http-status-code-counter/

版权说明

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