Zabbix監控nginx


編輯nginx.conf文件nginx


//在server內部添加一下內容web

location /nginx-status {bash

    stub_status on;curl

    access_log  off;    ide

}url


2.zabbix agentd客戶端配置rest


//編輯/usr/local/zabbix/etc/zabbix_agentd.confserver

//在文件末尾添加以下ip

UnsafeUserParameters=1requests

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

3.編輯nginx_status.sh文件


cat /usr/local/zabbix/scripts/nginx_status.sh

#!/bin/bash

HOST=127.0.0.1(若是在每個域名下就寫域名)

TERM=$1

 

# Functions to return nginx stats

function active {

        /usr/bin/curl "http://$HOST/nginx-status" 2>/dev/null | grep 'Active' | awk '{print $NF}'

}

function reading {

        /usr/bin/curl "http://$HOST/nginx-status" 2>/dev/null | grep 'Reading' | awk '{print $2}'

}

function writing {

        /usr/bin/curl "http://$HOST/nginx-status" 2>/dev/null | grep 'Writing' | awk '{print $4}'

}

function waiting {

        /usr/bin/curl "http://$HOST/nginx-status" 2>/dev/null | grep 'Waiting' | awk '{print $6}'

}

function accepts {

        /usr/bin/curl "http://$HOST/nginx-status" 2>/dev/null | awk NR==3 | awk '{print $1}'

}

function handled {

        /usr/bin/curl "http://$HOST/nginx-status" 2>/dev/null | awk NR==3 | awk '{print $2}'

}

function requests {

        /usr/bin/curl "http://$HOST/nginx-status" 2>/dev/null | awk NR==3 | awk '{print $3}'

}

$TERM


chmod  +x   /usr/local/zabbix/scripts/nginx_status.sh

4.重啓zabbix_agentd


service zabbix_agentd restart

5.zabbixweb控制端導入模板

6.zabbix監控的客戶端添加nginx模塊

相關文章
相關標籤/搜索