Skip to content

Commit 335258d

Browse files
wittypluckfabaff
andauthored
Add diskio sensors for Home Assistant (in bytes/second) (#37)
* Add diskio sensors for Home Assistant (in bytes/second) * Fix merge issue --------- Co-authored-by: Fabian Affolter <[email protected]> Co-authored-by: Fabian Affolter <[email protected]>
1 parent 40aae46 commit 335258d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

glances_api/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Client to interact with the Glances API."""
2+
23
from __future__ import annotations
34

45
import logging
@@ -189,4 +190,12 @@ async def get_ha_sensor_data(self) -> dict[str, Any]:
189190
"proc": sensor.get("proc", 0),
190191
"fan_speed": sensor.get("fan_speed", 0),
191192
}
193+
if data := self.data.get("diskio"):
194+
sensor_data["diskio"] = {}
195+
for disk in data:
196+
time_since_update = disk["time_since_update"]
197+
sensor_data["diskio"][disk["disk_name"]] = {
198+
"read": round(disk["read_bytes"] / time_since_update),
199+
"write": round(disk["write_bytes"] / time_since_update),
200+
}
192201
return sensor_data

tests/test_responses.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@
7272
"write_bytes": 23863296,
7373
"key": "disk_name",
7474
},
75+
{
76+
"time_since_update": 142.23511338233948,
77+
"disk_name": "sda",
78+
"read_count": 34,
79+
"write_count": 254,
80+
"read_bytes": 548864,
81+
"write_bytes": 3691520,
82+
"key": "disk_name",
83+
},
7584
],
7685
"containers": {
7786
"version": {},
@@ -287,6 +296,10 @@
287296
"docker": {"docker_active": 2, "docker_cpu_use": 77.2, "docker_memory_use": 1149.6},
288297
"uptime": "3 days, 10:25:20",
289298
"percpu": {"0": {"cpu_use_percent": 22.1}, "1": {"cpu_use_percent": 17.2}},
299+
"diskio": {
300+
"nvme0n1": {"read": 184320, "write": 23863296},
301+
"sda": {"read": 3859, "write": 25954},
302+
},
290303
"gpu": {
291304
"NVIDIA GeForce RTX 4080 (GPU 0)": {
292305
"mem": 13.333489176233513,

0 commit comments

Comments
 (0)