231232133 发表于 2016-11-15 08:37:51

zabbix监控nginx

前提条件:nginx需要加载--with-http_stub_status_module
/usr/local/webserver/nginx/sbin/nginx -V
nginx version: nginx/1.9.9
built by gcc 4.4.7 20120313 (Red Hat4.4.7-4) (GCC)
configure arguments:--prefix=/usr/local/webserver/nginx --with-http_stub_status_module--with-http_ssl_module --with-pcre=/opt/pcre-8.35
如果发现没有--with-http_stub_status_module 的监控模块就需要手动开启
./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module--with-http_ssl_module --with-pcre=/opt/pcre-8.35
make

一、编辑nginx配置文件
server
{
      listen 80;
      #index index.html;
      server_name 192.168.1.34 127.0.0.1;
      #root /data/www/static;

      location /nginx_status {
            stub_status on;
            access_log off;
            allow 127.0.0.1;
            allow 192.168.0.0/16;
            allow 10.195.1.100;
            deny all;
      }
}


测试:
curl http://127.0.0.1/nginx_status
Active connections: 1
server accepts handled requests
10054822 10054822 1313691
Reading: 0 Writing: 1 Waiting: 0



二、配置agent文件
修改

ll /usr/local/zabbix/etc/zabbix_agentd.conf

grep -v "#" zabbix_agentd.conf

Server=192.168.1.100
ServerActive=192.168.1.100
Hostname=192.168.1.34

#自定义脚本

UserParameter=nginx.status[*],/usr/local/zabbix/scripts/nginx_status.sh $1
加载脚本文件(见附件nginx_status.sh)


赋权限 chmod 755 nginx_status.sh(可能会导致图像无法显示)

测试:如果有输出说明脚本没问题了
./nginx_status.shhandled
10055263


重启agent服务
/usr/local/zabbix/sbin/zabbix_agentd


三,上传监控模板到zabbix web管理界面,导入模板


并添加到主机





四,页面打印信息



yohnnstar 发表于 2016-11-17 16:44:35

附件在哪呢
页: [1]
查看完整版本: zabbix监控nginx