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

1. 介绍
ngx-http-status-code-counter是一个用来记录nginx响应状态码的统计信息,做者将这个模块与munin结合来分析网站的http状态,咱们也能够将这个与nagios、zabbix或者其余监控系统想结合,有这个模块运维能够再也不使用脚本去分析日志了。html

2. 安装ios

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

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

# 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响应码,一切都是为了测试。
测试输出内容以下图github

  • ngx_http_status_code_counter

  • ngx_http_status_code_counterbash

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/

相关文章
相关标签/搜索