LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Up-/download rate for a single host (from shell) (https://www.linuxquestions.org/questions/linux-networking-3/up-download-rate-for-a-single-host-from-shell-858488/)

murmur101 01-25-2011 03:42 AM

Up-/download rate for a single host (from shell)
 
Hi all,

I have a slave node uploading all kinds of backups to my server in the internet. Now I would like to display the actual upload and download rate to this server (not the entire nic-traffic, any protocol) in a small php-page for easy monitoring.

I had a look at quite some monitoring tools and the one which kind of offers what I am looking for is iftop with a filter on the IP of my server. As I would like to periodically update a file with the actual rates, an interactive program won't do.

A possibility would be to filter the packages myself using http://search.cpan.org/~kcarnut/Net-Pcap-0.05/Pcap.pm
but this seems to be quite a long shot.

The optimal solution would be a program or script printing out the actual upload to a host specified in the options to STDOUT.

Thank you for your help

tva 01-25-2011 04:39 AM

Have you looked at ntop? http://www.ntop.org/

Not sure about filtering capabilities but I think its worth trying.

murmur101 01-25-2011 10:26 AM

Hi tva,

yeah I looked into it - it is pretty heavyweight and a bit complicated to get the actual up/download rate with a script (I tried filtering through the output with perl regexp). looking into gathering packets for a second or two with ngrep and dumping them into a temp file - but this too is ugly as hell...

murmur101 01-26-2011 07:19 AM

Hi,

solved it using iptables:


Code:

iptables -N myserver
iptables -A INPUT
iptables -A OUTPUT
iptables -A OUTPUT -d myserverip/32 -j myserver
iptables -A INPUT -s myserverip/32 -j myserver

and I query it every minute with:

Code:

iptables -L -v -n -x -Z
with a little reformatting and some minor calculations I get what I want without having to collect any packets.
Cheers!


All times are GMT -5. The time now is 07:29 AM.