Zabbix monitors Nginx status
Introduction:
How can I use Zabbix to monitor Nginx status?
1. Obtain the Nginx Status (HTTP Stub Status)
shell > /usr/local/nginx/sbin/nginx -Vnginx version: nginx/1.8.0built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module
# Check whether the status monitoring module is added during compilation. If not, load it separately.
2. Configure nginx. conf
shell > vim /usr/local/nginx/conf/nginx.conf location ~ /nginx_status { stub_status on; access_log off; allow 127.0.0.1; allow 121.142.111.210; deny all; }
# Add the preceding configuration to the VM server {}. You can also define a dedicated Vm for monitoring.
# Deny all: deny all hosts except allow to access this URL. If 403 is encountered during implementation, you may have rejected the machine you tested!
3. Nginx metric description
shell > curl http://127.0.0.1/nginx_statusActive connections: 1server accepts handled requests1 1 1Reading: 0 Writing: 1 Waiting: 0
# Active connections: Number of Active connections initiated to the backend
# Server accepts handled requests: Nginx processes one connection in total, successfully creates one handshake (no failures), and processes one request in total
# Reading: Number of headers that Nginx reads to the client
# Writing: Number of headers that Nginx returns to the client
# Waiting: When keep-alive is enabled, this value is equal to active-(reading + writing). This indicates that Nginx has completed processing and is Waiting for the next request command to reside in the connection.
# It is normal that many Waiting requests are processed quickly when the access efficiency is high. If the number of reading + writing is large, it indicates that the concurrent access volume is large and is being processed.
4. Write a script to get the above key value
shell > vim /script/nginx_status.sh#!/bin/bashcase $1 in active) curl -s http://127.0.0.1/nginx_status | awk '/Active/ {print $3}' ;; accepts) curl -s http://127.0.0.1/nginx_status | awk 'NR==3 {print $1}' ;; handled) curl -s http://127.0.0.1/nginx_status | awk 'NR==3 {print $2}' ;; requests) curl -s http://127.0.0.1/nginx_status | awk 'NR==3 {print $3}' ;; reading) curl -s http://127.0.0.1/nginx_status | awk '/Reading/ {print $2}' ;; 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: $0 { active | accepts | handled | requests | reading | writing | waiting }" ;;esac
# The script uses curl and awk to obtain the key value.
#-S silent mode. If the-s parameter is not added, the obtained result is incorrect.
shell > chmod a+x /script/nginx_status.sh
5. Add a custom key configuration file
shell > vim /usr/local/zabbix/etc/zabbix_agentd.conf.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
# You can also directly add it to the end of/usr/local/zabbix/etc/zabbix_agentd.conf
Shell> vim/usr/local/zabbix/etc/zabbix_agentd.confInclude =/usr/local/zabbix/etc/zabbix_agentd.conf.d/*. confUnsafeUserParameters = 1 # Allow custom keys
# Add the preceding Configuration
5. Restart Zabbix_agentd.
shell > service zabbix_agentd restart
# Note: all the operations above are performed on the monitored end
6. Test the Zabbix server to obtain the Key.
shell > /usr/local/zabbix/bin/zabbix_get -s 123.57.79.52 -k nginx.active1
# The key value can be obtained, indicating that the configuration is correct.
# Remember to enable port 10050 on the monitored side
7. Monitoring Nginx status using Zabbix
# Create a template and add monitoring items on the web interface
> Create a template
# Click Configuration-> Templates-> Create template together
Template name: Template App Nginx Service
Groups In groups: Templates
Update
> Create an Application Group
# Now back to the Template page, click Applications-> Create application next to the Template App Nginx Service Template with me
Name: Nginx status
Update
> Create a Metric
# The current location is the application page in the Template App Nginx Service Template. Click Items-> Create item next to the newly created Nginx status with me
Name: nginx active # metric Name
Type: Zabbix agent # monitoring Type, default Passive Mode
Key: nginx. active # because it is a custom Key, you must write it on your own. If you use the built-in Key, click Select to Select it.
Type of information: Numeric (unsiqned) # store data in the database after Type conversion
Numeric (unsiqned): A 64-bit unsigned integer
Numeric (float): Floating Point Number Type
Character: string type data, up to 255B
Log: log file. The required Key is Log [].
Text: Text, no size limit
Data type: Decimal # the Data type is used to store the value obtained by the Key in Items, stored in different tables, such as history and history_str.
Boolean: replace the original value with 0 or 1 during data storage. TRUE is stored as 1, and FALSE is stored as 0. All values are case sensitive (TRUE for any non-zero values, 0 is FALSE)
Octal: Octal value format
Decimal: numeric format of the Decimal number
Hexadecimal: Hexadecimal value format
# Zabbix automatically converts data formats
Units: Leave null # unit symbol. Zabbix automatically processes the received data and converts the data to the format to be displayed.
Use M multiplier: do not check # if enabled, the received data will be multiplied by an integer or floating point number. This option is used for unit conversion. KB and MBps are converted to B and Bps.
Update interval (in sec): 30 ## interval for how long data is collected through Items, in seconds
Flexible intervals: # It is used to set different data collection intervals in different time periods. If it is set, this interval is used for this time period, and the rest are separated by the preceding parameters.
New flexible interval Interval (in sec): 50 Period 1-7, 00: 00-24:00 Add: # here to Add a New time Period
History storage period (in days): 90 # retention time of historical data
Trend storage period (in days): 365 # retention time of Trend data
Store value: As is # type of data storage
As is: no preprocessing
Delta (speed per second): displays the rate per second (for example, Nic traffic)
Delta (simple change): displays the difference between the current value and the previous value.
Show value: As is # no preprocessing (type when data is displayed, value ing: maps the received value to a State. If the original value is not changed, only the display result is changed, for example, ing 1 to Nginx service states)
New application: leave blank # create a New application group
Applications: Nginx status # select an existing application group
Populates host inventory field: None # assign this Item to an Asset Management Group
Description: leave it blank # Description of the Item
Enabled: Check # enable this Item
Add
# Define active | accepts | handled | requests | reading | writing | waiting respectively
8. Apply the template to the host
> If no host exists, click Configuration> Hosts> Create host.
Host name: 123.121.211.52 # IP address of the monitored end (enter the Hostname value in the zabbix_agentd.conf file of the monitored end)
Visible name: Shuma_1 # define an alias (name to be displayed)
Groups In groups: Shuma # add to a host Group
New group: leave empty # customize a host group
Agent interfaces: # Interface Protocol
IP address: 123.121.211.52 # IP address of the monitored end
DNS name: leave blank # name that can be resolved by the monitoring host
Connect to: IP # How to Select
Port: 10050 # Open this Port on the monitored side
Description: leave it blank # host Description
Monitored by proxy: no proxy # Do not use a proxy
Enabled: Check # enable monitoring (Monitored indicates that the host is available and has been monitored; Not Monitored indicates that the host is unavailable and Not monitored)
Add ## indicates that the host has been added (Click here and link the template together). Select Templates on the current page.
> The current location is the template tab on the host page. Click Select
On the New Page, select Template App Nginx Service and return again. Click Add to successfully link the Template.
Add ## the last time.
9. Check the labor results
> Click Configuration> Hosts.
# You will see the newly added host, which has an application and seven Items. You will see the linked template in the "Enabled" status.
> Click Monitoring-> Latest data.
Hosts: Select the created host. Note: it is in the group and click Filter.
# Have you seen 7 metric items and all of them have obtained data?
10. Add a Graph to the host
> Click Configuration> Hosts and click Graphs next to the created host to create a chart.
# I have changed my mind temporarily. It is better to directly create a template, so that you do not have to create a host for each host.
> Click Configuration-> Templates and click Graphs-> Create graph next to the created template.
Name: Nginx status # chart Name
Width: 900 # width
Height: 200 # height
Graph type: Normal # chart type
Normal
Stacked: Stacked Graph
Pie: pie Chart
Exploded: break down the pie chart
Show legend: Check # display chart description
Show working time: Check # non-"working time" in gray. It is not used for pie charts or break-down pie charts.
Show triggers: Check # the red line is used to display the trigger threshold. It cannot be used for pie charts or decomposition pie charts. Only some trigger functions are supported, such as min and max.
Percentile line (left): do not check # Use the Y axis on the left to display the percentage, which is only applicable to regular charts.
Percentile line (right): do not check # Use the Y axis on the right to display the percentage. This option is only applicable to regular charts.
Y axix MIN value: Calculated # automatically calculate the minimum value of Y axis
Y axis MAX value: Calculated # automatically calculate the maximum value of Y axis
Items # click Add to Add the previous seven Items to a graph
Name: data displayed by Item Name
Function: when more than one value exists for an Item, which data is displayed (all, min is the minimum value, avg is the average value, and max is the maximum value)
Draw style: Line # Applicable only to regular charts and stacked Area
Line: draw lines
Filled region: Fill Area
Bold line: Draw a thick line
Dot: Draw a Dot
Dashed line: dotted line
Y axis side: Left # distribute elements to the Left of Y axis
Colour: The color of each element
Add ## create Graph. If the Graph is created on the host, you can view the Graph in the Preview tab.
11. View Graph
# Since the template has been referenced before, this Graph is automatically available on the host
> Click Monitoring-> Graphs.
Some Zabbix Tutorials:
Compile and install Zabbix2.4.5 source code in Ubuntu 14.04
Install and deploy the distributed monitoring system Zabbix 2.06
Install and deploy the distributed monitoring system Zabbix 2.06
Install and deploy Zabbix in CentOS 6.3
Zabbix distributed monitoring system practice
Under CentOS 6.3, Zabbix monitors apache server-status
Monitoring MySQL database Parameters Using Zabbix in CentOS 6.3
Install Zabbix 2.0.6 in 64-bit CentOS 6.2
ZABBIX details: click here
ZABBIX: click here
This article permanently updates the link address: