opt.: disk size (#252)

This commit is contained in:
lollipopkit
2024-01-21 18:01:11 +08:00
parent 362dcdf288
commit 50d6ed919b
11 changed files with 42 additions and 32 deletions

View File

@@ -7,9 +7,9 @@ class Disk {
final String dev;
final String mount;
final int usedPercent;
final String used;
final String size;
final String avail;
final BigInt used;
final BigInt size;
final BigInt avail;
const Disk({
required this.dev,
@@ -20,6 +20,12 @@ class Disk {
required this.avail,
});
/// raw:
/// ```
/// Filesystem 1K-blocks Used Available Use% Mounted on
/// overlay 959122528 154470540 755857572 17% /
/// tmpfs 65536 0 65536 0% /dev
/// ```
static List<Disk> parse(String raw) {
final list = <Disk>[];
final items = raw.split('\n');
@@ -43,9 +49,9 @@ class Disk {
dev: vals[0],
mount: vals[5],
usedPercent: int.parse(vals[4].replaceFirst('%', '')),
used: vals[2],
size: vals[1],
avail: vals[3],
used: BigInt.tryParse(vals[2]) ?? BigInt.zero,
size: BigInt.tryParse(vals[1]) ?? BigInt.one,
avail: BigInt.tryParse(vals[3]) ?? BigInt.one,
));
} catch (e) {
continue;
@@ -79,8 +85,8 @@ class DiskIO extends TimeSeq<DiskIOPiece> {
(String?, String?) getSpeed(String dev) {
final (read_, write_) = _getSpeed(dev);
if (read_ == null || write_ == null) return (null, null);
final read = '${read_.convertBytes}/s';
final write = '${write_.convertBytes}/s';
final read = '${read_.bytes2Str}/s';
final write = '${write_.bytes2Str}/s';
return (read, write);
}
@@ -92,8 +98,8 @@ class DiskIO extends TimeSeq<DiskIOPiece> {
read += read_ ?? 0;
write += write_ ?? 0;
}
final readStr = '${read.convertBytes}/s';
final writeStr = '${write.convertBytes}/s';
final readStr = '${read.bytes2Str}/s';
final writeStr = '${write.bytes2Str}/s';
return (readStr, writeStr);
}

View File

@@ -47,10 +47,10 @@ class NetSpeed extends TimeSeq<NetSpeedPart> {
for (var i = 0; i < now.length; i++) {
size += sizeInBytes(i);
}
return size.convertBytes;
return size.bytes2Str;
}
final idx = deviceIdx(device);
return sizeInBytes(idx).convertBytes;
return sizeInBytes(idx).bytes2Str;
}
String speedOut({String? device, bool all = false}) {
@@ -73,10 +73,10 @@ class NetSpeed extends TimeSeq<NetSpeedPart> {
for (var i = 0; i < now.length; i++) {
size += sizeOutBytes(i);
}
return size.convertBytes;
return size.bytes2Str;
}
final idx = deviceIdx(device);
return sizeOutBytes(idx).convertBytes;
return sizeOutBytes(idx).bytes2Str;
}
int deviceIdx(String? device) {
@@ -90,7 +90,7 @@ class NetSpeed extends TimeSeq<NetSpeedPart> {
return 0;
}
String buildStandardOutput(double speed) => '${speed.convertBytes}/s';
String buildStandardOutput(double speed) => '${speed.bytes2Str}/s';
/// [raw] example:
/// Inter-| Receive | Transmit