I'd like to measure network latency for SNMP GET request. There is a free command line tool time which can be used to find timing statistics for various commands. For example it can be used with snmpget in the following way:

$ time snmpget -v 2c -c public .
IF-MIB::ifInOctets.2 = Counter32: 112857973

real    0m0.162s
user    0m0.069s
sys 0m0.005s

According to the manual, statistics conists of:

  • the elapsed real time between invocation and termination,

  • the user CPU time (the sum of the
    tms_utime and tms_cutime values in a struct tms as returned by

  • the system CPU time (the sum of the
    tms_stime and tms_cstime values in a struct tms as returned by

As you see, none of these options allows to measure real network latency time (with excluded other program execution time stats). Is there any way to do so? Maybe not using time tool, but rather some kernel hacks?

I wanted to ask, before I'll start to write my own program.

Thanks, Piotr


The tcpdump(8) program's -ttt flag may be just what you need:

00:00:00.000031 IP haig.mdns > 0 PTR (QM)? (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.)

| improve this answer | |
  • -ttttt can also be useful -- instead of showing microseconds since last packet, it shows microseconds since the beginning of the trace. – Alex D Mar 27 '15 at 6:31

Try ping:

$ ping -U

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.

| improve this answer | |
  • Thanks for answer, but I'd like to measure latency specific to the SNMP get request. – Piotrek De Jun 24 '11 at 13:09

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.