Skip to content

Commit b44163a

Browse files
author
Dominik
authored
Add network information to ha data (#17)
1 parent ef37ba5 commit b44163a

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

glances_api/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,15 @@ async def get_ha_sensor_data(self) -> dict[str, Any] | None:
135135
}
136136
if data := self.data.get("quicklook"):
137137
sensor_data["cpu"] = {"cpu_use_percent": data["cpu"]}
138+
if networks := self.data.get("network"):
139+
sensor_data["network"] = {}
140+
for network in networks:
141+
sensor_data["network"][network["interface_name"]] = {
142+
"is_up": network["is_up"],
143+
"rx": round(network["rx"] / 1024, 1),
144+
"tx": round(network["tx"] / 1024, 1),
145+
"speed": round(network["speed"] / 1024**3, 1),
146+
}
138147
if "docker" in self.data and (data := self.data["docker"].get("containers")):
139148
active_containers = [
140149
container for container in data if container["Status"] == "running"

tests/test_responses.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,86 @@
105105
"cached": 1334816768,
106106
"shared": 1499136,
107107
},
108+
"network": [
109+
{
110+
"cumulative_cx": 19027046,
111+
"cumulative_rx": 9513523,
112+
"cumulative_tx": 9513523,
113+
"cx": 23770,
114+
"interface_name": "lo",
115+
"is_up": True,
116+
"key": "interface_name",
117+
"rx": 11885,
118+
"speed": 0,
119+
"time_since_update": 1.55433297157288,
120+
"tx": 11885,
121+
},
122+
{
123+
"cumulative_cx": 0,
124+
"cumulative_rx": 0,
125+
"cumulative_tx": 0,
126+
"cx": 0,
127+
"interface_name": "bond0",
128+
"is_up": False,
129+
"key": "interface_name",
130+
"rx": 0,
131+
"speed": 68718428160,
132+
"time_since_update": 1.55433297157288,
133+
"tx": 0,
134+
},
135+
{
136+
"cumulative_cx": 0,
137+
"cumulative_rx": 0,
138+
"cumulative_tx": 0,
139+
"cx": 0,
140+
"interface_name": "dummy0",
141+
"is_up": False,
142+
"key": "interface_name",
143+
"rx": 0,
144+
"speed": 0,
145+
"time_since_update": 1.55433297157288,
146+
"tx": 0,
147+
},
148+
{
149+
"cumulative_cx": 704585,
150+
"cumulative_rx": 518329,
151+
"cumulative_tx": 186256,
152+
"cx": 15463,
153+
"interface_name": "eth0",
154+
"is_up": True,
155+
"key": "interface_name",
156+
"rx": 6144,
157+
"speed": 10485760000,
158+
"time_since_update": 1.55433297157288,
159+
"tx": 9319,
160+
},
161+
{
162+
"cumulative_cx": 0,
163+
"cumulative_rx": 0,
164+
"cumulative_tx": 0,
165+
"cx": 0,
166+
"interface_name": "tunl0",
167+
"is_up": False,
168+
"key": "interface_name",
169+
"rx": 0,
170+
"speed": 0,
171+
"time_since_update": 1.55433297157288,
172+
"tx": 0,
173+
},
174+
{
175+
"cumulative_cx": 0,
176+
"cumulative_rx": 0,
177+
"cumulative_tx": 0,
178+
"cx": 0,
179+
"interface_name": "sit0",
180+
"is_up": False,
181+
"key": "interface_name",
182+
"rx": 0,
183+
"speed": 0,
184+
"time_since_update": 1.55433297157288,
185+
"tx": 0,
186+
},
187+
],
108188
"sensors": [
109189
{
110190
"label": "cpu_thermal 1",
@@ -138,6 +218,14 @@
138218
"memory_use": 1047.1,
139219
"memory_free": 2745.0,
140220
},
221+
"network": {
222+
"lo": {"is_up": True, "rx": 11.6, "tx": 11.6, "speed": 0.0},
223+
"bond0": {"is_up": False, "rx": 0.0, "tx": 0.0, "speed": 64.0},
224+
"dummy0": {"is_up": False, "rx": 0.0, "tx": 0.0, "speed": 0.0},
225+
"eth0": {"is_up": True, "rx": 6.0, "tx": 9.1, "speed": 9.8},
226+
"tunl0": {"is_up": False, "rx": 0.0, "tx": 0.0, "speed": 0.0},
227+
"sit0": {"is_up": False, "rx": 0.0, "tx": 0.0, "speed": 0.0},
228+
},
141229
"docker": {"docker_active": 2, "docker_cpu_use": 77.2, "docker_memory_use": 1149.6},
142230
"uptime": "3 days, 10:25:20",
143231
}

0 commit comments

Comments
 (0)