Another way to Zabbix monitor Nginx performance __zabbix

Source: Internet
Author: User
Tags curl nginx server
Another way to Zabbix monitor Nginx performance

Nginx and PHP-FPM have built a status page that is useful for trying to understand the status of Nginx and monitoring nginx, and for subsequent Zabbix monitoring, we need to enable the Nginx status page first

1. Enable Nginx status configuration
Add location to the default host or the host you wish to access.

server {
    location/ngx_status 
    {
        stub_status on;
        Access_log off;
        Allow 127.0.0.1;
        Deny all;
    }

2. Heavy Duty Nginx

# nginx-t
# service Nginx Reload

3. Open Status Page

# Curl 127.0.0.1:8555/ngx_status
Active connections:2 
Server accepts handled requests
3091 3091 3254 
reading:0 writing:1 waiting:1

# curl 127.0.0.1:8555/ngx_status
Active connections:2 
Server Accepts handled requests
3092 3092 3255 reading:0 writing:1 waiting:1 

4. Nginx Status Detailed

Active connections– number of actively connected connections
The server accepts handled requests-has handled 11,989 connections, successfully created 11,989 handshakes, and handled 11,991 requests in a total
Reading-reads the number of connections to the client.
Number of writing-response data to client
waiting-Open keep-alive, this value equals active– (reading+writing), meaning that Nginx has finished processing the resident connection waiting for the next request instruction.

The above is the Nginx performance count, in addition to monitoring the above data, we also need to monitor nginx process status, and configure triggers
Zabbix Client Configuration

Writing client Script nginx_status.sh

# Detect Nginx Performance

Mkdir-p/usr/local/zabbix-agent/scripts
vim/usr/local/zabbix-agent/scripts/nginx_status.sh
Function active {
    /usr/bin/curl "http://$HOST: $PORT/ngx_status/" 2>/dev/null| grep ' active ' | awk ' {print $NF} ' c1/>}
function reading {
    /usr/bin/curl "http://$HOST: $PORT/ngx_status/" 2>/dev/null| grep ' reading ' | awk ' { Print $} '
}
function writing {
    /usr/bin/curl ' http://$HOST: $PORT/ngx_status/' 2>/dev/null| grep ' Writing ' | awk ' {print $} '
}
function waiting {
    /usr/bin/curl "http://$HOST: $PORT/ngx_status/" 2>/dev/null| grep ' Waiting ' | awk ' {print $} '
}
function accepts {
    /usr/bin/curl "http://$HOST: $PORT/ngx_status/" 2>/dev/null| awk nr==3 | awk ' {print '} '
}
function handled {
    /usr/bin/curl "http://$HOST: $PORT/ngx_status/" 2>/dev/null| awk nr==3 | awk ' {print $} '
}
function requests {
    /usr/bin/curl "http://$HOST: $PORT/ngx_status/" 2>/dev/null| awk nr==3 | awk ' {print $} '
}
# Execute function
$

Add Script Execution permissions

# chmod +x/usr/local/zabbix-agent/scripts/nginx_status.sh

Zabbix Client Configuration
Add the custom Userparameter to the configuration file, and then restart Agentd, as follows:

# vim/etc/zabbix/zabbix_agentd.conf

userparameter=nginx.status[*],/usr/local/zabbix-agent/scripts/nginx_ Status.sh $

Restart Zabbix-agent
/etc/init.d/zabbix-agent restart

Zabbix_get Get Data

This step can be skipped, but it is best to test it, because we can check that the configuration is correct through this command

# zabbix_get-s ip-p 10050-k ' nginx.status[accepts ' 3101 # zabbix_get-s ip-p 10050-k
' nginx.status[ping] ' 
  1

Zabbix Web-side configuration

Import Template App nginx template

Link nginx Template
To the last stage, login Zabbix management, Link template to Nginx server:configuration->hosts-> Click Nginx Server-> Click Template->link New Templates input "Template App NGINX"->add-> Last click Update
Monitoring effect

Monitoring template: Zbx3_export_templates.xml

<?xml version= "1.0" encoding= "UTF-8"?> <zabbix_export> <version>3.0</version> <date>
        2017-07-17t09:37:18z</date> <groups> <group> <name>Templates</name> </group> </groups> <templates> <template> <template>temp Late Nginx status</template> <name>template nginx status</name> Gt;nginx monitoring Templates </description> <groups> <group> <name>
                templates</name> </group> </groups> <applications>
            <application> <name>nginx</name> </application> </applications> <items> <item> <name>nginx Status Server Accepts</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>nginx.status[a Ccepts]</key> <delay>60</delay> 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.