zabbix 监控 nginx性能
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zabbix 监控 nginx性能相关的知识,希望对你有一定的参考价值。
http://www.ttlsa.com/nginx/nginx-status-detail/
http://www.ttlsa.com/zabbix/zabbix-monitor-nginx-performance/
首先需要配置ngx_status
vim /etc/nginx/vhost/web.conf
server
{
listen 80;
server_name 192.168.80.62;
index index.php index.html index.htm default.html default.htm default.php;
root /usr/local/nginx/html;
location ~ .*\.(php|php5)?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
location ~ ^/(status|ping)$
{
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
}
location /ngx_status { #加上红色部分
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
access_log off;
}
重启nginx
测试如下ok
[[email protected] ~]# curl http://127.0.0.1/ngx_status
Active connections: 6
server accepts handled requests
8764 8764 38033
Reading: 0 Writing: 1 Waiting: 5
zabbix客户端配置
编写客户端脚本
vim /usr/local/zabbix/scripts/ngx-status.sh
#!/bin/bash
HOST="127.0.0.1"
PORT="80"
# 检测nginx进程是否存在
function ping {
/sbin/pidof nginx | wc -l
}
# 检测nginx性能
function active {
/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep ‘Active‘ | awk ‘{print $NF}‘
}
function reading {
/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep ‘Reading‘ | awk ‘{print $2}‘
}
function writing {
/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep ‘Writing‘ | awk ‘{print $4}‘
}
function waiting {
/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep ‘Waiting‘ | awk ‘{print $6}‘
}
function accepts {
/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| awk NR==3 | awk ‘{print $1}‘
}
function handled {
/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| awk NR==3 | awk ‘{print $2}‘
}
function requests {
/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| awk NR==3 | awk ‘{print $3}‘
}
# 执行function
$1
记得加执行权限
zabbi客户端配置
vim /usr/local/zabbix/etc/zabbix_agentd.conf
UserParameter=nginx.status[*],/usr/local/zabbix/scripts/ngx-status.sh $1
killall zabbix_agentd
/usr/local/zabbix/sbin/zabbix_agentd
测试zabbix_get 获取数据
/usr/local/zabbix/bin/zabbix_get -s 192.168.80.62 -k ‘nginx.status[accepts]‘
/usr/local/zabbix/bin/zabbix_get -s 192.168.80.62 -k ‘nginx.status[ping]‘
最后zabbix web配置 导入模板即可
模板附件下载:zabbix_monitor_nginx_template_ttlsa_com
本文出自 “秋水无痕” 博客,谢绝转载!
以上是关于zabbix 监控 nginx性能的主要内容,如果未能解决你的问题,请参考以下文章