-
-
Notifications
You must be signed in to change notification settings - Fork 520
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
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 | ||
} | ||
|
||
#ifdef IGNORE_VIRTUAL_INTF | ||
static bool Platform_isVirtualNetworkInterface(const char* name) { | ||
return (strncmp(name, "docker", 6) == 0 || strncmp(name, "veth", 4) == 0 || | ||
strncmp(name, "virbr", 5) == 0 || strncmp(name, "tun", 3) == 0 || | ||
strncmp(name, "tap", 3) == 0 || strncmp(name, "vboxnet", 7) == 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) … |
||
#endif | ||
|
||
const MeterClass* const Platform_meterTypes[] = { | ||
&CPUMeter_class, | ||
&ClockMeter_class, | ||
|
@@ -695,7 +703,11 @@ bool Platform_getDiskIO(DiskIOData* data) { | |
return true; | ||
} | ||
|
||
#ifdef IGNORE_VIRTUAL_INTF | ||
bool Platform_getNetworkIO(NetworkIOData* data, bool ignoreVirtual) { | ||
#else | ||
bool Platform_getNetworkIO(NetworkIOData* data) { | ||
#endif | ||
FILE* fp = fopen(PROCDIR "/net/dev", "r"); | ||
if (!fp) | ||
return false; | ||
|
@@ -712,7 +724,11 @@ bool Platform_getNetworkIO(NetworkIOData* data) { | |
&packetsTransmitted) != 5) | ||
continue; | ||
|
||
if (String_eq(interfaceName, "lo:")) | ||
if (String_eq(interfaceName, "lo:") | ||
#ifdef IGNORE_VIRTUAL_INTF | ||
|| (ignoreVirtual == true && Platform_isVirtualNetworkInterface(interfaceName)) | ||
#endif | ||
) | ||
continue; | ||
|
||
data->bytesReceived += bytesReceived; | ||
|
Uh oh!
There was an error while loading. Please reload this page.
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.
I don't like two kinds of function prototypes that depend on a compile time option. Even though the code can compile, the braces are unbalanced and would very likely confuse IDEs.
Another point is, you might not need to pass the boolean setting as a function argument. I suggest making it a member of the
NetworkIOData
(bool ignoreVirtualInterfaces;
), and letNetworkIOMeter_updateValues
set it before callingPlatform_getNetworkIO
.