Skip to content

Commit 406de5b

Browse files
Humanized byte values in VDEV table
Prompt: In the VDEVs table make the read byes and write bytes show humanized (1K, 1M, 1G) values instead of bytes.
1 parent b52265b commit 406de5b

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/zfs_dashboard/ui/widgets.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from textual.message import Message
66

77
from ..models import Pool, Vdev, Dataset
8+
from ..utils import humanize_bytes
89

910
class PoolOverview(Static):
1011
pool = reactive(None)
@@ -84,8 +85,8 @@ def watch_vdevs(self, vdevs: list[Vdev]):
8485
vdev.type,
8586
str(vdev.read_ops),
8687
str(vdev.write_ops),
87-
str(vdev.read_bytes),
88-
str(vdev.write_bytes)
88+
humanize_bytes(vdev.read_bytes),
89+
humanize_bytes(vdev.write_bytes)
8990
)
9091

9192
class DatasetTreeWidget(Static):

src/zfs_dashboard/utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
def humanize_bytes(value: float) -> str:
2+
"""
3+
Convert a byte count into a human-readable string (e.g., 1K, 1M, 1G).
4+
"""
5+
if value == 0:
6+
return "0B"
7+
8+
suffixes = ['B', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']
9+
i = 0
10+
while value >= 1024 and i < len(suffixes) - 1:
11+
value /= 1024.0
12+
i += 1
13+
14+
return f"{value:.1f}{suffixes[i]}"

0 commit comments

Comments
 (0)