diff --git a/glances_api/__init__.py b/glances_api/__init__.py index 9c8ea35..44224c7 100644 --- a/glances_api/__init__.py +++ b/glances_api/__init__.py @@ -135,6 +135,15 @@ async def get_ha_sensor_data(self) -> dict[str, Any] | None: } if data := self.data.get("quicklook"): sensor_data["cpu"] = {"cpu_use_percent": data["cpu"]} + if networks := self.data.get("network"): + sensor_data["network"] = {} + for network in networks: + sensor_data["network"][network["interface_name"]] = { + "is_up": network["is_up"], + "rx": round(network["rx"] / 1024, 1), + "tx": round(network["tx"] / 1024, 1), + "speed": round(network["speed"] / 1024**3, 1), + } if "docker" in self.data and (data := self.data["docker"].get("containers")): active_containers = [ container for container in data if container["Status"] == "running" diff --git a/tests/test_responses.py b/tests/test_responses.py index eb5e2ac..ad1fc26 100644 --- a/tests/test_responses.py +++ b/tests/test_responses.py @@ -105,6 +105,86 @@ "cached": 1334816768, "shared": 1499136, }, + "network": [ + { + "cumulative_cx": 19027046, + "cumulative_rx": 9513523, + "cumulative_tx": 9513523, + "cx": 23770, + "interface_name": "lo", + "is_up": True, + "key": "interface_name", + "rx": 11885, + "speed": 0, + "time_since_update": 1.55433297157288, + "tx": 11885, + }, + { + "cumulative_cx": 0, + "cumulative_rx": 0, + "cumulative_tx": 0, + "cx": 0, + "interface_name": "bond0", + "is_up": False, + "key": "interface_name", + "rx": 0, + "speed": 68718428160, + "time_since_update": 1.55433297157288, + "tx": 0, + }, + { + "cumulative_cx": 0, + "cumulative_rx": 0, + "cumulative_tx": 0, + "cx": 0, + "interface_name": "dummy0", + "is_up": False, + "key": "interface_name", + "rx": 0, + "speed": 0, + "time_since_update": 1.55433297157288, + "tx": 0, + }, + { + "cumulative_cx": 704585, + "cumulative_rx": 518329, + "cumulative_tx": 186256, + "cx": 15463, + "interface_name": "eth0", + "is_up": True, + "key": "interface_name", + "rx": 6144, + "speed": 10485760000, + "time_since_update": 1.55433297157288, + "tx": 9319, + }, + { + "cumulative_cx": 0, + "cumulative_rx": 0, + "cumulative_tx": 0, + "cx": 0, + "interface_name": "tunl0", + "is_up": False, + "key": "interface_name", + "rx": 0, + "speed": 0, + "time_since_update": 1.55433297157288, + "tx": 0, + }, + { + "cumulative_cx": 0, + "cumulative_rx": 0, + "cumulative_tx": 0, + "cx": 0, + "interface_name": "sit0", + "is_up": False, + "key": "interface_name", + "rx": 0, + "speed": 0, + "time_since_update": 1.55433297157288, + "tx": 0, + }, + ], "sensors": [ { "label": "cpu_thermal 1", @@ -138,6 +218,14 @@ "memory_use": 1047.1, "memory_free": 2745.0, }, + "network": { + "lo": {"is_up": True, "rx": 11.6, "tx": 11.6, "speed": 0.0}, + "bond0": {"is_up": False, "rx": 0.0, "tx": 0.0, "speed": 64.0}, + "dummy0": {"is_up": False, "rx": 0.0, "tx": 0.0, "speed": 0.0}, + "eth0": {"is_up": True, "rx": 6.0, "tx": 9.1, "speed": 9.8}, + "tunl0": {"is_up": False, "rx": 0.0, "tx": 0.0, "speed": 0.0}, + "sit0": {"is_up": False, "rx": 0.0, "tx": 0.0, "speed": 0.0}, + }, "docker": {"docker_active": 2, "docker_cpu_use": 77.2, "docker_memory_use": 1149.6}, "uptime": "3 days, 10:25:20", }