title: Zabbix监控Tengine
tags: zabbix,nginx,tengine
author: Chinge Yang
date: 2016-12-29
Zabbix监控Tengine
@(学习)[nginx, zabbix, tengine]
Tengine是由淘宝网发起的Web服务器项目。它在Nginx的基础上,针对大访问量网站的需求,添加了很多高级功能和特性。Tengine的性能和稳定性已经在大型的网站如淘宝网,天猫商城等得到了很好的检验。现在作为一个开源项目,也越来越多的人使用它代替nginx。
1.添加Tengine配置
tengine配置文件添加如下server
server {
listen 80 ;
server_name 127.0.0.1 ;
location /nginx-status {
stub_status on;
allow 127.0.0.1;
deny all;
access_log off;
}
location /check-status {
check_status;
allow 127.0.0.1;
deny all;
access_log off;
}
}
重载Tengine后,本机查看结果:# curl 127.0.0.1/nginx-status
Active connections: 1
server accepts handled requests
1805146 1805146 1805167
Reading: 0 Writing: 1 Waiting: 0
以上为正常显示结果。
2.添加nginx监控源脚本
cat /usr/local/zabbix/shell/nginx_status.sh
#!/bin/bash
HOST="127.0.0.1"
PORT="80"
# Functions to return nginx stats
function active {
/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| grep 'Active' | awk '{print $NF}'
}
function reading {
/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| grep 'Reading' | awk '{print $2}'
}
function writing {
/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| grep 'Writing' | awk '{print $4}'
}
function waiting {
/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| grep 'Waiting' | awk '{print $6}'
}
function accepts {
/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| awk NR==3 | awk '{print $1}'
}
function handled {
/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| awk NR==3 | awk '{print $2}'
}
function requests {
/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| awk NR==3 | awk '{print $3}'
}
# Run the requested function
$1
3.编辑zabbix agentd配置文件
修改如下:vim /usr/local/zabbix/etc/zabbix_agentd.conf
添加zabbix自定义key,重启zabbix agentdvim /usr/local/zabbix/etc/zabbix_agentd.conf.d/nginx_status_key
#nginx_status_key
UserParameter=nginx.accepts,/usr/local/zabbix/shell/nginx_status.sh accepts
UserParameter=nginx.handled,/usr/local/zabbix/shell/nginx_status.sh handled
UserParameter=nginx.requests,/usr/local/zabbix/shell/nginx_status.sh requests
UserParameter=nginx.connections.active,/usr/local/zabbix/shell/nginx_status.sh active
UserParameter=nginx.connections.reading,/usr/local/zabbix/shell/nginx_status.sh reading
UserParameter=nginx.connections.writing,/usr/local/zabbix/shell/nginx_status.sh writing
UserParameter=nginx.connections.waiting,/usr/local/zabbix/shell/nginx_status.sh waiting
从zabbix server端获取监控数据,结果如下为正常:
4.导入zabbix监控Tengine模板
5.Zabbix主机链接模板
6.监控成功
总结
从上文看到,Zabbix添加自定义监控数据,需要做到:
Zabbix agentd添加自定义key;
自定义key调用的是获取监控数据源脚本等;
添加Zabbix主机数据源模板,主机链接模板。