zabbix监控TCP连接数方法

2025-10-19 16:14:45

1、zabbix server的版本为3.4.9

zabbix监控TCP连接数方法

2、自定义监控项tcp.status

zabbix监控TCP连接数方法

3、 cat /etc/zabbix/scripts/tcp_conn_status.sh

#!/bin/bash

#this script is used to get tcp and udp connetion status

#tcp status

metric=$1

tmp_file=/tmp/tcp_status.txt

/bin/netstat -an|awk '/^tcp/{++S[$NF]}END{for(a in S) print a,S[a]}' > $tmp_file

case $metric in

   closed)

          output=$(awk '/CLOSED/{print $2}' $tmp_file)

          if [ "$output" == "" ];then

             echo 0

          else

             echo $output

          fi

        ;;

   listen)

          output=$(awk '/LISTEN/{print $2}' $tmp_file)

          if [ "$output" == "" ];then

             echo 0

          else

             echo $output

          fi

        ;;

   synrecv)

          output=$(awk '/SYN_RECV/{print $2}' $tmp_file)

          if [ "$output" == "" ];then

             echo 0

          else

             echo $output

          fi

        ;;

   synsent)

          output=$(awk '/SYN_SENT/{print $2}' $tmp_file)

          if [ "$output" == "" ];then

             echo 0

          else

             echo $output

          fi

        ;;

   established)

          output=$(awk '/ESTABLISHED/{print $2}' $tmp_file)

          if [ "$output" == "" ];then

             echo 0

          else

             echo $output

          fi

        ;;

   timewait)

          output=$(awk '/TIME_WAIT/{print $2}' $tmp_file)

          if [ "$output" == "" ];then

             echo 0

          else

             echo $output

          fi

        ;;

   closing)

          output=$(awk '/CLOSING/{print $2}' $tmp_file)

          if [ "$output" == "" ];then

             echo 0

          else

             echo $output

          fi

        ;;

   closewait)

          output=$(awk '/CLOSE_WAIT/{print $2}' $tmp_file)

          if [ "$output" == "" ];then

             echo 0

          else

             echo $output

          fi

        ;;

   lastack)

          output=$(awk '/LAST_ACK/{print $2}' $tmp_file)

          if [ "$output" == "" ];then

             echo 0

          else

             echo $output

          fi

         ;;

   finwait1)

          output=$(awk '/FIN_WAIT1/{print $2}' $tmp_file)

          if [ "$output" == "" ];then

             echo 0

          else

             echo $output

          fi

         ;;

   finwait2)

          output=$(awk '/FIN_WAIT2/{print $2}' $tmp_file)

          if [ "$output" == "" ];then

             echo 0

          else

             echo $output

          fi

         ;;

         *)

          echo -e "\e[033mUsage: sh  $0 [closed|closing|closewait|synrecv|synsent|finwait1|finwait2|listen|established|lastack|timewait]\e[0m"

   

esac

zabbix监控TCP连接数方法

4、zabbix web页面创建监控项

zabbix监控TCP连接数方法

5、最新数据中已经有TCP的连接信息了

zabbix监控TCP连接数方法

6、点图形可以看到趋势

zabbix监控TCP连接数方法

7、还可以创建触发器

zabbix监控TCP连接数方法

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢