Zabbix Monitoring Nginx Status

Source: Internet
Author: User

Monitor 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 $ ' $nginx

}


function reading {

Curl "Http://localhost/nginxstatus" &> $nginx && awk '/reading/{print $ ' $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 '} '

}


function handled {

Curl "Http://localhost/nginxstatus" &> $nginx && awk nr==6 $nginx | awk ' {print $} '

}


function requests {

Curl "Http://localhost/nginxstatus" &> $nginx && awk nr==6 $nginx | awk ' {print $} '

}


# Run The requested function

Case "$" in

Active

Active

;;

Reading

Reading

;;

Writing

Writing

;;

Waiting)

Waiting

;;

Accepts)

Accepts

;;

Handled

Handled

;;

Requests)

Requests

;;

*)

echo "Usage: $ {nginx_site_dicovery}"

echo "Usage: $ {Active [host] | Reading [Host] | Writing [Host] | Waiting [Host] | accepts [host] | handled [host] | Requests [host]} "

Esac


The owner and owner group of the file is then modified to be Zabbix and has execute permissions

Chown Zabbix.zabbix/usr/local/zabbix-2.4.4/scripts/nginx_status

chmod 755/usr/local/zabbix-2.4.4/scripts/nginx_status

Create a Nginx.txt file, set the genus and the owner as Zabbix, with read and write permissions

Then add the following code in 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 the situation of your own directory.


Once you've created it, you can configure the item monitoring item on the Web page.


This article is from the "Lemon" blog, be sure to keep this source http://xianglinhu.blog.51cto.com/5787032/1632850

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.