From ae41fe8929116bd8616c5b3d09d30cd8c8863cf8 Mon Sep 17 00:00:00 2001 From: Jan Vcelak Date: Tue, 8 Mar 2011 17:27:35 +0100 Subject: [PATCH] net: support new network device naming https://fedoraproject.org/wiki/Features/ConsistentNetworkDeviceNaming Resolves: #682379 --- monitorplugins/net.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/monitorplugins/net.py b/monitorplugins/net.py index 4ce7099..b113661 100644 --- a/monitorplugins/net.py +++ b/monitorplugins/net.py @@ -34,7 +34,7 @@ class NetMonitor: l = l.replace(":", " ") v = l.split() d = v[0] - if not d.startswith("eth"): + if not self._device_is_tunable(d): continue self.devices[d] = {} self.devices[d]["new"] = ['0', '0', '0', '0'] @@ -43,6 +43,16 @@ class NetMonitor: self.__updateStat__(d) self.devices[d]["max"] = [max_speed, 1, max_speed, 1] + def _device_is_tunable(self, name): + # just guess from device name + for prefix in ["eth", "em", "pci"]: + if name.startswith(prefix): break + else: + return False + + card = ethcard(name) + return len(card.supported_modes) > 1 and card.get_max_speed() >= 1000 + def __calcspeed__(self, speed): # 0.6 is just a magical constant (empirical value): Typical workload on netcard won't exceed # that and if it does, then the code is smart enough to adapt it. @@ -92,7 +102,7 @@ class NetMonitor: max_data = self.__calcspeed__(ethcard(d).get_max_speed()) * interval; self.devices[d]["max"] = [max_data, 1, max_data, 1] - log.info("Available ethernet cards: %s" % ", ".join(self.devices.keys())) + log.info("Tunable ethernet cards: %s" % ", ".join(self.devices.keys())) def cleanup(self): log.debug("Cleanup")