标签:gen inf emc list erp info ast time server
agent端脚本获取监控项
#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
修改agent配置文件
#vim /etc/zabbix/zabbix_agentd.d/tcp_status.conf
UserParameter=tcp_status[*],/bin/bash /etc/zabbix/zabbix_agentd.d/tcp_status.sh "$1"
agentd重启服务
systemctl restart zabbix-agent
注意:/tmp/ss.txt文件的属主是zabbix
zabbix-server端zabbix_get测试获取
# zabbix_get -s 192.168.1.32 -p10050 -k tcp_status[ESTAB]
2
键值
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]
验证
标签:gen inf emc list erp info ast time server
原文地址:https://www.cnblogs.com/lovelinux199075/p/9013411.html