檢查with-http_stub_status_module有沒有安裝
<a href="https://s3.51cto.com/wyfs02/M00/8C/DE/wKioL1h8cvvR8keIAABgUq9THi0586.png" target="_blank"></a>
nginx status 開啟方法:
在nginx配置檔案中:
<a href="https://s5.51cto.com/wyfs02/M02/8C/E2/wKiom1h8fHHQ6rr-AAD2Fds9cdE308.png" target="_blank"></a>
啟動nginx
用curl做測試
<a href="https://s4.51cto.com/wyfs02/M00/8C/E2/wKiom1h8fSnQRYPZAAAaJ697uFo635.png" target="_blank"></a>
狀态頁面各項資料的意義:
active connections – 目前 Nginx 正處理的活動連接配接數。
serveraccepts handled requests — 總共處理了 233851 個連接配接 , 成功建立 233851 次握手 (證明中間沒有失敗的 ), 總共處理了 687942 個請求 ( 平均每次握手處理了 2.94 個資料請求 )。
reading — nginx 讀取到用戶端的 Header 資訊數。
writing — nginx 傳回給用戶端的 Header 資訊數。
waiting — 開啟 keep-alive 的情況下,這個值等于 active – (reading + writing), 意思就是 Nginx 已經處理完正在等候下一次請求指令的駐留連接配接。
有3個步驟,首先是編寫擷取Nginx資訊腳本,接着配置中增加key資訊,然後重新開機agent 服務。
①編寫Nginx監控腳本,記住路徑,後面配置需要用到,注意腳本權限問題,agent運作使用者要能執行。
mkidr -p /usr/local/zabbix-agent/scripts/
cd /usr/local/zabbix-agent/scripts
vi nginx-check.sh
#!/bin/bash
##################################
# Zabbix monitoring script
#
# nginx:
# - anything available via nginx stub-status module
# Contact:
# Zabbix requested parameter
ZBX_REQ_DATA="$1"
ZBX_REQ_DATA_URL="$2"
# Nginx defaults
WGET_BIN="/usr/bin/wget"
# Error handling:
# - need to be displayable in Zabbix (avoid NOT_SUPPORTED)
# - items need to be of type "float" (allow negative + float)
ERROR_NO_ACCESS_FILE="-0.9900"
ERROR_NO_ACCESS="-0.9901"
ERROR_WRONG_PARAM="-0.9902"
ERROR_DATA="-0.9903" # either can not connect / bad host / bad port
# Handle host and port if non-default
if [ ! -z "$ZBX_REQ_DATA_URL" ]; then
URL="$ZBX_REQ_DATA_URL"
else
URL="$NGINX_STATUS_DEFAULT_URL"
fi
# save the nginx stats in a variable for future parsing
NGINX_STATS=$($WGET_BIN -q $URL -O - 2> /dev/null)
# error during retrieve
if [ $? -ne 0 -o -z "$NGINX_STATS" ]; then
echo $ERROR_DATA
exit 1
# Extract data from nginx stats
case $ZBX_REQ_DATA in
active_connections) echo "$NGINX_STATS" | head -1 | cut -f3 -d' ';;
accepted_connections) echo "$NGINX_STATS" | grep -Ev '[a-zA-Z]' | cut -f2 -d' ';;
handled_connections) echo "$NGINX_STATS" | grep -Ev '[a-zA-Z]' | cut -f3 -d' ';;
handled_requests) echo "$NGINX_STATS" | grep -Ev '[a-zA-Z]' | cut -f4 -d' ';;
reading) echo "$NGINX_STATS" | tail -1 | cut -f2 -d' ';;
writing) echo "$NGINX_STATS" | tail -1 | cut -f4 -d' ';;
waiting) echo "$NGINX_STATS" | tail -1 | cut -f6 -d' ';;
*) echo $ERROR_WRONG_PARAM; exit 1;;
esac
exit 0
~
agent的配置檔案 /etc/zabbix/zabbix_agentd.conf 中定義了其他key的包含目錄 Include=/etc/zabbix/zabbix_agentd.d/, 如果沒有這個配置請自己添加下。接着在 /etc/zabbix/zabbix_agentd.d/ 目錄建立一個檔案 nginx-params.conf, 内容如下
<a href="https://s1.51cto.com/wyfs02/M02/8C/E5/wKiom1h8z9WwLL6xAAAXOfk__Cc418.png" target="_blank"></a>
加入以下内容:
UserParameter=nginx[*],/usr/local/zabbix-agent/scripts/nginx-check.sh "$1"
<a href="https://s2.51cto.com/wyfs02/M00/8C/E5/wKiom1h80DWA0XIaAAA4IBYZf84597.png" target="_blank"></a>
/etc/init.d/zabbix-agent restart
<a href="https://s1.51cto.com/wyfs02/M02/8C/E5/wKiom1h80HaQnx4YAAApv5OCBgM505.png" target="_blank"></a>
<a href="https://s5.51cto.com/wyfs02/M02/8C/E1/wKioL1h80K2TKzzxAAG-B-dQB24054.png" target="_blank"></a>
在建立的主機--選擇該模闆。
<a href="https://s4.51cto.com/wyfs02/M00/8C/E1/wKioL1h80VLDGlP7AAErgBsPU3g887.png" target="_blank"></a>
本文轉自 15816815732 51CTO部落格,原文連結:http://blog.51cto.com/68686789/1892414