最新消息:

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

http admin 5497浏览 0评论

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

nginx流量带宽等请求状态统计( ngx_req_status)

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

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

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

ngx_http_status_code_counter

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响应码放入监控系统中,便于排除系统故障。后续再贴出整合到监控系统的案例,请继续关注运维生存时间。

 

转载请注明:爱开源 » nginx统计响应的http状态码信息(ngx-http-status-code-counter)

您必须 登录 才能发表评论!