Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 192.168.1.3 .1.3.6.1.2.1.2.2.1.10.2
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
    times(2)),

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

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

share|improve this question

migrated from stackoverflow.com Jun 25 '11 at 9:34

This question came from our site for professional and enthusiast programmers.

add comment

3 Answers 3

up vote 4 down vote accepted

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.)

share|improve this answer
add comment

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.

share|improve this answer
add comment

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.

share|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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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