我是一名公司的网管,公司有一台服务器,服务器上部署了一个公司专用的业务软件,这个软件需要连接到指定的服务器 [url=http://www.skyecho.com/]www.skyecho.com[/url] ,www1.skyecho.com, www2.skyecho.com 如果连不上将导致公司业务软件正常运行,影响公司业务正常。最近几天晚上的时候公司网络很不稳定,我做了3个批处理监控网络连接状态,代码如下(另外两个只是改下网址其它内容都一样,就不列出来了)- :ping
- cls
- @echo 本批处理用于检测网络状态并记录日志,请勿关闭
- @echo off
- title 检测www.skyecho.com服务器状态……
- echo %date:~0,10% %time% %r% >>www.txt
- ping www.skyecho.com -n 10 >>www.txt
- ping 127.0.0.1 -n 10>nul
- goto ping
复制代码 运行后的一段日志文件如下
2011-02-18 4:18:43.06
Pinging www.skyecho.com [203.88.208.133] with 32 bytes of data:
Reply from 203.88.208.133: bytes=32 time=13ms TTL=118
Reply from 203.88.208.133: bytes=32 time=13ms TTL=118
Reply from 203.88.208.133: bytes=32 time=13ms TTL=118
Reply from 203.88.208.133: bytes=32 time=13ms TTL=118
Reply from 203.88.208.133: bytes=32 time=13ms TTL=118
Reply from 203.88.208.133: bytes=32 time=13ms TTL=118
Reply from 203.88.208.133: bytes=32 time=13ms TTL=118
Reply from 203.88.208.133: bytes=32 time=13ms TTL=118
Reply from 203.88.208.133: bytes=32 time=13ms TTL=118
Reply from 203.88.208.133: bytes=32 time=13ms TTL=118
Ping statistics for 203.88.208.133:
Packets: Sent = 10, Received = 10, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 13ms, Maximum = 13ms, Average = 13ms
2011-02-18 4:19:01.15
Pinging www.skyecho.com [203.88.208.133] with 32 bytes of data:
Reply from 203.88.208.133: bytes=32 time=55ms TTL=118
Reply from 203.88.208.133: bytes=32 time=60ms TTL=118
Reply from 203.88.208.133: bytes=32 time=56ms TTL=118
Reply from 203.88.208.133: bytes=32 time=61ms TTL=118
Reply from 203.88.208.133: bytes=32 time=57ms TTL=118
Reply from 203.88.208.133: bytes=32 time=62ms TTL=118
Reply from 203.88.208.133: bytes=32 time=58ms TTL=118
Reply from 203.88.208.133: bytes=32 time=63ms TTL=118
Reply from 203.88.208.133: bytes=32 time=59ms TTL=118
Reply from 203.88.208.133: bytes=32 time=58ms TTL=118
Ping statistics for 203.88.208.133:
Packets: Sent = 10, Received = 10, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 55ms, Maximum = 63ms, Average = 58ms
现在每天要检查这些日志文件,这么多内容确实是件很麻烦的事,想对这个文件优化一下,分别将不同的结果写入到不同的日志文件,如网络延迟较大写入一个日志文件,网络中断有一个日志文件,检查网络有没有掉过线直接看有没有相应的日志文件生成就行了。
要优化的内容如下
1.批处理写入到硬盘文件的格式能够根据日期命名,如www2011-2-18.txt 到了第二天就会将日志写入到www2011-2-19
2.对写入到日志中的记录进行优化, 判断条件
①当time <=100ms时, 网络连接正常 写入a 日志文件,a文件命名 www日期.txt
②当100ms < time <=200ms 时, 网络延迟较大 写入a、b日志文件,b文件命名 www日期error1.txt
③当time>200ms 还没有达到超时, 网络很不稳定 写入a、c 日志文件,c文件命名 www日期error2.txt
④ 当网络超时时提示 网络连接中断 写入a、d日志文件,d文件命名 www日期error3.txt
假设我之前ping一次结果如下,只写入a日志文件。
2011-02-18 4:19:01.15
Pinging www.skyecho.com [203.88.208.133] with 32 bytes of data:
Reply from 203.88.208.133: bytes=32 time=55ms TTL=118
Reply from 203.88.208.133: bytes=32 time=60ms TTL=118
Reply from 203.88.208.133: bytes=32 time=56ms TTL=118
Reply from 203.88.208.133: bytes=32 time=61ms TTL=118
Ping statistics for 203.88.208.133:
Packets: Sent = 4, Received = 10, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 55ms, Maximum = 63ms, Average = 58ms
优化后的批处理将只会写入到a日志文件命名为 www2011-2-18.txt ,b、c、d日志文件将无记录
a日志文件中的内容只会显示
2011-02-18 4:19:01.15
网络连接正常
最小 = 55ms, 最大 = 63ms, 平均 = 58ms 数据包发送 = 4, 接收 = 10, 丢包率 = 0
如果出现一个有延迟的,如
2011-02-18 4:29:01.15
Pinging www.skyecho.com [203.88.208.133] with 32 bytes of data:
Reply from 203.88.208.133: bytes=32 time=155ms TTL=118
Reply from 203.88.208.133: bytes=32 time=160ms TTL=118
Reply from 203.88.208.133: bytes=32 time=156ms TTL=118
Reply from 203.88.208.133: bytes=32 time=161ms TTL=118
Ping statistics for 203.88.208.133:
Packets: Sent = 4, Received = 10, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 155ms, Maximum = 163ms, Average = 158ms
则a、b文件同时写入
2011-02-18 4:19:01.15
网络延迟较大
最小 = 155ms, 最大 = 163ms, 平均 = 158ms 数据包发送 = 4, 接收 = 10, 丢包率 = 0
如果出现超过200ms但没有出现过超时则在a、c中写入 网络很不稳定
如果出现一次超时,则在a、d中同时写入网络 网络连接中断
本人批处理只懂一点点,还请高手 指教
[ 本帖最后由 lx427 于 2011-2-18 05:27 编辑 ] |