zabbix如何监控tcp连接数
2016-05-25 11:55
423 查看
参考http://john88wang.blog.51cto.com/2165294/1586234/
tcp各个状态的意思:
ESTABLISHED socket已经建立连接CLOSED socket没有被使用,无连接
CLOSING 服务器端和客户端都同时关闭连接CLOSE_WAIT 等待关闭连接TIME_WAIT The socket is waiting after close to handle packets still in the network. 表示收到了对方的FIN报文,并发送出了ACK报文,等待2MSL后就可回到CLOSED状态LAST_ACK The remote end has shut down, and the socket is closed. Waiting for acknowledgement. 远端关闭,当前socket被动关闭后发送FIN报文,等待对方ACK报文LISTEN 监听状态SYN_RECV 接收到SYN报文SYN_SENT 已经发送SYN报文FIN_WAIT1 The socket is closed, and the connection is shutting downFIN_WAIT2 Connection is closed, and the socket is waiting for a shutdown from the remote end.
1 搭建环境:zabbix server :centos 6 ip 192.168.234.134 zabbix client (nginx) :centos 7 ip:192.168.234.133
2 监控方法:第一种监控方法用ss
vi /usr/local/zabbix/scripts/tcp.sh
5 测试链接
zabbix_get -s 192.168.234.133 -p 10055 -k tcp.status[timewait]
6 倒入模板,确认出图
附件:http://down.51cto.com/data/2367746
tcp各个状态的意思:
ESTABLISHED socket已经建立连接CLOSED socket没有被使用,无连接
CLOSING 服务器端和客户端都同时关闭连接CLOSE_WAIT 等待关闭连接TIME_WAIT The socket is waiting after close to handle packets still in the network. 表示收到了对方的FIN报文,并发送出了ACK报文,等待2MSL后就可回到CLOSED状态LAST_ACK The remote end has shut down, and the socket is closed. Waiting for acknowledgement. 远端关闭,当前socket被动关闭后发送FIN报文,等待对方ACK报文LISTEN 监听状态SYN_RECV 接收到SYN报文SYN_SENT 已经发送SYN报文FIN_WAIT1 The socket is closed, and the connection is shutting downFIN_WAIT2 Connection is closed, and the socket is waiting for a shutdown from the remote end.
1 搭建环境:zabbix server :centos 6 ip 192.168.234.134 zabbix client (nginx) :centos 7 ip:192.168.234.133
2 监控方法:第一种监控方法用ss
/usr/sbin/ss state all | awk '{++S[$1]} END {for (a in S) {printf "%11-s %s\n",a,S[a]}}' LISTEN 9 ESTAB 1 State 1 TIME-WAIT 110第二种监控方法用netstat
/bin/netstat -an|awk '/^tcp/{++S[$NF]}END{for(a in S) print a,S[a]}' LISTEN 9 ESTABLISHED 1 SYN_SENT 1 TIME_WAIT 1263 监控脚本编写
vi /usr/local/zabbix/scripts/tcp.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" esac4添加zabbix客户端配置文件
vi /usr/local/zabbix/etc/zabbix_agentd.conf 添加 UserParameter=tcp.status[*],/usr/local/zabbix/scripts/tcp.sh $1然后重启agentd服务
5 测试链接
zabbix_get -s 192.168.234.133 -p 10055 -k tcp.status[timewait]
6 倒入模板,确认出图
附件:http://down.51cto.com/data/2367746
相关文章推荐
- TCP版backshell的VBS脚本代码
- 使用C语言编写基于TCP协议的Socket通讯程序实例分享
- TCP Wrappers防火墙介绍与封锁IP地址的方法
- c语言多进程tcp服务器示例
- win2003连接限制TCP连接限制
- PowerShell脚本开发之收发TCP消息包
- Nodejs创建TCP服务器 - king0222
- C#实现TCP连接信息统计的方法
- linux shell 脚本实现tcp/upd协议通讯(重定向应用)
- 使用C#实现基于TCP和UDP协议的网络通信程序的基本示例
- Android使用socket创建简单TCP连接的方法
- Android实现TCP客户端接收数据的方法
- Android TCP 文件客户端与服务器DEMO介绍
- Android中实现TCP和UDP传输实例
- python实现可将字符转换成大写的tcp服务器实例
- php实现TCP端口检测的方法
- Java实现Socket的TCP传输实例
- 实现了基于TCP的Java Socket编程实例代码
- Java基于TCP方式的二进制文件传输
- Java基于Tcp协议的socket编程实例