美文网首页
zabbix配置ngnix监控

zabbix配置ngnix监控

作者: xiangxik | 来源:发表于2017-12-27 23:09 被阅读0次
    1. 启用nginx status
    // 下载nginx源码,再用以下命令编译安装
    # ./configure --with-http_stub_status_module
    # make && make install
    
    // 修改/usr/local/nginx/conf/nginx.conf,增加以下location
    location /ngx_status {
        stub_status on;
        access_log off;
    }
    
    1. 启动且访问nginx。
      http://127.0.0.1/ngx_status
    Active connections: 3 
    server accepts handled requests
     3 3 1 
    Reading: 0 Writing: 1 Waiting: 2 
    
    1. 编写服务端获取nginx信息的脚本文件ngx_status.sh
    #!/bin/bash
    
    HOST="192.168.2.207"
    PORT="81"
    
    # 检测nginx进程是否存在
    function ping {
        /sbin/pidof nginx | wc -l 
    }
    # 检测nginx性能
    function active {
        /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep 'Active' | awk '{print $NF}'
    }
    function reading {
        /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep 'Reading' | awk '{print $2}'
    }
    function writing {
        /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep 'Writing' | awk '{print $4}'
    }
    function waiting {
        /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep 'Waiting' | awk '{print $6}'
    }
    function accepts {
        /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| awk NR==3 | awk '{print $1}'
    }
    function handled {
        /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| awk NR==3 | awk '{print $2}'
    }
    function requests {
        /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| awk NR==3 | awk '{print $3}'
    }
    # 执行function
    $1
    
    1. 测试使用
    zabbix_get -s localhost -k 'nginx.status[ping]'
    
    1. 配置监控项

    相关文章

      网友评论

          本文标题:zabbix配置ngnix监控

          本文链接:https://www.haomeiwen.com/subject/ktgpgxtx.html