热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

nginx统计响应的http状态码信息(ngxhttpstatuscodecounter)

为什么80%的码农都做不了架构师?1.介绍ngx-http-status-code-counter是一个用来记录nginx响应状态码的统计信息,作

为什么80%的码农都做不了架构师?>>>   hot3.png

1. 介绍 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响应码,一切都是为了测试。 测试输出内容如下图 [caption id="attachment_4114" align="alignnone" width="516"] ngx_http_status_code_counter ngx_http_status_code_counter[/caption] 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/


转:https://my.oschina.net/766/blog/211506



推荐阅读
author-avatar
渔民-梁-家的西米姐
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有