1、编写监控脚本,上传客户端服务器/etc/zabbix/scripts/tcp_conn_status.sh ,注意脚本需要+x权限。
2、在客户端上的conf 文件中加配置段
vim /etc/zabbix/zabbix_agentd.d/userparameter_tcp_conn.conf
UserParameter=tcp.status[*],/etc/zabbix/scripts/tcp_conn_status.sh $1
3、客户端重启zabbix-agent.service
4、服务器端 测试zabbix_get -s 客户端ip -k tcp.status[established] 检查是否能连通
5、创建模板,名字为template tcp connetction status 隶属于templates 群组
6、创建当前模板下的监控项目 ,[closed listen synrecv synsent established timewait closing closewait lastack finwait1 finwait2] 键值tcp.status[listen] 定义应用集
7、设计模板图形 名称TCP STATUS ,然后添加入监控项 (上面11条)
8、主机 链接此模板。
图形乱码文件,找到zabbix 站点程序目录include/defines.inc.php 查看下realpath 字体文件目录,使用windows 的字体去替换这个目录内的文件。
#!/bin/bash #状态[closed listen synrecv synsent established timewait closing closewait lastack finwait1 finwait2] #set -x me=$1 tmpfile=/tmp/tcp_status.txt /bin/netstat -an|awk '/^tcp/{++a[$NF]}END{for(i in a) print i,a[i]}' >$tmpfile ######closed##### case $me in closed) status=$(awk '/CLOSED/{print $2}' $tmpfile) if [ "$status" == "" ];then echo 0 else echo $status fi ;; #####listen##### listen) status=$(awk '/LISTEN/{print $2}' $tmpfile) if [ "$status" == "" ];then echo 0 else echo $status fi ;; #####synrecv##### synrecv) status=$(awk '/SYNRECE/{print $2}' $tmpfile) if [ "$status" == "" ];then echo 0 else echo $status fi ;; #####synsent##### synsent) status=$(awk '/SYNSENT/{print $2}' $tmpfile) if [ "$status" == "" ];then echo 0 else echo $status fi ;; #####established##### established) status=$(awk '/ESTABLISHED/{print $2}' $tmpfile) if [ "$status" == "" ];then echo 0 else echo $status fi ;; #####timewait##### timewait) status=$(awk '/TIME_WAIT/{print $2}' $tmpfile) if [ "$status" == "" ];then echo 0 else echo $status fi ;; #####closing##### closing) status=$(awk '/CLOSING/{print $2}' $tmpfile) if [ "$status" == "" ];then echo 0 else echo $status fi ;; #####closewait#### closewait) status=$(awk '/CLOSEWAIT/{print $2}' $tmpfile) if [ "$status" == "" ];then echo 0 else echo $status fi ;; #####lastack##### lastack) status=$(awk '/LASTACK/{print $2}' $tmpfile) if [ "$status" == "" ];then echo 0 else echo $status fi ;; #####finwait1#### finwait1) status=$(awk '/FINWAIT1/{print $2}' $tmpfile) if [ "$status" == "" ];then echo 0 else echo $status fi ;; #####finwait2#### finwait2) status=$(awk '/FINWAIT2/{print $2}' $tmpfile) if [ "$status" == "" ];then echo 0 else echo $status fi ;; *) echo "ex:closed|listen|synrecv|synsent|established|timewait|closing|closewait|lastack|finwait1|finwait2 " esac