聲明參考地址:http://www.ttlsa.com/zabbix/zabbix-monitor-nginx-performance/nginx
1.zabbix須要監控nginx,則nginx須要配置ngx_statusvim
(1) 編譯安裝時帶上--with-http_stub_status_module參數:bash
./configure --prefix=/usr/local/nginx-1.11.5 --with-http_ssl_module --with-http_stub_status_module --with-pcre服務器
(2)vim /usr/local/nginx-1.11.5/conf/nginx.conf 在server內添加如下內容:curl
location /ngx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
allow 192.168.0.150; #(zabbix服務器的IP地址,通常是內網地址)
deny all;
}性能
(3)檢測--with-http_stub_status_module參數是否生效url
2.編寫客戶端腳本 vim /usr/local/zabbix-3.2.1/scripts/ngx-status.sh 賦予執行權限chmod a+x /usr/local/zabbix-3.2.1/scripts/ngx-status.sh 內容以下:spa
#!/bin/bash3d
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
3.將自定義的UserParameter加入zabbix_agentd.conf配置文件,而後重啓agentd
vim /usr/local/zabbix-3.2.1/etc/zabbix_agentd.conf
UserParameter=nginx.status[*],/usr/local/zabbix-3.2.1/scripts/ngx-status.sh $1
重啓agentd
4.zabbix_get 獲取數據,檢測配置是否正確
/usr/local/zabbix-3.2.1/bin/zabbix_get -s 127.0.0.1 -k 'nginx.status[accept]'
/usr/local/zabbix-3.2.1/bin/zabbix_get -s 127.0.0.1 -k 'nginx.status[ping]'
6.導入模板:配置、模板、導入模板
7.給該主機添加nginx的監控項:orm
8.完成,查看圖形:
交流qq1071179133