glances_api 0.7.0__tar.gz → 0.9.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.9.0}/PKG-INFO +2 -1
- {glances_api-0.7.0 → glances_api-0.9.0}/glances_api/__init__.py +36 -14
- {glances_api-0.7.0 → glances_api-0.9.0}/pyproject.toml +1 -1
- {glances_api-0.7.0 → glances_api-0.9.0}/LICENSE +0 -0
- {glances_api-0.7.0 → glances_api-0.9.0}/README.rst +0 -0
- {glances_api-0.7.0 → glances_api-0.9.0}/glances_api/exceptions.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: glances_api
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.9.0
|
|
4
4
|
Summary: Python API for interacting with Glances
|
|
5
5
|
Home-page: https://github.com/home-assistant-ecosystem/python-glances-api
|
|
6
6
|
License: MIT
|
|
@@ -17,6 +17,7 @@ Classifier: Operating System :: POSIX
|
|
|
17
17
|
Classifier: Programming Language :: Python :: 3
|
|
18
18
|
Classifier: Programming Language :: Python :: 3.11
|
|
19
19
|
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
21
|
Classifier: Topic :: Utilities
|
|
21
22
|
Requires-Dist: httpx (>=0.23,<1)
|
|
22
23
|
Project-URL: Repository, https://github.com/home-assistant-ecosystem/python-glances-api/releases
|
|
@@ -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."""
|
|
@@ -133,8 +134,9 @@ class Glances:
|
|
|
133
134
|
}
|
|
134
135
|
if data := self.data.get("load"):
|
|
135
136
|
sensor_data["load"] = {
|
|
136
|
-
"processor_load": data.get("min15")
|
|
137
|
-
|
|
137
|
+
"processor_load": data.get("min15"),
|
|
138
|
+
"processor_load_1m": data.get("min1"),
|
|
139
|
+
"processor_load_5m": data.get("min5"),
|
|
138
140
|
}
|
|
139
141
|
if data := self.data.get("processcount"):
|
|
140
142
|
sensor_data["processcount"] = {
|
|
@@ -154,27 +156,40 @@ class Glances:
|
|
|
154
156
|
if networks := self.data.get("network"):
|
|
155
157
|
sensor_data["network"] = {}
|
|
156
158
|
for network in networks:
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
159
|
+
rx = tx = None
|
|
160
|
+
if self.version <= 3:
|
|
161
|
+
time_since_update = network["time_since_update"]
|
|
162
|
+
if (rx_bytes := network.get("rx")) is not None:
|
|
163
|
+
rx = round(rx_bytes / time_since_update)
|
|
164
|
+
if (tx_bytes := network.get("tx")) is not None:
|
|
165
|
+
tx = round(tx_bytes / time_since_update)
|
|
166
|
+
else:
|
|
167
|
+
# New network sensors in Glances v4
|
|
168
|
+
rx = network.get("bytes_recv_rate_per_sec")
|
|
169
|
+
tx = network.get("bytes_sent_rate_per_sec")
|
|
166
170
|
sensor_data["network"][network["interface_name"]] = {
|
|
167
171
|
"is_up": network.get("is_up"),
|
|
168
172
|
"rx": rx,
|
|
169
173
|
"tx": tx,
|
|
170
174
|
"speed": round(network["speed"] / 1024**3, 1),
|
|
171
175
|
}
|
|
172
|
-
|
|
173
|
-
if
|
|
176
|
+
containers_data = None
|
|
177
|
+
if self.version <= 3:
|
|
178
|
+
# Glances v3 and earlier provide a dict, with containers inside a list in this dict
|
|
179
|
+
# Key is "dockers" in 3.3 and before, and "containers" in 3.4
|
|
180
|
+
data = self.data.get("dockers") or self.data.get("containers")
|
|
181
|
+
containers_data = data.get("containers") if data else None
|
|
182
|
+
else:
|
|
183
|
+
# Glances v4 provides a list of containers
|
|
184
|
+
containers_data = self.data.get("containers")
|
|
185
|
+
if containers_data:
|
|
186
|
+
sensor_data["containers"] = {}
|
|
174
187
|
active_containers = [
|
|
175
188
|
container
|
|
176
189
|
for container in containers_data
|
|
177
|
-
|
|
190
|
+
# "status" since Glance v4, "Status" in v3 and earlier
|
|
191
|
+
if container.get("status") == "running"
|
|
192
|
+
or container.get("Status") == "running"
|
|
178
193
|
]
|
|
179
194
|
sensor_data["docker"] = {"docker_active": len(active_containers)}
|
|
180
195
|
cpu_use = 0.0
|
|
@@ -185,6 +200,13 @@ class Glances:
|
|
|
185
200
|
for container in active_containers:
|
|
186
201
|
mem_use += container["memory"].get("usage", 0)
|
|
187
202
|
sensor_data["docker"]["docker_memory_use"] = round(mem_use / 1024**2, 1)
|
|
203
|
+
for container in active_containers:
|
|
204
|
+
sensor_data["containers"][container["name"]] = {
|
|
205
|
+
"container_cpu_use": round(container["cpu"].get("total", 0), 1),
|
|
206
|
+
"container_memory_use": round(
|
|
207
|
+
container["memory"].get("usage", 0) / 1024**2, 1
|
|
208
|
+
),
|
|
209
|
+
}
|
|
188
210
|
if data := self.data.get("raid"):
|
|
189
211
|
sensor_data["raid"] = data
|
|
190
212
|
if data := self.data.get("uptime"):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "glances_api"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.9.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
|