zabbix adds nginx monitoring

Zabbix comes with a lot of useful monitoring templates by default. Usually, you can use the default template for the running status of the host. Sometimes we need to customize some monitoring information according to the actual situation. This article records the configuration process of zabbix monitoring nginx service. After thinking about it, the whole configuration process is roughly as follows:

1. Determine the monitoring content
2. Write the monitoring script on the agent side
3. Configure the agentd.conf file and define the monitoring script key
4. The zabbix server uses the zabbix_get test to obtain data
5. Log in to the zabbix web configuration console;

1. Determine what to monitor

Think about what information nginx has to monitor. nginx has a built-in function of status status. You can see the operation of nginx through configuration. The content displayed by status includes the number of current connections, the number of active connections, the number of processed requests, etc. Wait, the configuration of the status status page is introduced in the article on enabling the status status page in nginx , so I won't say more here.

2. Write an agent-side monitoring script

The key values ​​of the status page information are obtained through the script, and the zabbix server can generate data images through these key values. The key value script for obtaining the status is as follows:

#! /bin/bash#date: 2018-05-04# Description:zabbix监控nginx性能以及进程状态# Note:此脚本需要配置在被监控端,否则ping检测将会得到不符合预期的结果HOST="gudaoyufu.com"PORT="80"# 检测nginx进程是否存在function ping {    /sbin/pidof nginx | wc -l}# 检测nginx性能function active {    /usr/bin/curl "http://$HOST:$PORT/status/" 2>/dev/null| grep 'Active' | awk '{print $NF}'}function reading {    /usr/bin/curl "http://$HOST:$PORT/status/" 2>/dev/null| grep 'Reading' | awk '{print $2}'}function writing {    /usr/bin/curl "http://$HOST:$PORT/status/" 2>/dev/null| grep 'Writing' | awk '{print $4}'}function waiting {    /usr/bin/curl "http://$HOST:$PORT/status/" 2>/dev/null| grep 'Waiting' | awk '{print $6}'}function accepts {    /usr/bin/curl "http://$HOST:$PORT/status/" 2>/dev/null| awk NR==3 | awk '{print $1}'}function handled {    /usr/bin/curl "http://$HOST:$PORT/status/" 2>/dev/null| awk NR==3 | awk '{print $2}'}function requests {    /usr/bin/curl "http://$HOST:$PORT/status/" 2>/dev/null| awk NR==3 | awk '{print $3}'}# 执行function$1
After writing the script, test it locally
[root@web ~]# sh /home/scripts/ngx_status.sh active2

3. Configure zabbixd.conf and define monitoring script key


UnsafeUserParameters=1To use script monitoring, you need to turn on in the zabbixd.conf file and
add key values ​​that define the following items in the script

UserParameter=nginx.status[*],/home/scripts/ngx_status.sh $1

After configuration, restart zabbix-agent

service zabbix-agent restart

4. The zabbix server uses the zabbix_get test to obtain data

[root@centos ~]# zabbix_get -s 45.76.195.97 -k nginx.status[active]3

After the server test is normal, you can configure monitoring on the web interface. Zabbix configuration is configured through the interface. To be proficient in configuring monitoring, you must understand the function of each component of zabbix and the relationship between each component, otherwise look at a bunch of menus Options can be overwhelming.
The configuration process of zabbix is ​​roughly as follows:

Create host group - "Add host -" Create monitoring template -" Create application set - "Create monitoring item -" Create image - "Create trigger -" Create event - "Create processing action -" Create user group and user - "Create Alarm mode

Since the host group and host have been created earlier, we start with the configuration template. We can configure the monitoring template to make all hosts with the same monitoring requirements call this monitoring template uniformly, so that we do not need to add monitoring items one by one. .
This article only does the steps of creating a monitoring template - "creating an application set - "creating a monitoring item - " creating an image, and monitoring the content of the alarm will be done later.

5. Log in to the zabbix web configuration console

Start page configuration below
Create a template


Define the template information. During the process of creating the template, you can add the template to the specified host group or host and

return to the template page. You can see that the created template has been generated. At this time, the created template is an empty template. Create application sets, monitoring items, etc., click the application set in the figure below to create it directly.

I understand that creating an application set is only to classify a part of the monitoring item templates in the entire template group. Different types of monitoring items can be created in a template group. Creating an application set is just a name, and it is created after entering the application set in the above figure. Application set Then you can create monitoring items in the application set, see the figure below

Create monitoring items

When creating monitoring items, you should pay attention to the naming method. You can see the name and meaning. The most important thing is the key value. The key value here should be consistent with the key value defined in the configuration file on the agent side.

In the monitoring script, a total of 7 monitoring items are defined, so the monitoring item page here needs to be created 7, repeat the above steps, and create the corresponding monitoring items in the script

After the monitoring item is created, the image can be created

Create an image

Creating an image Multiple items can be selected when selecting items for the image to display, so that multiple line graphs of data can be displayed in one image

After the image is created, you can see that the created monitoring template is already working, and you can see the created template information in the latest data

Enter the host to view, the created application set is already in the host's application set, because the template has been added to the host when the template was first created

Finally, look at the renderings

Seeing that the created image template has an image, and 4 monitoring items are defined when creating the image template, so there are 4 line graphs here.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325364194&siteId=291194637