345353 发表于 2016-7-8 11:17:54

zabbix监控tcp连接数

本帖最后由 345353 于 2016-7-8 11:19 编辑

1、监控tcp状态脚本文件如下


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# cat tcp_connections.sh
#!/bin/bash
#scripts for tcp status
function SYNRECV {
/usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s}' | grep 'SYN-RECV' | awk '{print $2}'
}
function ESTAB {
/usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s}' | grep 'ESTAB' | awk '{print $2}'
}
function FINWAIT1 {
/usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s}' | grep 'FIN-WAIT-1' | awk '{print $2}'
}
function FINWAIT2 {
/usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s}' | grep 'FIN-WAIT-2' | awk '{print $2}'
}
function TIMEWAIT {
/usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s}' | grep 'TIME-WAIT' | awk '{print $2}'
}
function LASTACK {
/usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s}' | grep 'LAST-ACK' | awk '{print $2}'
}
function LISTEN {
/usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s}' | grep 'LISTEN' | awk '{print $2}'
}
function CLOSED {
/usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s}' | grep 'CLOSED' | awk '{print $2}'
}
function SYN_SENT {
/usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s}' | grep 'SYN_SENT' | awk '{print $2}'
}
function CLOSE_WAIT {
/usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s}' | grep 'CLOSE_WAIT' | awk '{print $2}'
}
function CLOSING {
/usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s}' | grep 'CLOSING' | awk '{print $2}'
}
case $1 in
   SYNRECV)
          SYNRECV
      ;;
ESTAB)
         ESTAB
      ;;
FINWAIT1)
          FINWAIT1
      ;;
FINWAIT2)
          FINWAIT2
      ;;
TIMEWAIT)
          TIMEWAIT
      ;;
LASTACK)
          LASTACK
      ;;
LISTEN)
         LISTEN
      ;;
CLOSED)
         CLOSED
      ;;
SYN_SENT)
         SYN_SENT
      ;;
CLOSE_WAIT)
         CLOSE_WAIT
      ;;
CLOSING)
         CLOSING
      ;;
       *)
          exit 1
      ;;
esac




注:其实不一样非要监控所有的状态,其实只监控自己关心的即可,不需要的可以吧脚本内容case下面的选项注释即可

2、userparameter_tcp配置文件,以及重启zabbix-agent服务即可。。


1
2
# cat userparameter_tcp.conf
UserParameter=tcp.status,/bin/bash /etc/zabbix/scripts/tcp_connections.sh $1




3、    导入模板,然后主机连接到tcp模板。稍等片刻查看状态信息


有啥问题记得看l提示和log,恩,先这样。



页: [1]
查看完整版本: zabbix监控tcp连接数