Skip to content

Commit

Permalink
Add diskio sensors for Home Assistant (in bytes/second) (#37)
Browse files Browse the repository at this point in the history
* Add diskio sensors for Home Assistant (in bytes/second)

* Fix merge issue

---------

Co-authored-by: Fabian Affolter <fabian@affolter-engineering.ch>
Co-authored-by: Fabian Affolter <mail@fabian-affolter.ch>
  • Loading branch information
3 people committed Apr 4, 2024
1 parent 40aae46 commit 335258d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
9 changes: 9 additions & 0 deletions glances_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Client to interact with the Glances API."""

from __future__ import annotations

import logging
Expand Down Expand Up @@ -189,4 +190,12 @@ async def get_ha_sensor_data(self) -> dict[str, Any]:
"proc": sensor.get("proc", 0),
"fan_speed": sensor.get("fan_speed", 0),
}
if data := self.data.get("diskio"):
sensor_data["diskio"] = {}
for disk in data:
time_since_update = disk["time_since_update"]
sensor_data["diskio"][disk["disk_name"]] = {
"read": round(disk["read_bytes"] / time_since_update),
"write": round(disk["write_bytes"] / time_since_update),
}
return sensor_data
13 changes: 13 additions & 0 deletions tests/test_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@
"write_bytes": 23863296,
"key": "disk_name",
},
{
"time_since_update": 142.23511338233948,
"disk_name": "sda",
"read_count": 34,
"write_count": 254,
"read_bytes": 548864,
"write_bytes": 3691520,
"key": "disk_name",
},
],
"containers": {
"version": {},
Expand Down Expand Up @@ -287,6 +296,10 @@
"docker": {"docker_active": 2, "docker_cpu_use": 77.2, "docker_memory_use": 1149.6},
"uptime": "3 days, 10:25:20",
"percpu": {"0": {"cpu_use_percent": 22.1}, "1": {"cpu_use_percent": 17.2}},
"diskio": {
"nvme0n1": {"read": 184320, "write": 23863296},
"sda": {"read": 3859, "write": 25954},
},
"gpu": {
"NVIDIA GeForce RTX 4080 (GPU 0)": {
"mem": 13.333489176233513,
Expand Down

1 comment on commit 335258d

@wittypluck
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank you @fabaff !

Please sign in to comment.