nginx安装[192.68" target="_blank">168.47.104]
#1.编译安装
wget https://nginx.org/download/nginx-1.14.2.tar.gz
tar xvf nginx-1.14.2.tar.gz
cd nginx-1.14.2
./configure --prefix=/apps/nginx --with-http_stub_status_module
make && make install
#2.修改配置
vim /apps/nginx/conf/nginx.conf
location /nginx_status {
stub_status;
}
#3.启动
/apps/nginx/sbin/nginx
#4.访问
http://192.168.47.105/nginx_status
获取监控值
1.监控值脚本
host=${2:-'127.0.0.1'}
port=${3:-'80'}
page=${4:-'nginx_status'}
info=$(/usr/bin/curl --connect-timeout 5 -s http://${host}:${port}/${page} 2>/dev/null)
code=$(/usr/bin/curl --connect-timeout 5 -o /dev/null -s -w %{http_code} http://${host}:${port}/${page})
proc=$(/usr/bin/pgrep nginx | wc -l)
case "$1" in
status)
echo "$code$proc" | awk '{code=$1}{proc=$2}END{if(code == "200" && proc != 0){printf("%d\n",1)}else{printf("%d\n",0)}}'
;;
active)
echo "$info" | awk '/^Active/{var=$NF}END{if(var~/^[0-9]+$/){printf("%d\n",var)}else{printf("%d\n",0)}}'
;;
reading)
echo "$info" | awk '/Reading/ {print $2}'
;;
writing)
echo "$info" | awk '/Writing/ {print $4}'
;;
waiting)
echo "$info" | awk '/Waiting/ {print $6}'
;;
accepts)
echo "$info" | awk 'NR==3 {print $1}'
;;
handled)
echo "$info" | awk 'NR==3 {print $2}'
;;
requests)
echo "$info" | awk 'NR==3 {print $3}'
;;
restimes)
echo "$info" | awk 'BEGIN{OFMT="%.3f"} NR==3 {print $4/$3}'
;;
*)
echo "ZBX_NOTSUPPORTED"
;;
esac
发表评论