Samstag, 3. November 2012

extend ping (use timestamp and specific output) to detect network problems

Currently in production our application error logs show some strange peaks three times a day: a lot of unexpected socket timeouts. To check the network latency whithin a 24 hours time interval I need to extend the ping, with timestamp and write out the results in a log file.

The following example pings for 24 hours an "api-1"-called server and writes the results with an timestamp in a log file:

{#$}
ping -i 5 -c 17280 -s 2560 api-1 | while read res; do echo "$(date "+%y-%m-%d %H:%M:%S") $res"; done >> ping.log &
{/#$}

'-i' the ping interval, we set to 5 seconds
'-c' the count of ping, we use 17280 x 5seconds = 1day
'-s' size of packets, we use 2560 bytes

{#less ping.log}
12-11-03 11:22:38 2650 bytes from api-1 (#.46.7.1): icmp_seq=37 ttl=62 time=16.3 ms
12-11-03 11:22:43 2650 bytes from api-1 (#.46.7.1): icmp_seq=38 ttl=62 time=16.2 ms
12-11-03 11:22:48 2650 bytes from api-1 (#.46.7.1): icmp_seq=39 ttl=62 time=16.2 ms
12-11-03 11:22:53 2650 bytes from api-1 (#.46.7.1): icmp_seq=40 ttl=62 time=16.3 ms
12-11-03 11:22:58 2650 bytes from api-1 (#.46.7.1): icmp_seq=41 ttl=62 time=16.2 ms
{/#less ping.log}

Keine Kommentare:

Kommentar veröffentlichen