Fix systemmonitor IP address look-up logic (#48740)
This commit is contained in:
parent
fb1444c414
commit
030e9d314d
1 changed files with 7 additions and 1 deletions
|
@ -262,6 +262,7 @@ async def async_setup_sensor_registry_updates(
|
|||
_swap_memory.cache_clear()
|
||||
_virtual_memory.cache_clear()
|
||||
_net_io_counters.cache_clear()
|
||||
_net_if_addrs.cache_clear()
|
||||
_getloadavg.cache_clear()
|
||||
|
||||
async def _async_update_data(*_: Any) -> None:
|
||||
|
@ -439,7 +440,7 @@ def _update(
|
|||
else:
|
||||
state = None
|
||||
elif type_ in ["ipv4_address", "ipv6_address"]:
|
||||
addresses = _net_io_counters()
|
||||
addresses = _net_if_addrs()
|
||||
if data.argument in addresses:
|
||||
for addr in addresses[data.argument]:
|
||||
if addr.family == IF_ADDRS_FAMILY[type_]:
|
||||
|
@ -484,6 +485,11 @@ def _net_io_counters() -> Any:
|
|||
return psutil.net_io_counters(pernic=True)
|
||||
|
||||
|
||||
@lru_cache(maxsize=None)
|
||||
def _net_if_addrs() -> Any:
|
||||
return psutil.net_if_addrs()
|
||||
|
||||
|
||||
@lru_cache(maxsize=None)
|
||||
def _getloadavg() -> tuple[float, float, float]:
|
||||
return os.getloadavg()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue