rockmountain has asked for the wisdom of the Perl Monks concerning the following question:

http://speedcheck2.optonline.net/speedcheck/speedcheck.html This link shows first roadmap to what I want to implement. In disassembly I find out that it uses javascript and uses Microsoft API. I am not clear about the algorithm implemented. But sure it checks the rate of packets flow. What I really want to do is to somehow monitor the performance of my Cable Operator and store the information in a database. I am able to execute netstat, but trying hard to find a way to use those information contained in the packets. Please enlighten me in this area. And it is my personal belief or you can say it a jibgoism that Perl is a better solution provider then that idiotically slow java and javascript.
cheers Rock
  • Comment on How to monitor internet speed in real time?

Replies are listed 'Best First'.
Re: How to monitor internet speed in real time?
by matija (Priest) on Oct 05, 2004 at 12:01 UTC
    What is "internet speed" to you? Is it derived as
        distance_flown_by_the_internet
    ---------------------------------------
    time_when_it_lands-time_when_I_threw_it
    
    Or is it the speed of data through your internet interface? If the later, I use the following script as an input to MRTG graph:
    open(INP,"</proc/net/dev") || die "Can not open /proc/net/dev: $!"; while (<INP>) { s/eth0:(\d)/eth0: $1/; @a=split; print "$a[1]\n$a[9]\n" if ($a[0]=~s/eth0://); }
    This, of course, is highly system dependent...
Re: How to monitor internet speed in real time?
by jaco (Pilgrim) on Oct 05, 2004 at 13:49 UTC
    You have to be careful using the first equation matija
    pointed out on things such as dialup modems. One of
    the things people seem to forget about is data compression
    over PPP or even gzip'd browser compression. So if you
    download a 200k text file it'll appear like you're getting
    168Kbs on a dial up modem, because the NAS gear
    compresses the bejesus out of it.

    I say use a jpeg or already gziped file on a server and
    Time::HiRes for your time specs. Just make sure the
    data size you claim to be downloading is the actual amount of
    data that came across the pipe.
Re: How to monitor internet speed in real time?
by ambrus (Abbot) on Oct 05, 2004 at 17:34 UTC

    Your question is not really exact.

    Are you trying to monitor internet traffic of a certain machine from the machine itself, or from a different machine? Do you want to mesure all network usage or only that to certain destinations, protocols, ports or programs? And most importantly, what OS are you using?

    Anyway, here's some starting point for linux. In linux, there is a counter that counts the total incoming and outgoing bytes on a network interface. You access this counter with the ifconfig program, or directly from /proc/net/dev (this is linux 2.4.25, the /proc interface might be different in other versions). If you read that counter every few seconds, you can see how much data comes in and out.

    If you need more detailed statistics, you have to use iptables. Every iptables rule has a byte counter similar to that above. To read this, you run iptables -L -nvx or figure out how iptables gets the data from the kernel. The drawback of this is that iptables requires root permissions, while netstat ifconfig (Update: I meant to say ifconfig here, just as above) does not normally.

    Update: see also Re: measuring IN/OUT traffic on your computer which is about the same problem but has code.

      http://speedcheck2.optonline.net/speedcheck/speedcheck.html This link shows first roadmap to what I want to implement. In disassembly I find out that it uses javascript and uses Microsoft API. I am not clear about the algorithm implemented. But sure it checks the rate of packets flow. What I really want to do is to somehow monitor the performance of my Cable Operator and store the information in a database. I am able to execute netstat, but trying hard to find a way to use those information contained in the packets. Please enlighten me in this area. And it is my personal belief or you can say it a jingoism that Perl is a better solution provider then that idiotically slow java and javascript
      cheers Rock

        I couldn't view the webpage you've given, so I don't know if it mesures the network usage of your computer or only the speed of the connection of your computer and their server (which can be a good approximation of your internet access bandwidth if you're not downloading anything the same time you're running the speedcheck).

        Netstat is not relevant here. I meant to say ifconfig from the start, but I was tired and said netstat instead in the last paragraph.

        About ifconfig. On my system it prints a line like this about the eth0 interface.

        RX bytes:466213 (455.2 Kb) TX bytes:40233 (39.2 Kb)
        (I've just started my machine so that's why the numbers are so small.) I remember that some older versions of ifconfig does not print this info, probably because this feature was not available in older (2.2) kernels. The command corresponding to ifconfig in windows is ipconfig but I don't know whether it prints this info.

Re: How to monitor internet speed in real time?
by chanio (Priest) on Oct 06, 2004 at 05:47 UTC
    Perhaps you might like to do a java applet that synchronizes with a perl script at the serverside. And that keeps drawing some graphics of the traffic. The applet starts when the user loads the page. The java applet is working at the user's side.

    .{\('v')/}
    _`(___)' __________________________
    Wherever I lay my KNOPPIX disk, a new FREE LINUX nation could be established.
      Hey,can you tell me something in perl. I don't know java enough. But I must tell you, you hit the bull's eye
      cheers Rock
        Well, the JAVA applet is an example to show you that JAVA applets work from the users side of all.

        So, your server creates the page that contains a JAVA applet (you might find it from the plenty of JAVA stuff in the web). And then the user loads that html page and the applet starts working connected with your server (just sending pings or some other thing, don't know).

        From the applet's JAVA side I could inform you just what you need to know: that it works with some parameters that your server writes in the html page. The parameters that the applet needs (as any perl script). Then, with this parameters it starts working when the user loads the html page. JAVA works inside a 'sandbox' that doesn't compromise any other part of the users machine. So it is safe and should provide you with what you need at the server side.

        Hope that it helps!

        .{\('v')/}
        _`(___)' __________________________
        Wherever I lay my KNOPPIX disk, a new FREE LINUX nation could be established.