1. 程式人生 > >zabbix監控nginx服務狀態

zabbix監控nginx服務狀態

nginx需要安裝--with-http_stub_status_module模組

$ nginx -V
nginx version: nginx/1.12.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
built with OpenSSL 1.0.2n 7 Dec 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-openssl=../openssl-1.0.2n --with-pcre=../pcre-8.41 --with-pcre-jit --with-ld-opt=-ljemalloc

nginx配置檔案配置

location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}

監控指令碼

#!bin/bash
NGINX_PORT=80
NGINX_COMMAND=$1
nginx_active(){
/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk '/Active/ {print $NF}'
}
nginx_reading(){
/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk '/Reading/ {print $2}'
}
nginx_writing(){
/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk '/Writing/ {print $4}'
}
nginx_waiting(){
/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk '/Waiting/ {print $6}'
}
nginx_accepts(){
/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk 'NR==3 {print $1}'
}
nginx_handled(){
/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk 'NR==3 {print $2}'
}
nginx_requests(){
/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk 'NR==3 {print $3}'
}
case $NGINX_COMMAND in
active)
nginx_active;
;;
reading)
nginx_reading;
;;
writing)
nginx_writing;
;;
waiting)
nginx_waiting;
;;
accepts)
nginx_accepts;
;;
handled)
nginx_handled;
;;
requests)
nginx_requests;
;;
*)
echo $"USAGE:$0 {active|reading|writing|waiting|accepts|handled|requests}"
esac

配置zabbix_agent引數

UserParameter=nginx_status[*],/bin/bash /usr/local/zabbix/sh/nginx_status.sh $1

zabbix——server測試自定義監控是否能獲取值

zabbix_get -s 120.78.133.113 -k nginx_status[accepts]
10

web介面配置監控模板

鍵值:nginx_status[accepts]

其他項克隆改參即可