maluk
maluk

Reputation: 147

Linux C++: Accessing network statistics

I am developing a network statistic program in C++ for Linux.

I would like to access some statistical information about the current network connection.

E.g.:

Any idea how to access this kind of information?


so, i have been trying to accomplish my objective using de /proc, we can find alot of information, but there is some missing information i need. I am thinking in developing a simple C++ promiscuous application, using LibPcap, that captures the network traffic i need and starts taking the metrics i want.

The Con is that i think this is going to be CPU intensive, at least more then needed ... Any thoughts about this ?

Upvotes: 7

Views: 7106

Answers (4)

user7732300
user7732300

Reputation:

You can access Network statistics trough /sys/class/net/NAME_OF_DEVICE/statistics.

Upvotes: 1

sylvain.joyeux
sylvain.joyeux

Reputation: 1699

AFAIK, it is possible to retrieve statistics information programmatically through the rtnetlink interface. See e.g. this mail for examples

Upvotes: 1

All this information are spread into /proc/net files (updated by kernel). The most important file is /proc/net/netstat. Into to /proc/net/dev there are device statistics. You could open and parse.

Upvotes: 5

Mike Seymour
Mike Seymour

Reputation: 254461

A lot of information is available from the "files" in /proc/net.

/proc/net/netstat would be a good place to start.

Upvotes: 1

Related Questions