zabbix自定义监控脚本——获取tcp状态之不同命令的响应时间

1、阿里云的服务器配置:

  CPU 信息:       4  Intel(R) Xeon(R) CPU E5-2630 0 @ 2.30GHz   
  CPU 核数: 4  
  内存信息: 8G

2、最开始使用获取tcp状态的命令:

/bin/netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn|grep ESTABLISHED|awk '{print $1}'|| echo 0

3、使用zabbix_get,显示执行时间过长:

[root@ ~]# /data/soft/zabbix/bin/zabbix_get -s 192.168.1.102 -k net.stablished
ZBX_NOTSUPPORTED: Timeout while executing a shell script.

4、使用netstat查看状态,响应均是很慢:

[root@ alertscripts]$time netstat -nat |awk '{print $6}'|grep -v 'established)'|sort|uniq -c|sort -rn
  30164 ESTABLISHED
    113 TIME_WAIT
     56 LISTEN
      1 Foreign
      1 CLOSE_WAIT

real    0m7.627s
user    0m0.374s
sys     0m7.308s
[root@ alertscripts]$time /bin/netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn|grep ESTABLISHED|awk '{print $1}'|| echo 0
30193

real    0m8.056s
user    0m0.353s
sys     0m7.741s

5、最后使用 /proc/net/tcp的数据,进行统计,基本耗时在2s左右:

[root@ alertscripts]$time cat /proc/net/tcp |awk '{print $4}'|grep '01'|wc -l || echo 0
30953

real    0m2.048s
user    0m0.042s
sys     0m2.052s

#zabbix_get正常

[root@ ~]# /data/soft/zabbix/bin/zabbix_get -s 192.168.1.102 -k net.stablished
31138

6、/proc/net/tcp的数据,第四列是表示tcp状态的:

状态码对应如下:

00  "ERROR_STATUS",
01  "TCP_ESTABLISHED",
02  "TCP_SYN_SENT",
03  "TCP_SYN_RECV",
04  "TCP_FIN_WAIT1",
05  "TCP_FIN_WAIT2",
06  "TCP_TIME_WAIT",
07  "TCP_CLOSE",
08  "TCP_CLOSE_WAIT",
09  "TCP_LAST_ACK",
0A  "TCP_LISTEN",
0B  "TCP_CLOSING",

转载于:https://my.oschina.net/fufangchun/blog/903413

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值