1. 程式人生 > >Zabbix監控Nginx狀態信息

Zabbix監控Nginx狀態信息

spa scrip 客戶 init.d strong tar nss 請求 ips

首先要檢查Nginx是否安裝了 http_stub_status_module 模塊,通過下面的命令可以看到編譯參數。yum安裝的默認會帶有這個模塊。

[root@kafka60 ~]# /data/nginx/sbin/nginx -V
nginx version: nginx/1.10.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/data/nginx-1.10
.2 --user=www --group=www --with-http_stub_status_module --with-http_ssl_module

zabbix客戶端

配置nginx

1、啟用nginx status配置

Nginx 的server配置增加如下的片段

 ......
   server {
        listen       80;
        server_name  www.blog.com;
        location /nginx_status { 
            stub_status on; 
            access_log off; 
            allow 
10.0.0.60; deny all; } .....

[root@kafka60 share]# /data/nginx/sbin/nginx -t
nginx: the configuration file /data/nginx-1.10.2/conf/nginx.conf syntax is ok
nginx: configuration file /data/nginx-1.10.2/conf/nginx.conf test is successful
[root@kafka60 share]# /data/nginx/sbin/nginx -s reload

## 在虛擬主機 server {} 中加入上面配置,也可以單獨定義一個專門用於監控的虛擬主機。

## deny all , 拒絕除 allow 中的主機之外所有主機訪問此 URL ,實現過程中如果遇到 403 ,有可能是你把自己測試的機器拒絕了!

2、測試配置

[root@kafka60 share]# curl 10.0.0.60/nginx_status
Active connections: 1 
server accepts handled requests
 1 1 1 
Reading: 0 Writing: 1 Waiting: 0 

  ## Active connections: 對後端發起的活動連接數
## Server accepts handled requests: Nginx 總共處理了 1 個連接,成功創建了 1 次握手(沒有失敗次數),總共處理了 1 個請求
## Reading: Nginx 讀取到客戶端的 Header 信息數
## Writing: Nginx 返回給客戶端的 Header 信息數
## Waiting: 開啟 keep-alive 的情況下,這個值等於 active - ( reading + writing ), 意思是 Nginx 已經處理完成,正在等待下一次請求指令的駐留連接
## 在訪問效率很高,請求很快被處理完畢的情況下,Waiting 數比較多是正常的。如果 reading + writing 數較多,則說明並發訪問量很大,正在處理過程中

3、配置zabbix agentd配置文件

vim  /etc/zabbix/zabbix_agentd.conf
......
 UnsafeUserParameters=1
UserParameter=nginx.accepts,/usr/local/zabbix/scripts/nginx_status.sh accepts 
UserParameter=nginx.handled,/usr/local/zabbix/scripts/nginx_status.sh handled 
UserParameter=nginx.requests,/usr/local/zabbix/scripts/nginx_status.sh requests 
UserParameter=nginx.connections.active,/usr/local/zabbix/scripts/nginx_status.sh active 
UserParameter=nginx.connections.reading,/usr/local/zabbix/scripts/nginx_status.sh reading 
UserParameter=nginx.connections.writing,/usr/local/zabbix/scripts/nginx_status.sh writing 
UserParameter=nginx.connections.waiting,/usr/local/zabbix/scripts/nginx_status.sh waiting
.......

[root@iZms9dbzZ ~]# /etc/init.d/zabbix-agent restart
Shutting down Zabbix agent: [ OK ]
Starting Zabbix agent: [ OK ]

  

Zabbix監控Nginx狀態信息