zabbix监控——Nginx监控

环境说明

  • 已关闭防火墙、selinux;
  • 所用zabbix版本4.0.3(使用YUM安装);
  • 开启Nginx状态监测,开启配置详情请见Nginx状态监测
  • 所用IP地址及安装包如下表:
IP地址角色安装包
192.168.91.133serverzabbix-server-mysql、zabbix-web-mysql、zabbix-agent、zabbix-get
192.168.91.134agentzabbix-agent、nginx

配置

  • 编写脚本
[root@localhost scripts]# vim nginx_status.sh
#!/bin/bash

NGINX_PORT=80
NGINX_COMMON=$1

function Active_connection () {
curl -s http://127.0.0.1:$NGINX_PORT/status | awk '/Active/ {print NF}'
}
function server () {
curl -s http://127.0.0.1:$NGINX_PORT/status | awk 'NR==3 {print $1}'
}
function accepts () {
curl -s http://127.0.0.1:$NGINX_PORT/status | awk 'NR==3 {print $2}'
}
function handled_requests () {
curl -s http://127.0.0.1:$NGINX_PORT/status | awk 'NR==3 {print $3}'
}
function Reading () {
curl -s http://127.0.0.1:$NGINX_PORT/status | awk '/Reading/ {print $2}'
}
function Writing () {
curl -s http://127.0.0.1:$NGINX_PORT/status | awk '/Writing/ {print $4}'
}
function Waiting () {
curl -s http://127.0.0.1:$NGINX_PORT/status | awk '/Waiting/ {print $6}'
}

case $1 in
	Active_connection)
		Active_connection;
	;;
	server)
		server;
	;;
	accepts)
		acepts;
	;;
	handled_reqursts)
		handled_reqursts;
	;;
	Reading)
		Reading;
	;;
	Writing)
		Writing;
	;;
	Waiting)
		Waiting;
	;;
	*)
		echo "Usage:$0 {Active_connection|server|accepts|handles_reqursts|Reading|Writing|Waiting}"
esac
  • 给脚本赋予执行权限
[root@localhost scripts]# chmod +x nginx_status.sh
  • 在/etc/zabbix/zabbix.agent.d/目录下创建一个配置文件
[root@localhost scripts]# vim /etc/zabbix/zabbix_agentd.d/nginx_status.conf
UserParameter=nginx_status[*],/bin/bash /scripts/nginx_status.sh "$1"
  • 重启agent端zabbix-agent服务
[root@localhost scripts]# systemctl restart zabbix-agent
  • 在server端进行测试
[root@localhost init.d]# zabbix_get -s 192.168.91.134 -k "nginx_status[server]"
61
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值