Zabbix monitoring Nginx

Source: Internet
Author: User

First, add the following to the agent-side nginx.conf:

# vim/usr/local/nginx/conf/nginx.conf

server {
Listen 80;
server_name localhost;

location/nginxstatus{
Stub_status on;
Access_log off;
Allow 127.0.0.1;
Allow 192.168.1.0/24;-----The IP address of the >zabbix server side
Deny all;
}

}

Then write a script that monitors the Nginx state.

# vim/usr/local/zabbix/scripts/nginx.status.sh

#!/bin/bash
Function Active {
Curl "Http://127.0.0.1/nginxstatus" 2>/dev/null|awk '/active/{print $} '
}
function reading {
Curl "Http://127.0.0.1/nginxstatus" 2>/dev/null|awk '/reading/{print $} '
}
function writing {
Curl "Http://127.0.0.1/nginxstatus" 2>/dev/null|awk '/writing/{print $4} '
}
function waiting {
Curl "Http://127.0.0.1/nginxstatus" 2>/dev/null|awk '/waiting/{print $6} '
}
function accepts {
Curl "Http://127.0.0.1/nginxstatus" 2>/dev/null|awk Nr==3|awk ' {print $} '
}
function handled {
Curl "Http://127.0.0.1/nginxstatus" 2>/dev/null|awk Nr==3|awk ' {print $} '

}

function requests {
Curl "Http://127.0.0.1/nginxstatus" 2>/dev/null|awk Nr==3|awk ' {print $} '

}

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

Modify Permissions

# chmod 755/usr/local/zabbix/scripts/mysql.status.sh

Test scripts

#/usr/local/zabbix/scripts/nginx.status.sh Active
1

Modify the configuration file for the Zabbix agent

# vim/usr/local/zabbix/etc/zabbix_agentd.conf

include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/---> Configuration file key path

Unsafeuserparameters=1---"allows special characters

Add nginx Key configuration file

# vim/usr/local/zabbix/etc/zabbix_agentd.conf.d/nginx.status.conf

Userparameter=nginx.accepts,/usr/local/zabbix/scripts/nginx.status.sh accepts
Userparameter=nginx.handled,/usr/local/zabbix/scripts/nginx.status.sh handled
userparameter=nginx.requests,/usr/local/zabbix/scripts/nginx.status.sh Requests
Userparameter=nginx.active,/usr/local/zabbix/scripts/nginx.status.sh Active
userparameter=nginx.reading,/usr/local/zabbix/scripts/nginx.status.sh Reading
userparameter=nginx.writing,/usr/local/zabbix/scripts/nginx.status.sh Writing
Userparameter=nginx.waiting,/usr/local/zabbix/scripts/nginx.status.sh Waiting

Then the agent-side test

#/usr/local/zabbix/sbin/zabbix_agentd-t Nginx.active
nginx.active [T|1]

Restart Agent Service

Service Zabbix_agentd Restart

Add Nginx template key to view in Zabbix

Zabbix monitoring Nginx

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.