zabbix配置ngnix监控

  1. 启用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;
}
  1. 启动且访问nginx。
    http://127.0.0.1/ngx_status
Active connections: 3 
server accepts handled requests
 3 3 1 
Reading: 0 Writing: 1 Waiting: 2 
  1. 编写服务端获取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
  1. 测试使用
zabbix_get -s localhost -k 'nginx.status[ping]'
  1. 配置监控项
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容