- 启用nginx status
// 下载nginx源码,再用以下命令编译安装
# ./configure --with-http_stub_status_module
# make && make install
// 修改/usr/local/nginx/conf/nginx.conf,增加以下location
location /ngx_status {
stub_status on;
access_log off;
}
- 启动且访问nginx。
http://127.0.0.1/ngx_status
Active connections: 3
server accepts handled requests
3 3 1
Reading: 0 Writing: 1 Waiting: 2
- 编写服务端获取nginx信息的脚本文件ngx_status.sh
#!/bin/bash
HOST="192.168.2.207"
PORT="81"
# 检测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
- 测试使用
zabbix_get -s localhost -k 'nginx.status[ping]'
- 配置监控项
网友评论