-
-
Notifications
You must be signed in to change notification settings - Fork 530
Ignore virtual interfaces for network IO accounting #1746
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
base: main
Are you sure you want to change the base?
Changes from all commits
c30fcaf
bf6991a
715c1d8
e10e2b3
dbe13b3
ec2063f
62eff09
22fc673
0005bbd
8271c37
9921689
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -209,6 +209,14 @@ void Platform_setBindings(Htop_Action* keys) { | |
| keys[KEY_F(20)] = Platform_actionHigherAutogroupPriority; // Shift-F8 | ||
| } | ||
|
|
||
| static bool Platform_isVirtualNetworkInterface(const char* name) { | ||
| char path[PATH_MAX]; | ||
|
|
||
| // Since kerel 2.6.13 virtual interfaces are listed in /sys/devices/virtual/net | ||
| xSnprintf(path, sizeof(path), "/sys/devices/virtual/net/%s", name); | ||
| return access(path, F_OK) == 0; | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This list is quite incomplete, and IMO hard-coding it like this is not ideal. I imagine the BSDs and other platforms may have a similar requirement. The solution we use in pcp.io is to have an interfaces.conf configuration file (optionally, somewhere below /etc) that provides a regular expression - if interfaces match, they are culled from the calculation. This is platform agnostic - different platforms could have different config files - and indeed different sites may have their own naming conventions, custom drivers, etc. This is the current regex we're using: Using a similar approach to this could simplify and improve this PR. Can do away with all the configure.ac/ifdef changes as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, instead of relying on the name of the interface, using the interface type can help simplify things even more. Otherwise you risk breaking things depending on some settings (e.g. systemd's unusable names vs. the good ones like eth0) … |
||
|
|
||
| const MeterClass* const Platform_meterTypes[] = { | ||
| &CPUMeter_class, | ||
| &ClockMeter_class, | ||
|
|
@@ -712,7 +720,9 @@ bool Platform_getNetworkIO(NetworkIOData* data) { | |
| &packetsTransmitted) != 5) | ||
| continue; | ||
|
|
||
| if (String_eq(interfaceName, "lo:")) | ||
| if (String_eq(interfaceName, "lo:") || // Loopback must be always ignored | ||
| (data->ignoreVirtualIntf && Platform_isVirtualNetworkInterface(interfaceName)) | ||
| ) | ||
| continue; | ||
|
|
||
| data->bytesReceived += bytesReceived; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.