get the IFLA_STATS attribute (rx/tx byte counters) for a specific interface

Thomas Graf tgraf at infradead.org
Fri Feb 25 11:37:07 EST 2011


On Fri, Feb 25, 2011 at 05:17:50PM +0100, Jan-Philip gehrcke wrote:
> Hello,
> 
> currently, I'm trying to create a bandwidth measurement program for my
> Linux router in C. Obviously, for calculating a bandwidth, you need a
> time and byte count difference. Due to performance reasons, I would like
> to get the byte counters directly from the kernel, without reading from
> /proc oder /sys. Therefore, I'm working myself through the 'ip' program,
> gathering this data via rtnetlink using libnetlink. While searching the
> web to understand more of this topic, I came across libnl which seems to
> be a cleaner and more modern implementation. However, I'm a bit
> overwhelmed by the documentation.

You may want to have a look at:

http://www.infradead.org/~tgr/bmon/

It is a bandwidth measurement program I've created which is based on
libnl.

> Assume I know the interface index of the interface I want to evaluate.
> Then, what is the cleanest way to use libnl to receive the corresponding
> IFLA_STATS attribute [1] containing the byte counters? I would
> appreciate any guidance/suggestion that helps me orienting in libnl :-)

A good reference would be:

http://git.infradead.org/users/tgr/bmon.git/blob/HEAD:/src/in_netlink.c

-Thomas



More information about the libnl mailing list