通过nginx的http_stub_status_module模块提供的状态信息来监控,所以在agent端需要配置nginx状态获取的脚本,和添加key信息等,然后在server端配置nginx的监控模板等。请根据自己情况调整,这里只做简单的参照。
主要是使用github这个项目的代码 zabbix-templates
agent端
系统是centos6.x, zabbix-agent是3.0版本, nginx1.9.x 官方版本
首先要检查nginx是否安装了 http_stub_status_module 模块,通过下面的命令可以看到编译参数。
nginx -v
如果没有这个模块,还需要重新编译nginx.
配置nginx
nginx 80端口的server配置增加如下的片段
location /nginx_status { stub_statuson; access_logoff; allow127.0.0.1; deny all; }
配置完成之后,redload nginx,然后用简单测试下
>> curl http://127.0.0.1/nginx_statusactive connections: 7server accepts handled requests 2707270712528reading: 0 writing: 1 waiting: 6?
zabbix-agent 配置
有3个步骤,首先是编写获取nginx信息脚本,接着配置中增加key信息,然后重启agent 服务。
编写nginx监控脚本,记住路径,后面配置需要用到。!!注意脚本权限问题,agent运行用户要能执行。
>># mkdir -p /usr/local/zabbix-agent/scripts>># cd /usr/local/zabbix-agent/scripts>># vim nginx-check.sh>># cat nginx-check.sh#!/bin/bash################################### zabbix monitoring script## nginx:# - anything available via nginx stub-status module#################################### contact:# vincent.viallet@gmail.com# zabbix requested parameterzbx_req_data=$1zbx_req_data_url=$2# nginx defaultsnginx_status_default_url=http://127.0.0.1/nginx_statuswget_bin=/usr/bin/wget## error handling:# - need to be displayable in zabbix (avoid not_supported)# - items need to be of type float (allow negative + float)#error_no_access_file=-0.9900error_no_access=-0.9901error_wr>-0.9902error_data=-0.9903# either can not connect / bad host / bad port# handle host and port if non-defaultif [ ! -z $zbx_req_data_url ]; then url=$zbx_req_data_urlelse url=$nginx_status_default_urlfi# save the nginx stats in a variable for future parsingnginx_stats=$($wget_bin -q $url -o - 2> /dev/null)# error during retrieveif [ $? -ne0 -o -z $nginx_stats ]; thenecho$error_dataexit1fi## extract data from nginx stats#case$zbx_req_datain active_connections) echo$nginx_stats | head -1 | cut -f3 -d' ';; accepted_connections) echo$nginx_stats | grep -ev '[a-za-z]' | cut -f2 -d' ';; handled_connections) echo$nginx_stats | grep -ev '[a-za-z]' | cut -f3 -d' ';; handled_requests) echo$nginx_stats | grep -ev '[a-za-z]' | cut -f4 -d' ';; reading) echo$nginx_stats | tail -1 | cut -f2 -d' ';; writing) echo$nginx_stats | tail -1 | cut -f4 -d' ';; waiting) echo$nginx_stats | tail -1 | cut -f6 -d' ';; *) echo$error_wrong_param; exit1;;esacexit0
agent的配置文件 /etc/zabbix/zabbix_agentd.conf 中定义了其他key的包含目录 include=/etc/zabbix/zabbix_agentd.d/, 如果没有这个配置请自己添加下。接着在 /etc/zabbix/zabbix_agentd.d/ 目录新建一个文件 nginx-params.conf, 内容如下userparameter=nginx[*],/usr/local/zabbix-agent/scripts/nginx-check.sh $1
重启agent>>> /etc/init.d/zabbix-agent restart
server 的web端
首先命令行测试下刚才agent好使不,确认好用之后在web端导入模板,之后就可以给对应主机添加监控喽。
>>> zabbix_get -s127.0.0.1-p10050-knginx[reading]0
登录zabbix3.0 的web界面,一次选择 configuration > templates , 在主界面的右上角有个 import 按钮,用来导入模板。
模板文件比较长留一个下载地址
导入之后就可以给主机添加监控啦。
').addclass('pre-numbering').hide(); $(this).addclass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadein(1700); }); }); 以上就介绍了[zabbix30 ]添加nginx监控,包括了zabbix,nginx方面的内容,希望对php教程有兴趣的朋友有所帮助。