Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to average upload and download speed using dstat -n. How can I add all the received and sent data sizes that appear after dstat -n, so that I can add them and find average upload and download speed over some period of time ?

share|improve this question

You basically want dstat to provide you with an average over a given time (say 120 secs). This works exactly the same as vmstat or ifstat, the first argument is the delay, which means the given time to provide averages over. Default is 1 second.

So this should do:

dstat -n 120

or for given interfaces eth0 and eth1, do:

dstat -n -N eth0,eth1 120

or for all interfaces:

dstat -n -f 120

But if you prefer some output you can post-process, it's probably more interesting to have it write out CSV data:

dstat -n -f -o stat.csv 120

Which will write out 120sec averages out to a CSV file named stat.csv.

share|improve this answer
up vote 0 down vote accepted

As no one answered,I have figured it out. Here is how to do it. Let's say we need to average it for "2 min(120 sec)". First write it to a file named stat.txt.Refresh every second fro 120 times.

   dstat -n 1 120 >> stat.txt

Add the columns of stat.txt

   awk -F" " '{t1=t1+$1;t2=t2+$2}END{t1=t1/120;t2=t2/120;print t1"\t"t2}' stat.txt

Remove stat.txt

   rm stat.txt

We can make a script too from these commands.

share|improve this answer

It seems that dstat is a renamed/hacked version of the sysstat commands, and those will give you the measured traffic, not bandwidth ("speed"). To get that (and that will depend on the target system's load, the path to get there, ...), use something like curl(1), which will tell you afterwards what the average speed was. Also, most home installations are asymmetric, your upload bandwidth is a fraction of the download one.

Also consider that raw bandwith isn't enough, latency is critical for interactive applications (particularly games).

Perhaps a look at the bufferbloat phenomenon is also in order.

share|improve this answer

Your Answer


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.