用zabbix监控nginx_status状态
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用zabbix监控nginx_status状态相关的知识,希望对你有一定的参考价值。
思路:
1.在nginx上开启status状态
location /nginx_status {
stub_status on;
allow 127.0.0.1;
allow 本机IP;
allow zabbix_server IP;
deny all;
access_log off;
}
2.在被控端做监测status状态的脚本
[[email protected] etc]# cat /usr/local/zabbix_proxy/scripts/nginx_status
#!/bin/bash
# Script to fetch nginx statuses for tribily monitoring systems
# Author:[email protected]
# Set Variables
# HOST=`ifconfig eth0 | sed -n ‘/inet /{s/.*addr://;s/ .*//;p}‘`
HOST="hire.cepin.com"
# Functions to return nginx stats
# nginx=/usr/local/zabbix-2.4.4/scripts/nginx.txt
function active {
/usr/bin/curl "http://$HOST/nginx_status/" 2>/dev/null| grep ‘Active‘ | awk ‘{print $NF}‘
}
function reading {
/usr/bin/curl "http://$HOST/nginx_status/" 2>/dev/null| grep ‘Reading‘ | awk ‘{print $2}‘
}
function writing {
/usr/bin/curl "http://$HOST/nginx_status/" 2>/dev/null| grep ‘Writing‘ | awk ‘{print $4}‘
}
function waiting {
/usr/bin/curl "http://$HOST/nginx_status/" 2>/dev/null| grep ‘Waiting‘ | awk ‘{print $6}‘
}
function accepts {
/usr/bin/curl "http://$HOST/nginx_status/" 2>/dev/null| awk NR==3 | awk ‘{print $1}‘
}
function handled {
/usr/bin/curl "http://$HOST/nginx_status/" 2>/dev/null| awk NR==3 | awk ‘{print $2}‘
}
function requests {
/usr/bin/curl "http://$HOST/nginx_status/" 2>/dev/null| awk NR==3 | awk ‘{print $3}‘
}
$1
#END
给文件添加可执行权限
Chown -R zabbix.zabbix /usr/local/zabbix_proxy/scripts/nginx_status
Chmod 775 /usr/local/zabbix_proxy/scripts/nginx_status
3.在被控端的zabbix_agentd.conf上定义键值
[[email protected] etc]# tail -n 8 zabbix_agentd.conf
UserParameter=nginx.accepts,/usr/local/zabbix_proxy/scripts/nginx_status accepts
UserParameter=nginx.handled,/usr/local/zabbix_proxy/scripts/nginx_status handled
UserParameter=nginx.requests,/usr/local/zabbix_proxy/scripts/nginx_status requests
UserParameter=nginx.connections.active,/usr/local/zabbix_proxy/scripts/nginx_status active
UserParameter=nginx.connections.reading,/usr/local/zabbix_proxy/scripts/nginx_status reading
UserParameter=nginx.connections.writing,/usr/local/zabbix_proxy/scripts/nginx_status writing
UserParameter=nginx.connections.waiting,/usr/local/zabbix_proxy/scripts/nginx_status waiting
4.在控制端的web页面上添加监控项、图形等
模板->Template OS Linux->应用集->创建应用集->创建监控项->填上名称、键值(在zabbix_agentd.conf里定义的键值名称)、应用集->图形->创建图形->填上名称、项目
本文出自 “achao57865” 博客,请务必保留此出处http://achao57865.blog.51cto.com/8818586/1746223
以上是关于用zabbix监控nginx_status状态的主要内容,如果未能解决你的问题,请参考以下文章