zabbix监控nginx
1、开启nginx的stub_status状态统计(nginx需支持http_stub_status_module模块)
# 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;
}
2、下载源码
# git clone https://github.com/adubkov/zbx_nginx_template.git
3、复制监控脚本到指定目录
# cd zbx_nginx_template/
# cp -a zbx_nginx_stats.py /etc/zabbix/script/nginx/
4、修改脚本中zabbix-server的IP(注意这里有两处要修改)
# 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)
5、添加定时任务
# crontab -e
*/1 * * * * /etc/zabbix/script/nginx/zbx_nginx_stats.py
6、修改状态文件权限
# chown zabbix.zabbix /tmp/nginx_log_stat
7、在web上导入 zbx_nginx_templates.xml 模板