diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index 234df4b68..a73f22d30 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -206,6 +206,9 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* #ifdef HAVE_LIBHWLOC Panel_add(super, (Object*) CheckItem_newByRef("Show topology when selecting affinity by default", &(settings->topologyAffinity))); #endif + #ifdef IGNORE_VIRTUAL_INTF + Panel_add(super, (Object*) CheckItem_newByRef("Ignore virtual network interfaces to count rx and tx values", &(settings->ignoreVirtualNetworkInterfaces))); + #endif return this; } diff --git a/NetworkIOMeter.c b/NetworkIOMeter.c index 784c90ac3..7b22d5e2c 100644 --- a/NetworkIOMeter.c +++ b/NetworkIOMeter.c @@ -45,7 +45,11 @@ static void NetworkIOMeter_updateValues(Meter* this) { /* update only every 500ms to have a sane span for rate calculation */ if (passedTimeInMs > 500) { +#ifdef IGNORE_VIRTUAL_INTF + hasNewData = Platform_getNetworkIO(&data, host->settings->ignoreVirtualNetworkInterfaces); +#else hasNewData = Platform_getNetworkIO(&data); +#endif if (!hasNewData) { status = RATESTATUS_NODATA; } else if (cached_last_update == 0) { diff --git a/Settings.h b/Settings.h index 01e808e86..a52ae385a 100644 --- a/Settings.h +++ b/Settings.h @@ -112,6 +112,9 @@ typedef struct Settings_ { bool changed; uint64_t lastUpdate; +#ifdef IGNORE_VIRTUAL_INTF + bool ignoreVirtualNetworkInterfaces; +#endif } Settings; #define Settings_cpuId(settings, cpu) ((settings)->countCPUsFromOne ? (cpu)+1 : (cpu)) diff --git a/configure.ac b/configure.ac index 6d7752add..a84e780c5 100644 --- a/configure.ac +++ b/configure.ac @@ -1175,6 +1175,16 @@ if test "$enable_sensors" = yes || test "$my_htop_platform" = freebsd; then AC_DEFINE([BUILD_WITH_CPU_TEMP], [1], [Define if CPU temperature option should be enabled.]) fi +AC_ARG_ENABLE([ignore-virtual-intf], + [AS_HELP_STRING([--enable-ignore-virtual-intf], + [Ignore virtual network interfaces in NetworkIO meter [default=no]])], + [enable_ignore_virtual_intf=yes], + [enable_ignore_virtual_intf=no]) + +if test "x$enable_ignore_virtual_intf" = "xyes"; then + AC_DEFINE([IGNORE_VIRTUAL_INTF], [1], [Ignore virtual network interfaces]) +fi + # ---------------------------------------------------------------------- diff --git a/linux/Platform.c b/linux/Platform.c index ddaf1324d..4bc40d442 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -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); +} +#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; diff --git a/linux/Platform.h b/linux/Platform.h index 9867bb13e..71e30e0b7 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -85,8 +85,11 @@ void Platform_getPressureStall(const char* file, bool some, double* ten, double* void Platform_getFileDescriptors(double* used, double* max); bool Platform_getDiskIO(DiskIOData* data); - +#ifdef IGNORE_VIRTUAL_INTF +bool Platform_getNetworkIO(NetworkIOData* data, bool ignoreVirtual); +#else bool Platform_getNetworkIO(NetworkIOData* data); +#endif void Platform_getBattery(double* percent, ACPresence* isOnAC);