vostok / metrics.system

Cross-platform system metrics collection for .NET Core applications.
MIT License
3 stars 2 forks source link

Linux network metrics with team interfaces #7

Closed HolyPrapor closed 3 years ago

HolyPrapor commented 3 years ago

Because of the old kernel version getting team interface bandwidth on CentOS fails.

The task is to handle different teaming modes and calculate bandwidth accordingly.

https://kontur.slack.com/archives/CE3EZ7924/p1612180262246400

HolyPrapor commented 3 years ago

According to official documentation, we can look at the source code there.

After analyzing source code files, we can conclude, that current teaming mode can be obtained in /run/teamd/<iface>.conf. There lies JSON configuration file.

Teaming ports can be gathered either looking at /sys/class/net/<iface>/lower_<port iface> directories, or traversing /sys/class/net/<iface> directories and looking at their master.

Perhaps, there might be other sources of information.

There are 6 cases to handle:

HolyPrapor commented 3 years ago

Previous comment did not take into consideration two things:

  1. Teaming ports may be created in many ways. It means that /sys/class/net/<iface>/lower_<port iface> and /sys/class/net/<iface>/master may not exist.
  2. .conf files may contain obsolete information.

This leads us to the conclusion that actual state may be obtained only through teamlib calls.

For better understanding I suggest reading this specification first.

We can extract needed info (teaming mode and slave-ports) using StateDump method. It's implementation is located there.

It requires teamdctl context, which should be prepared. We can find teamdctl struct there.

1) Allocation 2) Connection to needed port

There are also:

It should be possible to get all needed methods from libteamdctl.so.0 library.

HolyPrapor commented 3 years ago

I managed to retreive actual JSON configuration of interface using method described above, but I faced two issues:

  1. Data returned in JSON, which needs to be parsed.
  2. I did not manage to retreive needed data without sudo

There is a chance that teamdctl address can be retreived somewhere and then used to connect to the Netlink Socket (to communicate with driver). If it's true, then we will be able to retreive needed data without sudo. Worth investigating

HolyPrapor commented 3 years ago

Unfortunately we are unable to retreive needed data without sudo. Now this is a requirement to collect full host metrics on Linux.

We can use teamdctl team0 state item get setup.runner_name to get current teaming mode.

To retreive ports we can use teamdctl team0 state dump (JSON).