Zabbix monitors Nginx status

Source: Internet
Author: User

Zabbix monitors Nginx status

Zabbix monitors the Nginx status. First, add the following code to the nginx configuration file:

Server
{
Listen localhost: 80;
Server_name localhost;
Location/nginxstatus {
Stub_status on;
Access_log off;
Allow 127.0.0.1;
Allow 192.168.1.165;
Deny all;
}
}
Restart nginx after saving

Create a script in the zabbix Script directory to monitor the zabbix status
#! /Bin/bash
# Script to fetch nginx statuses for tribily monitoring systems
# Author: [email protected]
# License: GPLv2


# Set Variables


# Functions to return nginx stats
Nginx =/usr/local/zabbix-2.4.4/scripts/nginx.txt
Function active {
Curl "http: // localhost/nginxstatus" & >$ nginx & awk '/Active/{print $3}' $ nginx
}


Function reading {
Curl "http: // localhost/nginxstatus" &> $ nginx & awk '/Reading/{print $2}' $ nginx
}

 


Function writing {
Curl "http: // localhost/nginxstatus" &> $ nginx & awk '/Writing/{print $4}' $ nginx
}


Function waiting {
Curl "http: // localhost/nginxstatus" &> $ nginx & awk '/Waiting/{print $6}' $ nginx
}


Function accepts {
Curl "http: // localhost/nginxstatus" &> $ nginx & awk NR = 6 $ nginx | awk '{print $1 }'
}


Function handled {
Curl "http: // localhost/nginxstatus" &> $ nginx & awk NR = 6 $ nginx | awk '{print $2 }'
}


Function requests {
Curl "http: // localhost/nginxstatus" &> $ nginx & awk NR = 6 $ nginx | awk '{print $3 }'
}


# Run the requested function
Case "$1" in
Active)
Active
;;
Reading)
Reading
;;
Writing)
Writing
;;
Waiting)
Waiting
;;
Accepts)
Accepts
;;
Handled)
Handled
;;
Requests)
Requests
;;
*)
Echo "Usage: $0 {nginx_site_dicovery }"
Echo "Usage: $0 {active [host] | reading [host] | writing [host] | waiting [host] | accepts [host] | handled [host] | requests [host]}"
Esac

Modify the owner and group of the file to zabbix and have the execution permission.
Chown zabbix. zabbix/usr/local/zabbix-2.4.4/scripts/nginx_status
Chmod 755/usr/local/zabbix-2.4.4/scripts/nginx_status
Create another nginx.txt file, set the group and owner to zabbix, and have read and write permissions.
Add the following code to the zabbix_agentd.conf configuration file:
# Monitor nginx
UserParameter = nginx. accepts,/usr/local/zabbix-2.4.4/scripts/nginx_status accepts
UserParameter = nginx. handled,/usr/local/zabbix-2.4.4/scripts/nginx_status handled
UserParameter = nginx. requests,/usr/local/zabbix-2.4.4/scripts/nginx_status requests
UserParameter = nginx. connections. active,/usr/local/zabbix-2.4.4/scripts/nginx_status active
UserParameter = nginx. connections. reading,/usr/local/zabbix-2.4.4/scripts/nginx_status reading
UserParameter = nginx. connections. writing,/usr/local/zabbix-2.4.4/scripts/nginx_status writing
UserParameter = nginx. connections. waiting,/usr/local/zabbix-2.4.4/scripts/nginx_status waiting
This code can be changed depending on your directory


After creation, you can configure item monitoring items on the web page.

Some Zabbix Tutorials:

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:

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.