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

@@ -214,7 +214,7 @@ const _statusCmds = [
'cat /proc/stat | grep cpu',
'uptime',
'cat /proc/net/snmp',
'df -h',
'df -B 1K',
"cat /proc/meminfo | grep -E 'Mem|Swap'",
'cat /sys/class/thermal/thermal_zone*/type',
'cat /sys/class/thermal/thermal_zone*/temp',
@@ -246,7 +246,7 @@ const _bsdStatusCmd = [
'uname -or',
'top -l 1 | grep "CPU usage"',
'uptime',
'df -h',
'df -k',
'top -l 1 | grep PhysMem',
//'sysctl -a | grep temperature',
'hostname',

View File

@@ -34,7 +34,7 @@ final class PodmanImg implements ContainerImg {
});
@override
String? get sizeMB => size?.convertBytes;
String? get sizeMB => size?.bytes2Str;
@override
int? get containersCount => containers;

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

View File

@@ -41,13 +41,13 @@ abstract final class InitStatus {
avail: 1,
),
disk: [
const Disk(
Disk(
dev: '/',
mount: '/',
usedPercent: 0,
used: '0',
size: '0',
avail: '0',
used: BigInt.zero,
size: BigInt.one,
avail: BigInt.zero,
)
],
tcp: const Conn(maxConn: 0, active: 0, passive: 0, fail: 0),