1) agent side configuration
- agent-side scripting acquisition monitored item
#vim /etc/zabbix/zabbix_agentd.d/tcp_status.sh
#bin/bash
[ $# -ne 1 ] && echo "Usage:CLOSE-WAIT|CLOSED|CLOSING|ESTAB|FIN-WAIT-1|FIN-WAIT-2|LAST-ACK|LISTEN|SYN-RECV SYN-SENT|TIME-WAIT" && exit 1
tcp_status_fun(){
TCP_STAT=$1
ss -ant | awk 'NR>1 {++s[$1]} END {for(k in s) print k,s[k]}' > /tmp/ss.txt
TCP_STAT_VALUE=$(grep "$TCP_STAT" /tmp/ss.txt | cut -d ' ' -f2)
if [ -z "$TCP_STAT_VALUE" ];then
TCP_STAT_VALUE=0
fi
echo $TCP_STAT_VALUE
}
tcp_status_fun $1;
-
修改脚本权限
#chmod +x /etc/zabbix/zabbix_agentd.d/tcp_status.sh
- Modify agent profiles
#vim /etc/zabbix/zabbix_agentd.d/tcp_status.conf
UserParameter=tcp_status[*],/bin/bash /etc/zabbix/zabbix_agentd.d/tcp_status.sh "$1"
- agentd restart the service
systemctl restart zabbix-agent
Note: The owner /tmp/ss.txt file is zabbix
(2) server side configuration
Ideas: define tcp_status template ---> defined set of applications nginx_status ---> defined monitoring item ----> custom graphics ---> define the trigger ----> add a host or hosts associated with this template
- zabbix-server end of the test obtain zabbix_get
# zabbix_get -s 192.168.1.32 -p10050 -k tcp_status[ESTAB]
2
- The key
tcp_status[ESTAB]
tcp_status[CLOSE-WAIT]
tcp_status[CLOSED]
tcp_status[CLOSING]
tcp_status[FIN-WAIT-1]
tcp_status[FIN-WAIT-2]
tcp_status[LAST-ACK]
tcp_status[LISTEN]
tcp_status[SYN-RECV]
tcp_status[SYN-SENT]
tcp_status[TIME-WAIT]
- Defined monitoring item: write only one, the other is a different key
- Custom Graphics
- verification