glances_api 0.7.0__tar.gz → 0.8.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {glances_api-0.7.0 → glances_api-0.8.0}/PKG-INFO +1 -1
- {glances_api-0.7.0 → glances_api-0.8.0}/glances_api/__init__.py +25 -12
- {glances_api-0.7.0 → glances_api-0.8.0}/pyproject.toml +1 -1
- {glances_api-0.7.0 → glances_api-0.8.0}/LICENSE +0 -0
- {glances_api-0.7.0 → glances_api-0.8.0}/README.rst +0 -0
- {glances_api-0.7.0 → glances_api-0.8.0}/glances_api/exceptions.py +0 -0
|
@@ -41,6 +41,7 @@ class Glances:
|
|
|
41
41
|
self.password = password
|
|
42
42
|
self.verify_ssl = verify_ssl
|
|
43
43
|
self.httpx_client = httpx_client
|
|
44
|
+
self.version = version
|
|
44
45
|
|
|
45
46
|
async def get_data(self, endpoint: str) -> None:
|
|
46
47
|
"""Retrieve the data."""
|
|
@@ -154,27 +155,39 @@ class Glances:
|
|
|
154
155
|
if networks := self.data.get("network"):
|
|
155
156
|
sensor_data["network"] = {}
|
|
156
157
|
for network in networks:
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
158
|
+
rx = tx = None
|
|
159
|
+
if self.version <= 3:
|
|
160
|
+
time_since_update = network["time_since_update"]
|
|
161
|
+
if (rx_bytes := network.get("rx")) is not None:
|
|
162
|
+
rx = round(rx_bytes / time_since_update)
|
|
163
|
+
if (tx_bytes := network.get("tx")) is not None:
|
|
164
|
+
tx = round(tx_bytes / time_since_update)
|
|
165
|
+
else:
|
|
166
|
+
# New network sensors in Glances v4
|
|
167
|
+
rx = network.get("bytes_recv_rate_per_sec")
|
|
168
|
+
tx = network.get("bytes_sent_rate_per_sec")
|
|
166
169
|
sensor_data["network"][network["interface_name"]] = {
|
|
167
170
|
"is_up": network.get("is_up"),
|
|
168
171
|
"rx": rx,
|
|
169
172
|
"tx": tx,
|
|
170
173
|
"speed": round(network["speed"] / 1024**3, 1),
|
|
171
174
|
}
|
|
172
|
-
|
|
173
|
-
if
|
|
175
|
+
containers_data = None
|
|
176
|
+
if self.version <= 3:
|
|
177
|
+
# Glances v3 and earlier provide a dict, with containers inside a list in this dict
|
|
178
|
+
# Key is "dockers" in 3.3 and before, and "containers" in 3.4
|
|
179
|
+
data = self.data.get("dockers") or self.data.get("containers")
|
|
180
|
+
containers_data = data.get("containers") if data else None
|
|
181
|
+
else:
|
|
182
|
+
# Glances v4 provides a list of containers
|
|
183
|
+
containers_data = self.data.get("containers")
|
|
184
|
+
if containers_data:
|
|
174
185
|
active_containers = [
|
|
175
186
|
container
|
|
176
187
|
for container in containers_data
|
|
177
|
-
|
|
188
|
+
# "status" since Glance v4, "Status" in v3 and earlier
|
|
189
|
+
if container.get("status") == "running"
|
|
190
|
+
or container.get("Status") == "running"
|
|
178
191
|
]
|
|
179
192
|
sensor_data["docker"] = {"docker_active": len(active_containers)}
|
|
180
193
|
cpu_use = 0.0
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "glances_api"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.8.0"
|
|
4
4
|
description = "Python API for interacting with Glances"
|
|
5
5
|
authors = ["Fabian Affolter <fabian@affolter-engineering.ch>"]
|
|
6
6
|
homepage = "https://github.com/home-assistant-ecosystem/python-glances-api"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|