zabbix server:172.16.26.15
zabbix_agent: 172.16.178.21
vim zabbix_agentd.conf
SourceIP=172.16.178.21
Hostname=172.16.178.21
Server=172.16.26.15
ServerActive=172.16.26.15
EnableRemoteCommands=1
LogRemoteCommands=1
HostMetadataItem=system.uname
Timeout=30
AllowRoot=0
User=bestpay
Include=/tools/zabbix_agent/etc/zabbix_agentd.conf.d/*.conf
UnsafeUserParameters=1
UserParameter=nginx.status[*],/etc/zabbix/zabbix_agentd.d/ngx_status.sh $1
PidFile=/tools/zabbix_agent/zabbix_agentd.pid
LogFile=/data/dataLogs/zabbix_agent/zabbix_agentd.log
vim /etc/zabbix/zabbix_agentd.d/ngx_status.sh
#!/bin/bash
HOST="127.0.0.1"
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