打开这个文件 /usr/local/nginx/conf/nginx.conf
一般是有模块监控功能 没有就添加
我的文件配置全部是这样
server {
listen 884;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location /status {
stub_status on;
}
location / {
root /usr/local/nginx/html;
index index.html index.htm index.php;
}
location ~ \.php$ {
root /usr/local/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
创建一个脚本文件
mkdir /usr/local/zabbix/scripts
记得个脚本权限
在该目录下创建脚本文件 vi nginx_status
#!/bin/bash
# Script to fetch nginx statuses for tribily monitoring systems
# Author: xiaoluo
# License: GPLv2
function active {
/
usr
/
bin
/
curl
"http://192.168.10.7:8067/status"
2
>
/
dev
/
null| grep
'Active'
| awk
'{print $NF}'
}
function reading {
/
usr
/
bin
/
curl
"http://192.168.10.7:8067/status"
2
>
/
dev
/
null| grep
'Reading'
| awk
'{print $2}'
}
function writing {
/
usr
/
bin
/
curl
"http://192.168.10.7:8067/status"
2
>
/
dev
/
null| grep
'Writing'
| awk
'{print $4}'
}
function waiting {
/
usr
/
bin
/
curl
"http://192.168.10.7:8067/status"
2
>
/
dev
/
null| grep
'Waiting'
| awk
'{print $6}'
}
function accepts {
/
usr
/
bin
/
curl
"http://192.168.10.7:8067/status"
2
>
/
dev
/
null| awk NR
=
=
3
| awk
'{print $1}'
}
function handled {
/
usr
/
bin
/
curl
"http://192.168.10.7:8067/status"
2
>
/
dev
/
null| awk NR
=
=
3
| awk
'{print $2}'
}
function requests {
/
usr
/
bin
/
curl
"http://192.168.10.7:8067/status"
2
>
/
dev
/
null| awk NR
=
=
3
| awk
'{print $3}'
}
# Run the requested function
$
1
UnsafeUserParameters=1 值为1 还有记得修改include 里面的目录包含Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
(有后面这个*号才能运行/usr/local/zabbix/etc/zabbix_agentd.conf.d这个文件目录下的内容)
然后再到这个文件下/usr/local/zabbix/etc/zabbix_agentd.conf.d
创建一个文件 nginx.conf可以执行上面的KEY值的
内容UserParameter=nginx[*],/usr/local/zabbix/scripts/nginx_status $1
配置完记得重启zabbix_agentd服务就可以了