Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi all!
I need to know the bandwith that is being consumed by a specific port.
For instances, if I have Gaim running and I'm sending a file to anyone, let's say that the port I'm using is 5090. So, how can I know how much network traffic is generated every second on that port??
Google for iptables accounting. That'll get you lots of hints on what can be done. The simplest solution I'd say is to use either mrtg or rrdtool in conjunction with an iptables rule that counts the packets. Then all you have to do is to periodically read out the byte counter and store it in an rrd. Check out the rrdtool page. If you need help in setting this up, post back.
Thnaks for your answer
It seems to be a good idea. But it assumes that the user of my program have iptables installed and configured in her system, and I know that can be difficult.
I red something about tcpdump. I know how to caputre packages on a given port, but I don't know how to use them to get the bytes/sec rate...
Originally posted by telemaco ...But it assumes that the user of my program have iptables installed and configured in her system, and I know that can be difficult.
Not necessarily. If there's a router the traffic passes through that's where you want to do the traffic monitoring.
Do you want to do long term monitoring or just want to know the throughput on a certain port at the moment? The latter is probably even possible with toys like gkrellm.
What I want to to do is the latter you said.
Every second I would like to show the information for each port.
I'm looking gkrellm and it reminds me to superkaramba but with more functionality.
It's quite good, but what I'm looking for is something in command line in order to get the value I want.
Gkrellm has its own GUI and I don't see anywhere the way to run it in comman-line.
What I have exactly i mind is...
From my littel application I make I system call to any other command line application that outputs its data to the standard output (console). Then I would use sed and grep to get the data I'm looking for.
Every second I would do a port measure so, in my application, I could show in my GUI, the program running on that port and the bandwith it is using.
Ok then clearly iptables isn't a practical solution to do the accounting. I'd use either libpcap or if you want something more high level check out pmacct. It uses libpcap and allows you to write out packet or byte counters to stdout (or better yet for your purpose: a pipe). It's very felxible and you can grab packets based on source or destination port, mac address, ip address,...
Ok, I know about pcap because It was the base of almost every program of network monitoring, but I think is too low level for me.
I will test pmacct tonight and tomorrow I'll tell you about my progress
the lower part of the screen will show you the rate (in/out) of the port you wan to monitor.
if you want to graph it, check out www.cacti.net - and see if it can handle what you need. i've never tried graphing by port. i only do rrdtool graphing per host just to monitor their b/w usage.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.