centos ping添加丢包记录

    由于生产环境有丢包情况,想确认丢包的时间点,记录到ELK系统进行分析,使用ping命令,发现centos 7.5可以实现,但是centos 6.7无法实现,google查找,发现也有人有这个需求,经过测试,找到解决方案:

    1.centos 7.5下(其他版本没有测试)

    命令:

 ping  -O  8.8.8.8 -D

   结果:

PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
[1540370905.497951] no answer yet for icmp_seq=1
[1540370905.548084] 64 bytes from 8.8.8.8: icmp_seq=2 ttl=36 time=49.9 ms
[1540370906.549005] 64 bytes from 8.8.8.8: icmp_seq=3 ttl=36 time=49.5 ms
[1540370907.556569] 64 bytes from 8.8.8.8: icmp_seq=4 ttl=36 time=51.0 ms

  2.centos 6.7没有-O的命令,在网上找了一个ping.py,稍微改动了下,可以实现需求

pip install python-ping
ls /usr/bin/ping.py

  这个没有时间戳,手动添加一个,时间紧,代码写的丑,凑活能用,如果后续有需求再改吧


   https://github.com/sunhackboy/python/blob/master/ping-addtime.py


  结尾:如果对你有用,请留言或点赞吧,不枉我重新注册github账号...

  

猜你喜欢

转载自blog.51cto.com/sjitwant/2308547