一、下载客户端按照包,这里用rpm包安装
修改客户端配置文件 1
2
| Server=127.0.0.1
ServerActive=127.0.0.1
|
改为zabbix server实际的IP地址(比如zabbix server的IP地址为10.0.0.100) 1
2
| Server=10.0.0.100
ServerActive=10.0.0.100
|
重启zabbix 客户端 1
| [iyunv@zabbix]# systemctl restart zabbix-agent
|
二、自定义脚本监控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
| #!/bin/bash
HOST=localhost
PORT="9999"
function active {
/usr/bin/curl "http://$HOST:$PORT/nginx-status/" 2>/dev/null| grep 'Active' | awk '{print $NF}'
}
function reading {
/usr/bin/curl "http://$HOST:$PORT/nginx-status/" 2>/dev/null| grep 'Reading' | awk '{print $2}'
}
function writing {
/usr/bin/curl "http://$HOST:$PORT/nginx-status/" 2>/dev/null| grep 'Writing' | awk '{print $4}'
}
function waiting {
/usr/bin/curl "http://$HOST:$PORT/nginx-status/" 2>/dev/null| grep 'Waiting' | awk '{print $6}'
}
function accepts {
/usr/bin/curl "http://$HOST:$PORT/nginx-status/" 2>/dev/null| awk NR==3 | awk '{print $1}'
}
function handled {
/usr/bin/curl "http://$HOST:$PORT/nginx-status/" 2>/dev/null| awk NR==3 | awk '{print $2}'
}
function requests {
/usr/bin/curl "http://$HOST:$PORT/nginx-status/" 2>/dev/null| awk NR==3 | awk '{print $3}'
}
$1
|
将脚本存放与脚本目录,注意该目录根据自己情况定义,我这里用rpm 按照zabbix-agent客户端,所以直接放在/etc/zabbix/script目录下 1
2
3
| [iyunv@localhost script]# ll nginx-status.sh
-rwx------ 1 root root 947 Mar 22 10:49 nginx-status.sh
[iyunv@localhost script]#
|
不要忘了给脚本执行权限 1
2
3
4
5
| [iyunv@localhost script]# chmod +x nginx-status.sh
[iyunv@localhost script]#
[iyunv@localhost script]# ll nginx-status.sh
-rwxr-xr-x 1 root root 947 Mar 22 10:49 nginx-status.sh
[iyunv@localhost script]#
|
修改配置文件,在末尾添加如下内容: 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
26
27
| [iyunv@localhost zabbix]# vim zabbix_agentd.conf
...................................省略部分......................................................
### DISK I/O
UserParameter=custom.vfs.dev.read.ops,cat /proc/diskstats | grep $1 | head -1 | awk '{print $$4}'
UserParameter=custom.vfs.dev.read.ms,cat /proc/diskstats | grep $1 | head -1 | awk '{print $$7}'
UserParameter=custom.vfs.dev.write.ops,cat /proc/diskstats | grep $1 | head -1 | awk '{print $$8}'
UserParameter=custom.vfs.dev.write.ms,cat /proc/diskstats | grep $1 | head -1 | awk '{print $$11}'
UserParameter=custom.vfs.dev.io.active,cat /proc/diskstats | grep $1 | head -1 | awk '{print $$12}'
UserParameter=custom.vfs.dev.io.ms,cat /proc/diskstats | grep $1 | head -1 | awk '{print $$13}'
UserParameter=custom.vfs.dev.read.sectors,cat /proc/diskstats | grep $1 | head -1 | awk '{print $$6}'
UserParameter=custom.vfs.dev.write.sectors,cat /proc/diskstats | grep $1 | head -1 | awk '{print $$10}'
######## TCP connections total
UnsafeUserParameters=1
UserParameter=synrecv,/etc/zabbix/script/tcp_connection_status.sh SYNRECV
UserParameter=estab,/etc/zabbix/script/tcp_connection_status.sh ESTAB
UserParameter=timewait,/etc/zabbix/script/tcp_connection_status.sh TIMEWAIT
UserParameter=last_ack,/etc/zabbix/script/tcp_connection_status.sh LAST_ACK
UserParameter=total,/etc/zabbix/script/tcp_connection_status.sh TOTAL
#####Nginx Status
UserParameter=nginx.accepts,/etc/zabbix/script/nginx-status.sh accepts
UserParameter=nginx.handled,/etc/zabbix/script/nginx-status.sh handled
UserParameter=nginx.requests,/etc/zabbix/script/nginx-status.sh requests
UserParameter=nginx.connections.active,/etc/zabbix/script/nginx-status.sh active
UserParameter=nginx.connections.reading,/etc/zabbix/script/nginx-status.sh reading
UserParameter=nginx.connections.writing,/etc/zabbix/script/nginx-status.sh writing
UserParameter=nginx.connections.waiting,/etc/zabbix/script/nginx-status.sh waiting
EnableRemoteCommands=1
|
然后重启zabbix客户端 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| [iyunv@zabbix]# systemctl restart zabbix-agent
[iyunv@localhost zabbix]# systemctl status zabbix-agent
● zabbix-agent.service - Zabbix Agent
Loaded: loaded (/usr/lib/systemd/system/zabbix-agent.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2017-03-22 11:03:05 CST; 6min ago
Process: 13613 ExecStop=/bin/kill -SIGTERM $MAINPID (code=exited, status=0/SUCCESS)
Process: 13615 ExecStart=/usr/sbin/zabbix_agentd -c $CONFFILE (code=exited, status=0/SUCCESS)
Main PID: 13617 (zabbix_agentd)
CGroup: /system.slice/zabbix-agent.service
├─13617 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
├─13618 /usr/sbin/zabbix_agentd: collector [idle 1 sec]
├─13619 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection]
├─13620 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection]
└─13621 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection]
Mar 22 11:03:05 localhost systemd[1]: Starting Zabbix Agent...
Mar 22 11:03:05 localhost systemd[1]: PID file /run/zabbix/zabbix_agentd.pid not readable (yet?) after start.
Mar 22 11:03:05 localhost systemd[1]: Started Zabbix Agent.
[iyunv@localhost zabbix]#
|
最后在服务端添加主机对应的监控项,键值为如下字段: 1
2
3
4
5
6
7
| nginx.accepts
nginx.handled
nginx.requests
nginx.connections.active,
nginx.connections.reading
nginx.connections.writing
nginx.connections.waiting
|
|