1. 程式人生 > >Zabbix 監控 TCP 連線 。

Zabbix 監控 TCP 連線 。

一步:編寫監控 shell 指令碼。

[[email protected] ~]# cd /usr/local/zabbix/scripts/

[[email protected] scripts]# vim tcp_status.sh

#!/bin/bash
############################################################
#$Name: tcp_status.sh
#$Version: v1.0
$Function: TCP Status
$Author: wangwang
$organization: wangwang
#$Create Date: 2018-12-25
#$Description: Monitor TCP Service Status

############################################################
[ $# -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;

二步:新增執行許可權 。

[[email protected] scripts]# chmod +x tcp_status.sh

三步:編輯 zabbix_agentd.conf 的配置檔案。
[[email protected] ~]# vim /etc/zabbix/zabbix_agentd.conf
UserParameter=tcp_status[*],/bin/bash /etc/zabbix/scripts/tcp_status.sh "$1"

四步:重啟 zabbix-agent 修改配置檔案必須重啟。
[[email protected] ~]# systemctl restart zabbix-agent

五步:Server測試Agent是否能獲取到值,通過Zabbix_get(不要直接執行指令碼)。
[[email protected] ~]# zabbix_get -s 192.168.90.11 -k tcp_status[ESTAB]
10

六步:新增所有監控項(將模板關聯主機)。

Zabbix  監控  TCP 連線 。

七步:檢視相關資料。