1. 程式人生 > >zabbix-2.4.8-1添加nginx狀態監控

zabbix-2.4.8-1添加nginx狀態監控

展示 tin 一個 active rpm waiting bash size clas

前期準備:nginx在編譯是必須要加如下參數:

技術分享

並且要在nginx的配置文件中添加如下配置:

server {
    listen  *:80 default_server;
    server_name localhost;
    location /nginx_status 
    {
        stub_status on;
        access_log off;
        allow 127.0.0.1;
        deny all;
    }
}

1、安裝zabbix-agent
yum -y install zabbix-2.4.8-1.el6.x86_64.rpm zabbix-agent-2.4.8-1.el6.x86_64.rpm


2、編輯agent端的/etc/zabbix/zabbix_agentd.conf文件修改如下內容:
Server=127.0.0.1
換成:(紅色字體是你自己的Server端的ip)
Server=Zabbix-Server-IP
3、將nginx_status.sh文件放入/etc/zabbix/zabbix_agentd.d/目錄下
nginx_status.sh內容如下:

#!/bin/bash
# Author: fansik
# Description: Statistics the number of nginx state connections
# Date: Wed Sep 13 10:51:28 CST 2017
nginx_status_fun(){ ServerName="127.0.0.1" nginx_active(){ /usr/bin/curl "http://"$ServerName"/nginx_status/" 2> /dev/null | grep "Active" | awk {print $NF} } nginx_reading(){ /usr/bin/curl "http://"$ServerName"/nginx_status/" 2> /dev/null | grep "Reading" | awk {print $2} } nginx_writing(){
/usr/bin/curl "http://"$ServerName"/nginx_status/" 2> /dev/null | grep "Writing" | awk {print $4} } nginx_waiting(){ /usr/bin/curl "http://"$ServerName"/nginx_status/" 2> /dev/null | grep "Waiting" | awk {print $6} } nginx_accepts(){ /usr/bin/curl "http://"$ServerName"/nginx_status/" 2> /dev/null | awk NR==3{print $1} } nginx_handled(){ /usr/bin/curl "http://"$ServerName"/nginx_status/" 2> /dev/null | awk NR==3{print $2} } nginx_requests(){ /usr/bin/curl "http://"$ServerName"/nginx_status/" 2> /dev/null | awk NR==3{print $3} } case $1 in active) nginx_active; ;; reading) nginx_reading; ;; writing) nginx_writing; ;; waiting) nginx_waiting; ;; accepts) nginx_accepts; ;; handled) nginx_handled; ;; requests) nginx_requests; ;; esac } nginx_status_fun $1

4、將status.conf文件放入/etc/zabbix/zabbix_agentd.d/目錄下
status.conf內容如下:

UserParameter=nginx_status[*],/etc/zabbix/zabbix_agentd.d/nginx_status.sh "$1"

5、賦予nginx_status.sh文件的執行權限:
chmod +x /etc/zabbix/zabbix_agentd.d/nginx_status.sh

6、啟動zabbix-agentd服務
/etc/init.d/zabbix-agent start

7、添加nginx的監控模板
添加nginx_status監控的模板

技術分享

8、添加Application

技術分享

9、添加item(其余六個分別是nginx_status.sh中case的內容)

技術分享

10、將起個狀態放到一個graph中

技術分享

11、結果展示

技術分享

zabbix-2.4.8-1添加nginx狀態監控