First, set on the monitored side
Main command: Netstat-an | awk '/^tcp/{++s[$NF]} END {for (a in S) print A, s[a]} '
1 |
Netstat-an | awk '/^tcp/{++s[$NF]} END {for (a in S) print A, s[a]} ' |
Output content:
Time_wait 100
Close_wait 5
Fin_wait1 6
Established 161
SYN_RECV 1
Last_ack 1
LISTEN 11
The following is an example of monitoring the number of time_wait (first to prepare the script) Mkdir-pv/usr/local/shell/zabbix Cd/usr/local/shell/zabbix vim tcp_connections.sh
1 2 3) 4 5 |
Mkdir-pv/usr/local/shell/zabbix Cd/usr/local/shell/zabbix vim tcp_connections. Sh |
#!/bin/bash Netstat-an | awk '/^tcp/{++s[$NF]} END {for (a in S) print A, S[a]} ' | grep $1| Cut-d '-F2//script relies on the main command above
1 2 3 4 |
#!/bin/bash Netstat-an | awk '/^tcp/{++s[$NF]} END {for (a in S) print A, S[a]} ' | grep $1 | Cut-d '-F2//script relies on the main command above |
Edit the Zabbix configuration file on the node that zabbix_server is monitored vim/usr/local/zabbix/etc/zabbix_agentd.conf
1 |
Vim/usr/local/zabbix/etc/zabbix_agentd. Conf |
#在256行添加下列内容
Unsafeuserparameters=1
#在265行添加以下内容
Userparameter=time_wait,/bin/bash/usr/local/shell/zabbix/tcp_connections.sh TIME_WAIT
Restart the client service Zabbix_agentd restart
1 |
Service Zabbix_agentd Restart |
Second, Zabbix_server terminal settings
First see if you can fetch the value cd/usr/local/zabbix/bin./zabbix_get-s 10.6.5.1-k time_wait
1 2 3 |
Cd/usr/local/zabbix/bin. /zabbix_get-s 10.6.5.1-k time_wait |
If you can get the value, then congratulations on your success.
Access the Zabbix Web interface to create templates
Invasive
Building graphics
Apply the template to the corresponding machine and the drawing results are as follows:
In this Zabbix, the number of TCP connections that are customized to monitor a host is fixed.
#!/bin/bash
Sed-i "s#\# unsafeuserparameters=0#unsafeuserparameters=1#g"/usr/local/etc/zabbix_agentd.conf
echo "include=/usr/local/etc/zabbix_agentd.conf.d/" >>/usr/local/etc/zabbix_agentd.conf
Mkdir-p/usr/local/shell/zabbix
Cat << EOF >/usr/local/shell/zabbix/tcp_connections.sh
#!/bin/bash
Netstat-an |awk '/^tcp/{++s[\ $NF]} END {for (a in S) print A, S[a]} ' |grep \$1|cut-d '-f2
Eof
Cat << EOF >/usr/local/shell/zabbix/zabbix_tcp.sh
#!/bin/bash
Netstat-s|grep "Connections established" |awk ' {print\$1} '
Eof
chmod 755/usr/local/shell/zabbix/zabbix_tcp.sh
Mkdir-p/USR/LOCAL/ETC/ZABBIX_AGENTD.CONF.D
Cat << EOF >/usr/local/etc/zabbix_agentd.conf.d/tcp
#!monitor TCP
Userparameter=time_wait,/bin/bash/usr/local/shell/zabbix/tcp_connections.sh TIME_WAIT
Userparameter=close_wait,/bin/bash/usr/local/shell/zabbix/tcp_connections.sh CLOSE_WAIT
Userparameter=established,/bin/bash/usr/local/shell/zabbix/tcp_connections.sh ESTABLISHED
Userparameter=fin_wait1,/bin/bash/usr/local/shell/zabbix/tcp_connections.sh FIN_WAIT1
Userparameter=last_ack,/bin/bash/usr/local/shell/zabbix/tcp_connections.sh Last_ack
Userparameter=listen,/bin/bash/usr/local/shell/zabbix/tcp_connections.sh LISTEN
Userparameter=syn_recv,/bin/bash/usr/local/shell/zabbix/tcp_connections.sh SYN_RECV
userparameter=tcpconnect,/usr/local/shell/zabbix/zabbix_tcp.sh
Eof
Service Zabbix_agentd Restart
Key values for several monitoring items are time_wait, close_wait, established, Fin_wait1, Last_ack, LISTEN, SYN_RECV, Tcpconnect