0

Does somebody know a module, which has a function that returns ( for example for eth0 ) the download speed?

sid_com
  • 24,137
  • 26
  • 96
  • 187
  • I have gigabit ethernet but my Internet connection is ADSL. The phrasing of your question suggests that (for my system) you are looking for 1000 Mbit/s, is that right? – Quentin Apr 11 '12 at 08:31
  • Then the phrasing was not ok. I'm interested in the Internet connection. – sid_com Apr 11 '12 at 14:58
  • There is no reliable way to measure that. Speeds will vary depending on where the other end point is, what other traffic is going over the network at the time, and so on. – Quentin Apr 11 '12 at 14:59
  • Yet there are tools which are printing the (changing) download-speed. Of course it would suffice some round about value. – sid_com Apr 11 '12 at 15:14
  • That would be an estimate of the speed of a particular transfer between two particular end points. Not a generic measure of link speed. – Quentin Apr 11 '12 at 15:16

2 Answers2

2

Employ a monitoring program: atop, iftop, ntop, dstat, icinga, munin, knemo, ksysguardd

daxim
  • 39,270
  • 4
  • 65
  • 132
  • It's to laborious with this tools to get the needed info in my script. And the script doesn't run with superuser privileges. – sid_com Apr 11 '12 at 15:03
  • Not true. There's nothing laborious about `my ($recv, $send) = qx'dstat --net 1 1' =~ /(\d+\w*)\s+(\d+\w*)\s+\z/;`. It runs fine without super user priv. – daxim Apr 25 '12 at 23:15
0
#!/usr/bin/perl

use strict;
use warnings;
use Time::HiRes;
use LWP::Simple;

my $url = 'http://www.cnn.com/';
my $file = 'cnn.html';
my $start = [Time::HiRes::gettimeofday()];
getstore($url, $file);
my $time = Time::HiRes::tv_interval($start);
my $size = -s $file;

printf "Speed: %d kbps\n", $size/$time/1000;
Ωmega
  • 42,614
  • 34
  • 134
  • 203