Network latency measurement (Linux)
The tcpdump(8)
program's -ttt
flag may be just what you need:
00:00:00.000031 IP haig.mdns > 224.0.0.251.mdns: 0 PTR (QM)? 1.0.168.192.in-addr.arpa. (42)
00:00:01.897031 IP haig.45240 > stackoverflow.com.www: Flags [F.], seq 866615166, ack 62506321, win 123, options [nop,nop,TS val 6026371 ecr 419296939], length 0
00:00:00.000030 IP haig.45242 > stackoverflow.com.www: Flags [F.], seq 853537650, ack 61102072, win 123, options [nop,nop,TS val 6026371 ecr 419296939], length 0
00:00:00.000019 IP haig.45243 > stackoverflow.com.www: Flags [F.], seq 863535366, ack 62086489, win 123, options [nop,nop,TS val 6026371 ecr 419296939], length 0
The timestamp at the beginning of the lines show the time in microseconds since the previous packet. By giving a different number of -t
on the command line, you can get either absolute times, relative times since the first packet, or relative times between packets.
I've just shown random mdns and web traffic because that's what is easy to find on my system; you could easily filter for SNMP traffic with tcpdump(8)
to get only the packets you're interested in. (Which would be a good idea, as dumping all traffic from busy systems can generate a huge load.)
Try ping:
$ ping -U 192.168.1.3
From the ping manual:
-U Print full user-to-user latency (the old behaviour). Normally ping prints network round trip time, which can be different f.e. due to DNS failures.
Run you program and the meantime capture network traffic with tcpdump
or wireshark
. Check the time of the request and the reply and do a simple subtraction.