zabbix監控nginx

一、開啓nginx的stub_status狀態統計(nginx需支持http_stub_status_module模塊)nginx

# vim www.xxx.com.conf
upstream www-xxx-com {
    server 10.0.1.61:8081 weight=10 max_fails=3 fail_timeout=10;
    server 10.0.1.119:8081 weight=10 max_fails=3 fail_timeout=10;
}

server {
    listen 80;
    server_name www.xxx.com;

    location /nginx_status {
        stub_status on;
        access_log off;
    }

    location / {
        proxy_pass http://www-xxx-com;
        include proxy.conf;
        userid on;
        userid_name uid;
        userid_domain xxx.com;
        userid_path /;
        userid_expires 365d;
        add_header Access-Control-Allow-Origin *;
        break;
    }

    access_log /data/log/nginx/www.xxx.com.access.log main;
    error_log /data/log/nginx/www.xxx.com.error.log;
}

二、下載源碼git

# git clone https://github.com/adubkov/zbx_nginx_template.git

三、複製監控腳本到指定目錄github

# cd zbx_nginx_template/
# cp -a zbx_nginx_stats.py /etc/zabbix/script/nginx/

四、修改腳本中zabbix-server的IP(注意這裏有兩處要修改)web

# vim /etc/zabbix/script/nginx/zbx_nginx_stats.py
zabbix_host = '10.0.0.149'   # Zabbix server IP
zabbix_port = 10051          # Zabbix server port
hostname = '10.0.1.61'       # Name of monitored host, like it shows in zabbix web ui
time_delta = 1               # grep interval in minutes
stat_url = 'http://www.xxx.com/nginx_status'
nginx_log_file_path = '/data/log/nginx/www.xxx.com.access.log'
def send_to_zabbix(metrics, zabbix_host='10.0.0.149', zabbix_port=10051)

五、添加定時任務vim

# crontab -e
*/1 * * * * /etc/zabbix/script/nginx/zbx_nginx_stats.py

六、修改狀態文件權限dom

# chown zabbix.zabbix /tmp/nginx_log_stat

七、在web上導入 zbx_nginx_templates.xml 模板ui

相關文章
相關標籤/搜索