zabbix-2.4.8-1添加nginx状态监控
Posted fansik
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zabbix-2.4.8-1添加nginx状态监控相关的知识,希望对你有一定的参考价值。
前期准备:nginx在编译是必须要加如下参数:
并且要在nginx的配置文件中添加如下配置:
server {
listen *:80 default_server;
server_name localhost;
location /nginx_status
{
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
}
1、安装zabbix-agent
yum -y install zabbix-2.4.8-1.el6.x86_64.rpm zabbix-agent-2.4.8-1.el6.x86_64.rpm
2、编辑agent端的/etc/zabbix/zabbix_agentd.conf文件修改如下内容:
Server=127.0.0.1
换成:(红色字体是你自己的Server端的ip)
Server=Zabbix-Server-IP
3、将nginx_status.sh文件放入/etc/zabbix/zabbix_agentd.d/目录下
nginx_status.sh内容如下:
#!/bin/bash
# Author: fansik
# Description: Statistics the number of nginx state connections
# Date: Wed Sep 13 10:51:28 CST 2017
nginx_status_fun(){
ServerName="127.0.0.1"
nginx_active(){
/usr/bin/curl "http://"$ServerName"/nginx_status/" 2> /dev/null | grep "Active" | awk \'{print $NF}\'
}
nginx_reading(){
/usr/bin/curl "http://"$ServerName"/nginx_status/" 2> /dev/null | grep "Reading" | awk \'{print $2}\'
}
nginx_writing(){
/usr/bin/curl "http://"$ServerName"/nginx_status/" 2> /dev/null | grep "Writing" | awk \'{print $4}\'
}
nginx_waiting(){
/usr/bin/curl "http://"$ServerName"/nginx_status/" 2> /dev/null | grep "Waiting" | awk \'{print $6}\'
}
nginx_accepts(){
/usr/bin/curl "http://"$ServerName"/nginx_status/" 2> /dev/null | awk \'NR==3{print $1}\'
}
nginx_handled(){
/usr/bin/curl "http://"$ServerName"/nginx_status/" 2> /dev/null | awk \'NR==3{print $2}\'
}
nginx_requests(){
/usr/bin/curl "http://"$ServerName"/nginx_status/" 2> /dev/null | awk \'NR==3{print $3}\'
}
case $1 in
active)
nginx_active;
;;
reading)
nginx_reading;
;;
writing)
nginx_writing;
;;
waiting)
nginx_waiting;
;;
accepts)
nginx_accepts;
;;
handled)
nginx_handled;
;;
requests)
nginx_requests;
;;
esac
}
nginx_status_fun $1
4、将status.conf文件放入/etc/zabbix/zabbix_agentd.d/目录下
status.conf内容如下:
UserParameter=nginx_status[*],/etc/zabbix/zabbix_agentd.d/nginx_status.sh "$1"
5、赋予nginx_status.sh文件的执行权限:
chmod +x /etc/zabbix/zabbix_agentd.d/nginx_status.sh
6、启动zabbix-agentd服务
/etc/init.d/zabbix-agent start
7、添加nginx的监控模板
添加nginx_status监控的模板
8、添加Application
9、添加item(其余六个分别是nginx_status.sh中case的内容)
10、将起个状态放到一个graph中
11、结果展示
以上是关于zabbix-2.4.8-1添加nginx状态监控的主要内容,如果未能解决你的问题,请参考以下文章