1、查看nginx安装HTTP Stub Status
如果”–with-http_stub_status_module”参数,表示没有安装,要手动添加:
1 2
| 在编译nginx 的时候要加上参数 –with-http_stub_status_module, 执行./configure && make就可以了,不用make install。不过,一般情况下都是安装了的。
|
2、nginx服务器添加配置
2.1添加配置文件nginx_status.conf
cat /usr/local/openresty/nginx/conf/conf.d/nginx_status.conf
1 2 3 4 5 6 7 8
| server { listen 80; server_name 127.0.0.1;
location /basic_status { stub_status; } }
|
2.2重新加载配置文件
2.3获取nginx监控状态
1 2 3 4 5 6
| curl http://127.0.0.1/basic_status ------------- Active connections: 1 server accepts handled requests 572 572 764 Reading: 0 Writing: 1 Waiting: 0
|
nginx监控参数详解
3、配置zabbix
创建存放脚本目录,(我的zabbix安装路径为 /usr/local/zabbix):
1 2
| mkdir /usr/local/zabbix/script cd /usr/local/zabbix/script
|
创建存放数据文件(可自行定义):
编辑脚本用于获取nginx监控状态参数:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| echo " #!/bin/bash
server_hostname=127.0.0.1 data_file=/usr/local/zabbix/script/.status.txt
status_data=\`curl -o \$data_file -s http://\$server_hostname/basic_status\`
function Active() { awk -F \"[: ]\" '/Active/{print \$4}' \$data_file }
function Reading() { awk -F \"[: ]\" '/Reading/ {print \$3}' \$data_file }
function Writing() { awk -F \"[: ]\" '/Writing/ {print \$6}' \$data_file }
function Waiting() { awk -F \"[: ]\" '/Waiting/ {print \$9}' \$data_file }
\$1" > /usr/local/zabbix/script/nginx_connection.sh
|
修改目录下所有文件的权限,否则脚本写入文件会有权限问题
1
| chown -R zabbix.zabbix /usr/local/zabbix/script
|
添加zabbix参数到agent配置文件
1 2 3 4
| echo \"UserParameter=nginx.Active,sh /usr/local/zabbix/script/nginx_connection.sh Active UserParameter=nginx.Writing,sh /usr/local/zabbix/script/nginx_connection.sh Writing UserParameter=nginx.Reading,sh /usr/local/zabbix/script/nginx_connection.sh Reading UserParameter=nginx.Waiting,sh /usr/local/zabbix/script/nginx_connection.sh Waiting\" >> /usr/local/zabbix/etc/zabbix_agentd.conf
|
重新启动agent客户端:
1
| /etc/init.d/zabbix_agentd restart
|
在server端测试是否能获取到参数:
1
| /usr/local/zabbix/bin/zabbix_get -s 10.1.130.47 -k nginx.Active
|