“Zabbix监控nginx”的版本间的差异

来自linux中国网wiki
跳到导航 跳到搜索
第71行: 第71行:
  
 
脚本  
 
脚本  
 +
mkdir -p /etc/zabbix/scripts/
 +
vi /etc/zabbix/scripts/nginx_status.sh
 +
 +
#!/bin/bash
 +
HOST="127.0.0.1"
 +
PORT="80"
 +
 +
function proc_num {
 +
    num=$(pgrep nginx |wc -l)
 +
}
 +
function active {
 +
    num=$(curl -s "http://$HOST:$PORT/nginx_stat" |grep 'Active' |awk '{print $NF}')
 +
}
 +
function reading {
 +
    num=$(curl -s "http://$HOST:$PORT/nginx_stat" |grep 'Reading' |awk '{print $2}')
 +
}
 +
function writing {
 +
    num=$(curl -s "http://$HOST:$PORT/nginx_stat" |grep 'Writing' |awk '{print $4}')
 +
}
 +
function waiting {
 +
    num=$(curl -s "http://$HOST:$PORT/nginx_stat" |grep 'Waiting' |awk '{print $6}')
 +
}
 +
function accepts {
 +
    num=$(curl -s "http://$HOST:$PORT/nginx_stat" |awk NR==3 |awk '{print $1}')
 +
}
 +
function handled {
 +
    num=$(curl -s "http://$HOST:$PORT/nginx_stat" |awk NR==3 |awk '{print $2}')
 +
}
 +
function requests {
 +
    num=$(curl -s "http://$HOST:$PORT/nginx_stat" |awk NR==3 |awk '{print $3}')
 +
}
 +
 +
$1
 +
echo ${num:-0}
 +
 +
  
 
chmod +x  /etc/zabbix/scripts/nginx_status.sh
 
chmod +x  /etc/zabbix/scripts/nginx_status.sh

2021年10月21日 (四) 08:35的版本

office

nginx -V 2>&1 | grep -o with-http_stub_status_module.

Example configuration of Nginx: 直接加在 nginx.conf 







location = /basic_status {
    stub_status;
    allow 127.0.0.1;
    allow ::1;
    deny all;
}


一般我放的位置  参数不一致 不过官方用过了 爽 可用 
    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        #evan
         location /nginx_stat {
           stub_status on;
           access_log off;
           allow 127.0.0.1;
           deny all;
        } 
        #evan




官方模板有 4个图 只有一个  Nginx: Connections by state

Nginx: Connections by state	900	200	正常	
	Nginx: Connections per second	900	200	正常	
	Nginx: Memory usage	900	200	正常	
	Nginx: Requests per second


还有报警的要改   可以用  666  

告警信息: Nginx: Failed to fetch stub status page (or no data for 30m)

告警项目:web.page.get["localhost","basic_status","80"]

最后添加官方模板  Template App Nginx by Zabbix agent

3rd_party

官方推荐

https://github.com/mjwtc0722/zabbix-nginx-status



#隐私问题  目录不全
openresty/nginx/sbin/nginx -V 2>&1 | grep -o with-http_stub_status_module
with-http_stub_status_module


脚本 
mkdir -p /etc/zabbix/scripts/
vi /etc/zabbix/scripts/nginx_status.sh

#!/bin/bash
HOST="127.0.0.1"
PORT="80"
 
function proc_num {
    num=$(pgrep nginx |wc -l)
}
function active {
    num=$(curl -s "http://$HOST:$PORT/nginx_stat" |grep 'Active' |awk '{print $NF}')
}
function reading {
    num=$(curl -s "http://$HOST:$PORT/nginx_stat" |grep 'Reading' |awk '{print $2}')
}
function writing {
    num=$(curl -s "http://$HOST:$PORT/nginx_stat" |grep 'Writing' |awk '{print $4}')
}
function waiting {
    num=$(curl -s "http://$HOST:$PORT/nginx_stat" |grep 'Waiting' |awk '{print $6}')
}
function accepts {
    num=$(curl -s "http://$HOST:$PORT/nginx_stat" |awk NR==3 |awk '{print $1}')
}
function handled {
    num=$(curl -s "http://$HOST:$PORT/nginx_stat" |awk NR==3 |awk '{print $2}')
}
function requests {
    num=$(curl -s "http://$HOST:$PORT/nginx_stat" |awk NR==3 |awk '{print $3}')
}

$1
echo ${num:-0}



chmod +x   /etc/zabbix/scripts/nginx_status.sh





vi /etc/zabbix/zabbix_agentd.d/userparameter_nginx.conf



    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        #evan
         location /nginx_stat {
           stub_status on;
           access_log off;
           allow 127.0.0.1;
           deny all;
        } 
        #evan

        location / {
            root   html;
            index  index.ht

curl http://127.0.0.1/nginx_stat
Active connections: 4 
server accepts handled requests
 126582804 126582804 126582907 
Reading: 0 Writing: 4 Waiting: 0 

不能放在最后呀 虽然没语法错误 
server {
    listen 80;
    location /nginx_stat {
        stub_status on;
        access_log off;
        allow 127.0.0.1;
        deny all;
    }
}


template 下的 Template App Nginx 好像也不对 下午再看一下是哪个 template  但看起来有数据了  就他吧 


openresty -t
openresty  -s reload



最后要重启  zabbix agent 


Nginx http_stub_status_module状态查看模块

Nginx monitoring 官方