Skip to content

Commit

Permalink
Add network information to ha data (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
freeDom- authored Jun 27, 2023
1 parent ef37ba5 commit b44163a
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
9 changes: 9 additions & 0 deletions glances_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
88 changes: 88 additions & 0 deletions tests/test_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
}
Expand Down

0 comments on commit b44163a

Please sign in to comment.