zabbix-3.4監控nginx-1.14.0狀態
阿新 • • 發佈:2018-07-13
pid alt cto col stub tar ip地址 $1 mage zabbix需要監控nginx,則nginx需要配置nginx_status
[root@nginx1 scripts]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.14.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module
如果沒有添加此模塊可以編譯添加 http://blog.51cto.com/10158955/2141048
vi /usr/local/nginx/conf/nginx.conf
location /ngx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
allow 192.168.254.131; #(zabbix服務器的IP地址,一般是內網地址)
deny all;
}
檢測--with-http_stub_status_module參數是否生效
編寫客戶端腳本 vi /etc/zabbix/scripts/nginx_status.sh
賦予執行權限chmod +x vi /etc/zabbix/scripts/nginx_status.sh 內容如下:
#!/bin/bash
HOST="192.168.254.131"
PORT="80" }
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}‘
}
[root@nginx1 scripts]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.14.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module
vi /usr/local/nginx/conf/nginx.conf
location /ngx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
allow 192.168.254.131; #(zabbix服務器的IP地址,一般是內網地址)
deny all;
}
檢測--with-http_stub_status_module參數是否生效
編寫客戶端腳本 vi /etc/zabbix/scripts/nginx_status.sh
賦予執行權限chmod +x vi /etc/zabbix/scripts/nginx_status.sh 內容如下:
HOST="192.168.254.131"
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
將自定義的UserParameter加入zabbix_agentd.conf配置文件,然後重啟agentd
vi /etc/zabbix/zabbix_agentd.conf
UserParameter=nginx.status[*],/bin/bash /etc/zabbix/scripts/nginx_status.sh $1
重啟agentd
/etc/init.d/zabbix-agent restart
模板附件下載:zabbix_monitor_nginx_template_ttlsa_com
http://www.ttlsa.com/wp-content/uploads/2015/10/zabbix_monitor_nginx_template_ttlsa_com.zip
導入模板:配置、模板、導入模板
給該主機添加nginx的監控項:
完成,查看圖形:
zabbix-3.4監控nginx-1.14.0狀態