环境说明
- 已关闭防火墙、selinux;
- 所用zabbix版本4.0.3(源码安装);
- 开启Nginx状态监测,开启配置详情请见Nginx状态监测;
- 所用IP地址如下表:
ip地址 |
角色 |
192.168.163.128 |
server |
192.168.163.168 |
agent |
配置
#!/bin/bash
NGINX_PORT=80
NGINX_COMMON=$1
function Active_connection () {
curl -s http://127.0.0.1:$NGINX_PORT/status | awk '/Active/ {print NF}'
}
function accepts () {
curl -s http://127.0.0.1:$NGINX_PORT/status | awk 'NR==3 {print $1}'
}
function handled () {
curl -s http://127.0.0.1:$NGINX_PORT/status | awk 'NR==3 {print $2}'
}
function requests () {
curl -s http://127.0.0.1:$NGINX_PORT/status | awk 'NR==3 {print $3}'
}
function Reading () {
curl -s http://127.0.0.1:$NGINX_PORT/status | awk '/Reading/ {print $2}'
}
function Writing () {
curl -s http://127.0.0.1:$NGINX_PORT/status | awk '/Writing/ {print $4}'
}
function Waiting () {
curl -s http://127.0.0.1:$NGINX_PORT/status | awk '/Waiting/ {print $6}'
}
case $1 in
Active_connection)
Active_connection;
;;
requests)
requests;
;;
accepts)
accepts;
;;
handled)
handled;
;;
Reading)
Reading;
;;
Writing)
Writing;
;;
Waiting)
Waiting;
;;
*)
echo "Usage:$0 {Active_connection|requests|accepts|handled|Reading|Writing|Waiting}"
;;
esac
[root@localhost scripts]# chmod +x nginx_status.sh
- 修改配置文件/usr/local/etc/zabbix_agentd.conf
UnsafeUserParameters=1
UserParameter=nginx_status[*],/bin/bash /scripts/nginx_status.sh "$1"
pkill zabbix_agentd
zabbix_agentd
[root@localhost init.d]# zabbix_get -s 127.0.0.1 -k "nginx_status[requests]"
481