共计 2975 个字符,预计需要花费 8 分钟才能阅读完成。
Zabbix 监控 Nginx 状态,首先,在 nginx 的配置文件中添加如下一段代码
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;
}
}
保存之后重启 nginx
在 zabbix 脚本目录下创建脚本监控 zabbix 状态
#!/bin/bash
# Script to fetch nginx statuses for tribily monitoring systems
# Author: admin@linuxidc.com
# 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
然后修改该文件的属主和属组为 zabbix,并且具有执行权限
chown zabbix.zabbix /usr/local/zabbix-2.4.4/scripts/nginx_status
chmod 755 /usr/local/zabbix-2.4.4/scripts/nginx_status
再创建一个 nginx.txt 的文件,将属组和属主定为 zabbix,具有读写权限
然后在 zabbix_agentd.conf 配置文件中添加如下代码
#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
这段代码可以视自己目录情况而改变
创建好了之后就可以在 web 页面配置 item 监控项了
一些 Zabbix 相关教程集合:
安装部署分布式监控系统 Zabbix 2.06 http://www.linuxidc.com/Linux/2013-07/86942.htm
《安装部署分布式监控系统 Zabbix 2.06》http://www.linuxidc.com/Linux/2013-07/86942.htm
CentOS 6.3 下 Zabbix 安装部署 http://www.linuxidc.com/Linux/2013-05/83786.htm
Zabbix 分布式监控系统实践 http://www.linuxidc.com/Linux/2013-06/85758.htm
CentOS 6.3 下 Zabbix 监控 apache server-status http://www.linuxidc.com/Linux/2013-05/84740.htm
CentOS 6.3 下 Zabbix 监控 MySQL 数据库参数 http://www.linuxidc.com/Linux/2013-05/84800.htm
64 位 CentOS 6.2 下安装 Zabbix 2.0.6 http://www.linuxidc.com/Linux/2014-11/109541.htm
ZABBIX 的详细介绍:请点这里
ZABBIX 的下载地址:请点这里
本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-04/116303.htm