zabbix-3.4监控nginx-1.14.0状态
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zabbix-3.4监控nginx-1.14.0状态相关的知识,希望对你有一定的参考价值。
zabbix需要监控nginx,则nginx需要配置nginx_status
[[email protected] scripts]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.14.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module
如果没有添加此模块可以编译添加 http://blog.51cto.com/10158955/2141048
vi /usr/local/nginx/conf/nginx.conf
location /ngx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
allow 192.168.254.131; #(zabbix服务器的IP地址,一般是内网地址)
deny all;
}
检测--with-http_stub_status_module参数是否生效
编写客户端脚本 vi /etc/zabbix/scripts/nginx_status.sh
赋予执行权限chmod +x vi /etc/zabbix/scripts/nginx_status.sh 内容如下:
#!/bin/bash
HOST="192.168.254.131"
PORT="80"
检测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
将自定义的UserParameter加入zabbix_agentd.conf配置文件,然后重启agentd
vi /etc/zabbix/zabbix_agentd.conf
UserParameter=nginx.status[*],/bin/bash /etc/zabbix/scripts/nginx_status.sh $1
重启agentd
/etc/init.d/zabbix-agent restart
模板附件下载:zabbix_monitor_nginx_template_ttlsa_com
http://www.ttlsa.com/wp-content/uploads/2015/10/zabbix_monitor_nginx_template_ttlsa_com.zip
导入模板:配置、模板、导入模板
给该主机添加nginx的监控项:
完成,查看图形:
以上是关于zabbix-3.4监控nginx-1.14.0状态的主要内容,如果未能解决你的问题,请参考以下文章