zabbix nginx模板

zabbix服务端nginx的上传文件限制修改:client_max_body_size 5m;

nginx 客户端开启状态检测

nginx
server {
listen 80;
server_name localhost;

location /stub_status {
    stub_status on;
    access_log off;
    allow 127.0.0.1;
    deny all;
}

}

zabbix客户端配置脚本指令

cat /etc/zabbix/zabbix_agentd.d/userparameter_nginx.conf
UserParameter=nginx.status[*],/etc/zabbix/scripts/nginx.sh $1

nginx.sh脚本

mkdir -p /etc/zabbix/scripts
vim /etc/zabbix/scripts/nginx.sh


#!/bin/bash
##################################################
# AUTHOR: Neo 
# WEBSITE: http://www.netkiller.cn
# Description:zabbix 通过 status 模块监控 nginx
# Note:Zabbix 3.2
# DateTime: 2016-11-22
##################################################

HOST="localhost"
PORT="80"
stub_status=stub_status

function check() {
    if [ -f /sbin/pidof ]; then
       /sbin/pidof nginx | wc -w
    else
       ps ax | grep "nginx:" | grep -v grep | wc -l
    fi
}

function active() {
    /usr/bin/curl -s "http://$HOST:$PORT/${stub_status}/" 2>/dev/null| grep 'Active' | awk '{print $NF}'
}
function accepts() {
    /usr/bin/curl -s "http://$HOST:$PORT/${stub_status}/" 2>/dev/null| awk NR==3 | awk '{print $1}'
}
function handled() {
    /usr/bin/curl -s "http://$HOST:$PORT/${stub_status}/" 2>/dev/null| awk NR==3 | awk '{print $2}'
}
function requests() {
    /usr/bin/curl -s "http://$HOST:$PORT/${stub_status}/" 2>/dev/null| awk NR==3 | awk '{print $3}'
}
function reading() {
    /usr/bin/curl -s "http://$HOST:$PORT/${stub_status}/" 2>/dev/null| grep 'Reading' | awk '{print $2}'
}
function writing() {
    /usr/bin/curl -s "http://$HOST:$PORT/${stub_status}/" 2>/dev/null| grep 'Writing' | awk '{print $4}'
}
function waiting() {
    /usr/bin/curl -s "http://$HOST:$PORT/${stub_status}/" 2>/dev/null| grep 'Waiting' | awk '{print $6}'
}

case "$1" in
    check)
        check
        ;;
    active)
        active
        ;;
    accepts)
        accepts
        ;;
    handled)
        handled
        ;;
    requests)
        requests
        ;;
    reading)
        reading
        ;;
    writing)
        writing
        ;;
    waiting)
        waiting
        ;;

    *)
        echo $"Usage $0 {check|active|accepts|handled|requests|reading|writing|waiting}"
        exit        
esac

#zabbix客户端
chmod +x /srv/zabbix/libexec/nginx.sh

# /srv/zabbix/libexec/nginx.sh
Usage /srv/zabbix/libexec/nginx.sh {active|accepts|handled|requests|reading|writing|waiting}
# /srv/zabbix/libexec/nginx.sh accepts
82

# systemctl restart zabbix-agent.service

#zabbix页面导入模板

#nginx.xml


    3.2
    2016-11-29T07:05:44Z
    
        
            Netkiller
        
        
            Templates
        
    
    
        
    
    
        
            {Template App Nginx:nginx.status[check].last()}=0
            0
            
            nginx was down!
            0
            
            
            0
            4
            Nginx process count: 0
            0
            0
            
            
        
    
    
        
            nginx status connections
            900
            200
            0.0000
            100.0000
            1
            1
            0
            1
            0
            0.0000
            0.0000
            0
            0
            0
            0
            
                
                    0
                    0
                    00C800
                    0
                    2
                    0
                    
                        Template App Nginx
                        nginx.status[active]
                    
                
                
                    1
                    0
                    C80000
                    0
                    2
                    0
                    
                        Template App Nginx
                        nginx.status[reading]
                    
                
                
                    2
                    0
                    0000C8
                    0
                    2
                    0
                    
                        Template App Nginx
                        nginx.status[waiting]
                    
                
                
                    3
                    0
                    C800C8
                    0
                    2
                    0
                    
                        Template App Nginx
                        nginx.status[writing]
                    
                
            
        
        
            nginx status server
            900
            200
            0.0000
            100.0000
            1
            1
            0
            1
            0
            0.0000
            0.0000
            0
            0
            0
            0
            
                
                    0
                    0
                    00C800
                    0
                    2
                    0
                    
                        Template App Nginx
                        nginx.status[accepts]
                    
                
                
                    1
                    0
                    C80000
                    0
                    2
                    0
                    
                        Template App Nginx
                        nginx.status[handled]
                    
                
                
                    2
                    0
                    0000C8
                    0
                    2
                    0
                    
                        Template App Nginx
                        nginx.status[requests]
                    
                
            
        
    
    
        
            Service state
            
                
                    0
                    Down
                
                
                    1
                    Up
                
            
        
    

你可能感兴趣的:(zabbix nginx模板)