zabbix of monitoring Nginx connections

#; Download Nginx (compile time must add this option --with- http_stub_status_module) 
official website address: HTTP: // nginx.org/en/docs/http/ngx_http_stub_status_module.html 

root @ Ubuntu: / usr / local / src # wget HTTP: // nginx.org/download/nginx-1.16.1.tar.gz 
root @ Ubuntu: / usr / local / src # tar XF nginx- 1.16 . 1 . tar .gz 
root @ Ubuntu: / usr / local / src # cd nginx- 1.16 . 1 / 

#: compile and install Nginx 

root @ Ubuntu: / usr / local / src / nginx- 1.16 . 1 # ./configure --prefix = / Apps / nginx --with-http_stub_status_module 
root @ Ubuntu: / usr / local / src / nginx- 1.16 . 1 # the make && the make  install 

#: Nginx configuration status page 

root @ Ubuntu: / usr / local / src / nginx- 1.16 . 1 # vim / Apps / Nginx / the conf / nginx.conf 
LOCATION = / nginx_status { 
    stub_status; 
} 

#: start service 
the root @ Ubuntu: / usr / local / the src / nginx- 1.16 . . 1 # / Apps / Nginx / sbin / Nginx 

# configure connection monitoring the Nginx A script 

root @ Ubuntu: . / opt # vim nginx_status SH  
# ! / bin /the bash 

nginx_status_fun () {# function contents 
        NGINX_PORT = $ . 1 first parameter # port, the second parameter is a function of the script, the script that is the second parameter is the port number of segments 
        NGINX_COMMAND = $ 2 # command, the function of two third parameter is a parameter of the script, the script that is the third parameter is the command 
        nginx_active () {# Get the number nginx_active, hereinafter the same, which is opened, but only be seen from a state nginx native
         / usr / bin / curl " of http://127.0.0.1: " $ NGINX_PORT " / nginx_status "  2 > / dev / null | grep  ' the Active ' | awk  ' {} of NF Print $ ' 
        } 
        nginx_reading () {# nginx_reading state quantity acquisition
         / usr / bin / curl"http://127.0.0.1:"$NGINX_PORT"/nginx_status" 2>/dev/null| grep 'Reading' | awk '{print $2}'
       }
        nginx_writing(){
        /usr/bin/curl "http://127.0.0.1:"$NGINX_PORT"/nginx_status" 2>/dev/null| grep 'Writing' | awk '{print $4}'
       }
        nginx_waiting(){
        /usr/bin/curl "http://127.0.0.1:"$NGINX_PORT"/nginx_status" 2>/dev/null| grep 'Waiting' | awk '{print $6}'
       }
        nginx_accepts(){
        /usr/bin/curl "http://127.0.0.1:"$NGINX_PORT"/nginx_status" 2>/dev/null| awk NR==3 | awk '{print $1}'
       }
        nginx_handled(){
        /usr/bin/curl "http://127.0.0.1:"$NGINX_PORT"/nginx_status" 2>/dev/null| awk NR==3 | awk '{print $2}'
       }
        nginx_requests(){
        /usr/bin/curl "http://127.0.0.1:"$NGINX_PORT"/nginx_status" 2>/dev/null| awk NR==3 | awk '{print $3}'
       }
        case $NGINX_COMMAND in
                active)
                        nginx_active;
                        ;;
                reading)
                        nginx_reading;
                        ;;
                writing)
                        nginx_writing;
                        ;;
                waiting)
                        nginx_waiting;
                        ;;
                accepts)
                        nginx_accepts;
                        ;;
                handled)
                        nginx_handled;
                        ;;
                requests)
                        nginx_requests; 
                Esac 
} 

main () {# main function contents 
        Case $ . 1  in # branched structure, for determining a user's input operation responsive 
                nginx_status) # invoked when the input nginx_status nginx_status_fun, and transmits the second and third parameters 
                        $ nginx_status_fun 2 $ 3 ; 
                        ;;
                 * ) # print help other input
                         echo $ " Usage: $ 0} {nginx_status Key " 
        esac # branch endings 
} 

main $ 1 $ 2 $ 3 

#: test scripts

root @ ubuntu: / opt # 88 nginx_status the bash nginx_status.sh Active

#: script to move to the next agent profile directory
Ubuntu @ root: ~ # mv /opt/nginx_status.sh /etc/zabbix/zabbix_agentd.conf.d/



#: Custom Monitor Agent configuration file in

root @ Ubuntu: / opt # vim /etc/zabbix/zabbix_agentd.conf
UserParameter nginx.status = [*], / etc / zabbix / zabbix_agentd.conf.d / nginx_status.sh "$ 1" "$ 2" "$ 3"

#: restart the service
root @ ubuntu: / opt # systemctl restart zabbix-agent.service



Create a template

 

 

 

 

 

 

 

 After adding the hosts added monitoring items

 

After adding create graphics

 

 

 

Guess you like

Origin www.cnblogs.com/maxuebin/p/11568376.html