6

I would like to get the NIC driver 64bit statistics in userspace, in the simplest way possible. The man page of API function getifaddrs(), suggests a simple example program that does it using 32bit "struct rtnl_link_stats" (possible to see it here for example: http://man7.org/linux/man-pages/man3/getifaddrs.3.html).

The problem with this struct is obvious: the 32bit variables wrap-around (exceed 2^32) quickly (e.g. "rx_bytes").

In the same header file (linux/if_link.h) that contains struct rtnl_link_stats, there is a similar struct with 64bit variables: struct rtnl_link_stats64. I was sure that I'm very close to have the same statistics on 64bit variables, but unfortunately, I failed doing so.

There are functions like dev_get_stats(), but they are all written for kernel-space.

Programs like "ethtool -S" show these statistics in 64bit values, but I think they do some manipulation and not fill up struct rtnl_link_stats64 in a simple way.

Reading directly from /sys/class/net/ethX/statistics/rx_bytes (using fopen, fscanf...) is ok, but it doesn't perform as good as reading using API.

Is there a simple way in userspace to have struct rtnl_link_stats64 filled with the relevant statistics, that I miss?

Stefan Zobel
  • 3,182
  • 7
  • 28
  • 38

1 Answers1

2

Apparently, the best (performance wise) way I found is using netlink APIs from library libnl.

Here is a link to a simple example program that I found, that implements it: https://gist.github.com/beejeebus/cc4fb07472cf5a0afd41