Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collect netns #240

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Collect netns #240

wants to merge 6 commits into from

Conversation

ShirleyFei
Copy link
Contributor

The network devices, like eth2, are settled in another network namespace via ip netns add in some scenarios in the production environment. In this case, we have to switch to that new netns to get network related statistics, e.g. reading from /proc/net/dev, /proc/net/snmp, /proc/net/snmp6.

Add a 'netns' indicator to indicate which netns the network is belong to. And collect statistics for other netns by using setns to switch to another netns to read /proc files, and then use shared memory for parent-child IPC.

Combined with actual needs and performance considerations, this patch only collects other netns's physical network devices stats. Virtual devices are ignored except the 'lo'.

To pass the compiling, also update for atopsar, parsable and json.

Also format some lines according to astyle.

We already get the attibutes of ifprop during getifprop() after
reading /proc/net/dev, thus remove the unnecessary second getter
in deviatsyst().

Signed-off-by: Fei Li <lifei.shirley@bytedance.com>
The network devices, like eth2, are settled in another network
namespace via `ip netns add` in some scenarios in the production
environment. In this case, we have to switch to that new netns
to get network related statistics, e.g. reading from /proc/net/dev,
/proc/net/snmp, /proc/net/snmp6.

This patch firstly adds the needed attributes, like 'netns', for
collecting and displaying network namespace statistics. Then the
following patches will do the real implementation.

To pass the compiling, also update for atopsar, parsable and json.

Also format some lines according to astyle.

Signed-off-by: Fei Li <lifei.shirley@bytedance.com>
Signed-off-by: Fei Li <lifei.shirley@bytedance.com>
For linux kernel, it exposes almost 100 lines for /proc/net/snmp6
file. Considering multiple-netns situations, too many lines had to
be read and transferred, which is quite time consuming and space
consuming.

Let's optimize this by adding 'idx' to mark the needed indicators'
position in struct v6tab. During the first time reading, e.i. the
init_net namespace, we record the positions. Then in the following
other netns, we only need to store and transfer indicators' values
according to their positions.

Signed-off-by: Fei Li <lifei.shirley@bytedance.com>
This patch implements how to collect statistics for other netns
by using `setns` to switch to another netns to read /proc files,
and then use shared memory for parent-child IPC.

Combined with actual needs and performance considerations, this
patch only collects other netns's physical network devices stats.
Virtual devices are ignored except the 'lo'.

Signed-off-by: Fei Li <lifei.shirley@bytedance.com>
The default rule is splitting netns by blank space.
And make sure the netns path exits.

Signed-off-by: Fei Li <lifei.shirley@bytedance.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant