0

I know that gnome-system-monitor can show me bandwidth even when opened by a non-root user. But tools like iftop, nethogs, etc. all seem to require root to work. How can I allow a regular user to do what gnome-system-monitor does? The application I'm going for is a script that outputs Mb/s up/down every n seconds, used for piping to a status line.

  • Non-root cannot monitor network traffic. They can see system-generated totals though – qasdfdsaq Nov 9 '15 at 15:15
4

The data you want is available for everyone, at /proc/net/dev. However, you’ll have to calculate bandwidth yourself, by taking the delta and the time between two values.

Keep in mind though, that these counters may overflow, depending on your system’s architecture and kernel version. Overflow may occur at 232-1 (reachable in a matter of seconds on Gigabit Ethernet) or 264-1 (virtually irrelevant).

1

Dir /sys/class/net/${interface}/statistics/ has all you need.

BASH script based on this: check_bandwidth.sh

0

Let's assume you're talking about nethogs. We know that nethogs is owned by root if we do ls -l $(which nethogs).

All we need to do now is change the SUID bit so that when nethogs is run, it will run with the permissions of its owner (i.e. root). Run:

sudo chmod u+s $(which nethogs)

And it should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.