Keeping the old disk maximum read/write rate so the progress bars mean something.

This commit is contained in:
Roland 2023-09-07 13:02:38 -06:00
parent aeda5bfa44
commit b765f2e440
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
3 changed files with 26 additions and 8 deletions

View file

@ -21,7 +21,8 @@ function DriveInfo({used, size, percent, mount}) {
}
function DiskBandwidthProgress({bytes_ps, total, label, ...props}) {
let percent = bytes_ps / total;
// Calculate percent so colors can be shown.
let percent = (bytes_ps / total) * 100;
percent = percent || 0;
let color = null;
if (percent >= 90) {
@ -35,19 +36,17 @@ function DiskBandwidthProgress({bytes_ps, total, label, ...props}) {
return <Progress percent={percent} label={label} color={color} key={label} {...props}/>;
}
function DiskBandwidth({name, bytes_read_ps, bytes_write_ps}) {
const total = 10_000_000; // Arbitrary size. What is the real speed of the disk?
function DiskBandwidth({name, bytes_read_ps, bytes_write_ps, maximum_read_ps, maximum_write_ps}) {
const read = <DiskBandwidthProgress
bytes_ps={bytes_read_ps}
total={total}
total={maximum_read_ps}
label={`${name} read`}
size='tiny'
disabled={bytes_read_ps === 0}
/>;
const write = <DiskBandwidthProgress
bytes_ps={bytes_write_ps}
total={total}
total={maximum_write_ps}
label={`${name} write`}
size='tiny'
disabled={bytes_write_ps === 0}

View file

@ -355,6 +355,8 @@ class DiskBandwidthInfo:
bytes_write_ps: int = None
elapsed: int = None
name: str = None
maximum_read_ps: int = None
maximum_write_ps: int = None
def __json__(self):
return dict(
@ -362,6 +364,8 @@ class DiskBandwidthInfo:
bytes_write_ps=self.bytes_write_ps,
elapsed=self.elapsed,
name=self.name,
maximum_read_ps=self.maximum_read_ps,
maximum_write_ps=self.maximum_write_ps,
)
@ -370,12 +374,14 @@ IGNORED_DISK_NAMES = (
'ram',
)
DISKS_BANDWIDTH = multiprocessing.Manager().dict()
MAX_DISKS_BANDWIDTH = multiprocessing.Manager().dict()
async def get_bandwidth_info() -> Tuple[List[NICBandwidthInfo], List[DiskBandwidthInfo]]:
"""Get all bandwidth information for all NICs."""
"""Get all bandwidth information for all NICs and Disks."""
nics_info = []
disks_info = []
try:
for name in sorted(BANDWIDTH.keys()):
nic = BANDWIDTH[name]
@ -402,11 +408,25 @@ async def get_bandwidth_info() -> Tuple[List[NICBandwidthInfo], List[DiskBandwid
if any(name.startswith(i) for i in IGNORED_DISK_NAMES):
continue
used_disks.append(name)
try:
maximum_read_ps = max(disk['bytes_read_ps'], MAX_DISKS_BANDWIDTH[name]['maximum_read_ps'])
maximum_write_ps = max(disk['bytes_write_ps'], MAX_DISKS_BANDWIDTH[name]['maximum_write_ps'])
except KeyError as e:
# Use a low first value. Hopefully all drives are capable of this speed.
maximum_read_ps = 500_000
maximum_write_ps = 500_000
# Always write the new maximums.
value = {name: {'maximum_read_ps': maximum_read_ps, 'maximum_write_ps': maximum_write_ps}}
MAX_DISKS_BANDWIDTH.update(value)
disks_info.append(DiskBandwidthInfo(
bytes_read_ps=disk['bytes_read_ps'],
bytes_write_ps=disk['bytes_write_ps'],
elapsed=disk['elapsed'],
name=name,
maximum_read_ps=maximum_read_ps,
maximum_write_ps=maximum_write_ps,
))
except Exception as e:
warn_once(e)

View file

@ -33,7 +33,6 @@ async def test_get_cpu_info():
info = await status.get_cpu_info()
assert isinstance(info, status.CPUInfo)
assert isinstance(info.percent, int)
assert info.temperature >= 0
@pytest.mark.asyncio