Zabbix Monitoring Nginx Status

Source: Internet
Author: User

One, Zabbix client configuration

First modify the configuration of the Zabbix client, accustomed to copy the Zabbix configuration file to the self-built/etc/zabbix/directory, easy to manage:

[Email protected] ~]# sed-e '/^$/d;/^#/d '/etc/zabbix/zabbix_agentd.confpidfile=/tmp/zabbix_agentd.pidlogfile=/tmp /zabbix_agentd.logserver=192.168.199.79serveractive=127.0.0.1hostname=zabbix Client1Include=/etc/zabbix/zabbix_ agentd.conf.d/#启用一个专门保存配置文件的目录 to reduce the direct modification of zabbix_agentd.conf files. Unsafeuserparameters=1 #代表是否启用 "Unsafe user parameters", 0 is not enabled, 1 is enabled. If not enabled, it may cause Zabbix to not recognize certain parameters, such as the requests that will be used.

Restart Zabbix_agent after modification and create the /etc/zabbix/zabbix_agentd.conf.d/ directory.

Second, the configuration Nginx can view nginx status   

Zabbix monitoring Nginx State, is through the Nginx Stub_staus module to obtain the value of the parameter. So we need to add the--with-http_stub_status option when compiling nginx. If you do not know whether to add this option when compiling, you can use/usr/local/nginx/sbin/nginx-v to view it, as shown in:

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/84/7B/wKioL1eR0q6y7GOCAAAzfbhEoYY541.png "title=" 1.png " alt= "Wkiol1er0q6y7gocaaazfbheoyy541.png"/>

Modify the Nginx configuration file and add the Stub_status configuration in server{}:

 48         location /status {              #location匹配规则  49              stub_status on; 50              allow 127.0.0.1; 51              allow 192.168.199.79;    #zabbix服务端ip, you must allow  52             allow  192.168.199.80;    #zabbix客户端ip, can be allowed, easy to test  53              allow 192.168.199.186;   #本地windows的ip, can be allowed, easy to test  54              deny all; 55          }

Restart Nginx after modification.

Through the browser access to the 192.168.199.80/status, you can see the information about the Nginx status, such as:

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/84/7B/wKiom1eR077Ay28DAAAkoNJ8iYA541.png-wh_500x0-wm_3 -wmp_4-s_2163852393.png "title=" 1.png "alt=" Wkiom1er077ay28daaakonj8iya541.png-wh_50 "/>

If you do not see the effect, you should check whether Nginx allows the IP browser to view the Nginx state, or the path defined in Nginx is correct.

Third, write the script

By writing a script to get the values of the Nginx state parameters, the path of this script is not limited, the script content is as follows:

[[Email protected] ~]# cat /etc/zabbix/nginx_status.sh#!/bin/bash#author: zhen#date:  2016/7/15path=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/binhost= 192.168.199.80port=80function active {  /usr/bin/curl  $HOST: $PORT/status 2>/ dev/null | awk  ' nr==1{print $3} '   }function accept {  /usr/ bin/curl  $HOST: $PORT/status 2>/dev/null | awk  ' nr==3{print $1} '   } function handled {  /usr/bin/curl  $HOST: $PORT/status 2>/dev/null |  awk  ' nr==3{print $2} '   }function requests {  /usr/bin/curl  $HOST: $PORT/status 2>/dev/null | awk  ' nr==3{print $3} '   }function reading  {  /usr/bin/curl  $HOST: $PORT/status 2>/dev/null | awk  ' Nr==4{print  $2} '   }function writing {  /usr/bin/curl  $HOST: $PORT/status2>/dev/null | awk   ' nr==4{print $4} '   }function waiting {  /usr/bin/curl  $HOST: $ port/status 2>/dev/null | awk  ' nr==4{print $6} '   }$1       # "$" must not fall, otherwise Zabbix will not read the value.

Four, increase or decrease Zabbix configuration

Add the following configuration on the Zabbix client:

[Email protected] ~]# cat/etc/zabbix/zabbix_agentd.conf.d/nginx_status.confuserparameter=nginx.active,/etc/ zabbix/nginx_status.sh activeuserparameter=nginx.accept,/etc/zabbix/nginx_status.sh acceptUserParameter= Nginx.handled,/etc/zabbix/nginx_status.sh handleduserparameter=nginx.requests,/etc/zabbix/nginx_status.sh Requestsuserparameter=nginx.reading,/etc/zabbix/nginx_status.sh readinguserparameter=nginx.writing,/etc/zabbix/ nginx_status.sh writinguserparameter=nginx.waiting,/etc/zabbix/nginx_status.sh Waiting

Format of userparameter: Userparameter=key,shell command

After writing, you still need to restart the Zabbix client.

Switch to the Zabbix server, and test to get the key value to the client, as follows:

[Email protected] ~]#/usr/local/zabbix/bin/zabbix_get-k nginx.active-s 192.168.199.80-p 100501

-K: Specify KEY-S: Specify host Ip-p: Specify port, default port does not need to be specified

Test each key, no problem can be the next step. If you do not get a value or are not supported, the most likely cause is a permissions problem, you can change the required file owner to Zabbix, or execute the visudo command, add sudo permission for Zabbix user, let Zabbix can execute/etc/zabbix/nginx_ Status.sh. Then there is the check that key is entered correctly.

V. Add monitoring on the Zabbix Web page

1. Create Template:

For a large number of servers can be used for monitoring, you should create a special template, add the host when the template can be added directly, without needing to add item to the host.

Login to the Zabbix page, under "Configuration--templates" in the upper right corner click "Create Template", fill in "Template name", "group", you can also create a new group, click "Save" after completion Save, such as:

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/84/7B/wKioL1eR1VKD8iP_AADJFGq8bVo659.png-wh_500x0-wm_3 -wmp_4-s_2920695215.png "title=" 2.png "alt=" Wkiol1er1vkd8ip_aadjfgq8bvo659.png-wh_50 "/>

2. Create an app set

To add an app set "application" to this template, click on the application:

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M02/84/7B/wKiom1eR1ZOxKRHlAABiZNvLDfw532.png-wh_500x0-wm_3 -wmp_4-s_1175999162.png "title=" 3.png "alt=" Wkiom1er1zoxkrhlaabiznvldfw532.png-wh_50 "/>

In the upper right corner there is "Create application", click, fill in the following:

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/84/7B/wKiom1eR1eCjBf7dAAAYCkMRqlY146.png-wh_500x0-wm_3 -wmp_4-s_830443698.png "title=" 4.png "alt=" Wkiom1er1ecjbf7daaayckmrqly146.png-wh_50 "/>

You only need to define the name of the app set, save it.

3. Create Item

After saving, create item. Under "Configuration--template", locate the template you just created, "Nginx status" and click "Items", such as:

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M00/84/7B/wKiom1eR1qmRvvl7AABhmRbPeEw688.png-wh_500x0-wm_3 -wmp_4-s_50782182.png "title=" 5.png "alt=" Wkiom1er1qmrvvl7aabhmrbpeew688.png-wh_50 "/>

Click Create item in the upper-left corner, such as:

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/84/7B/wKiom1eR1uCibJnoAACZwsfnxOc426.png-wh_500x0-wm_3 -wmp_4-s_2064715587.png "title=" 6.png "alt=" Wkiom1er1ucibjnoaaczwsfnxoc426.png-wh_50 "/>

Fill in the name of the item, key does not select, fill in the key defined in the Zabbix client configuration file, set "Update Interval" (update interval), select "Application" (Application set), save. Follow these steps to create an item for the other key as well.

4. Create graph

After saving, create item. Under "Configuration--template" Find the template you just created "Nginx status", click "Graphs", such as:

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/84/7B/wKioL1eR1x7x9wHCAABhNLZeQ4c765.png "title=" 7.png " alt= "Wkiol1er1x7x9whcaabhnlzeq4c765.png"/>

Click Create Graph in the upper-right corner, such as:

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/84/7B/wKiom1eR11KjPjVxAAC1LogBV4I595.png-wh_500x0-wm_3 -wmp_4-s_1060046350.png "title=" 8.png "alt=" Wkiom1er11kjpjvxaac1logbv4i595.png-wh_50 "/>

Fill in the graph name, customize width, height, click "Add", select the item to add graph to, and click "Save" to save.

5, for the host link template

Under "Configuration--hosts", click on the hostname in the Name column, and in the "Templates

Select "Nginx Status" and click "Add" to "save".

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/84/7B/wKiom1eR15bAX8lOAACwFdxyHAA553.png-wh_500x0-wm_3 -wmp_4-s_2710805629.png "title=" 9.png "alt=" Wkiom1er15bax8loaacwfdxyhaa553.png-wh_50 "/>

6. View the added graphics

In "Monitoring--dashboard" under "favourate graphs" add graph, such as:

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/84/7B/wKioL1eR2ALD_r_yAADFu6UlcO8639.png-wh_500x0-wm_3 -wmp_4-s_1227201413.png "title=" 10.png "alt=" Wkiol1er2ald_r_yaadfu6ulco8639.png-wh_50 "/>

Select the Nginx status,select in the pop-up window to complete the addition. Then click on "Nginx status" to view the graphics.


This article is from the "Tranquility" blog, so be sure to keep this source http://zhen0522.blog.51cto.com/11834939/1828850

Zabbix Monitoring Nginx Status

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.