Zabbix monitoring Nginx (four)

Source: Internet
Author: User

Brief introduction:

How can I use Zabbix to monitor Nginx status?

1. Get Nginx State (HTTP Stub status)

[Email protected] ~]#/apps/product/nginx/sbin/nginx-vnginx version:nginx/1.8. 1  4.4. 7 20120313 4.4. 7-41.0--prefix=/apps/product/ Nginx--with-http_stub_status_module--with-http_realip_module--with-http_ssl_module--with-file-aio--with-pcre

#查看编译时有没有加入状态监控模块, if there is no need to load separately

2, Configuration nginx.conf

[Email protected] ~]# vim/apps/product/nginx/conf/nginx.conf    ~/nginx_status {stub_status on    ;    access_log off;     127.0. 0.1 ;     10.10. 100.147 ;    Deny all;     403 , it is possible that you have rejected the machine you have tested!

3, Nginx Monitoring Item explanation

 [[email protected] ~]# curl http://  127.0.0.1/nginx_status  Active connections: 1   server accepts handled requests  77671  77671  77666   Reading:  0  Writing: 1  waiting: 0  

# Active Connections: Number of active connections initiated on the backend
# Server accepts handled Requests:nginx processed 77,671 connections, successfully created 77,671 handshake (no number of failures), processed 77,666 requests in total
# Reading:nginx The number of Header messages read to the client
# Writing:nginx The number of Header messages returned to the client
# Waiting: When Keep-alive is turned on, this value equals active-(reading + writing), meaning that Nginx has finished processing and is waiting for the next request instruction to reside on the connection
# The number of waiting is normal in cases where access is very efficient and requests are processed quickly. If the number of reading + writing is large, it indicates that the concurrent traffic is very high and is in process

4, write a script to get the above key value

[Email protected] ~]# vim/script/nginx_status.sh#!/bin/Bash Case$1 inchActive) Curl-S http://127.0.0.1/nginx_status | awk '/active/{print $} ';;accepts) Curl-S http://127.0.0.1/nginx_status | awk ' nr==3 {print $} ';;handled) Curl-S http://127.0.0.1/nginx_status | awk ' nr==3 {print $} ';;requests) Curl-S http://127.0.0.1/nginx_status | awk ' nr==3 {print $} ';;reading) Curl-S http://127.0.0.1/nginx_status | awk '/reading/{print $} ';;writing) Curl-S http://127.0.0.1/nginx_status | awk '/writing/{print $4} ';;waiting) Curl-S http://127.0.0.1/nginx_status | awk '/waiting/{print $6} ';;*) echo"Usage: $ {active | accepts | handled | requests | reading | writing | waiting}" ;; Esac

The script uses curl in conjunction with awk to get the value of the key.
#-S silent mode, if the-s parameter is not added, the obtained result is incorrect.

5. Add a custom key configuration file

[Email protected] ~]# vim/etc/zabbix/zabbix_agentd.d/nginx_status.conf## nginx_statususerparameter= nginx.active,/script/nginx_status.sh activeuserparameter=nginx.accepts,/script/nginx_status.sh Acceptsuserparameter=nginx.handled,/script/nginx_status.sh handleduserparameter=nginx.requests,/ script/nginx_status.sh requestsuserparameter=nginx.reading,/script/nginx_status.sh Readinguserparameter=nginx.writing,/script/nginx_status.sh writinguserparameter=nginx.waiting,/ Script/nginx_status.sh Waiting

# can also be added directly to the end of/etc/zabbix/zabbix_agentd.conf

[Email protected] ~]# vim/etc/zabbix/zabbix_agentd.confinclude=/usr/local/zabbix/etc/zabbix_ AGENTD.CONF.D/*Confunsafeuserparameters=1 # allow custom Key

# Add the above configuration

5. Restart Zabbix_agentd

[Email protected] ~]#/etc/init.d/zabbix-agent restart

Note that all of the above is on the monitored side

6, Zabbix service side test can get Key

10.10. 100.24 -k nginx.active   110.10.  100.24 -k nginx.requests        78182

# you can get the value to key, which means there is no problem with the configuration.
# being monitored, remember to turn on port 10050.

Zabbix monitoring Nginx (four)

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.