opt.: shell_func only get useful mem data

This commit is contained in:
lollipopkit
2023-10-13 12:48:54 +08:00
parent 7388ad4524
commit a2bb4f1287
11 changed files with 43 additions and 52 deletions

View File

@@ -192,7 +192,7 @@ const _statusCmds = [
'uptime',
'cat /proc/net/snmp',
'df -h',
'cat /proc/meminfo',
'cat /proc/meminfo | grep Mem',
'cat /sys/class/thermal/thermal_zone*/type',
'cat /sys/class/thermal/thermal_zone*/temp',
'hostname',

View File

@@ -1,13 +1,11 @@
class Memory {
final int total;
final int free;
final int cache;
final int avail;
const Memory({
required this.total,
required this.free,
required this.cache,
required this.avail,
});
@@ -46,16 +44,6 @@ Memory parseMem(String raw) {
'0',
) ??
0;
final cached = int.tryParse(
items
.firstWhere(
(e) => e?.group(1) == 'Cached:',
orElse: () => null,
)
?.group(2) ??
'0',
) ??
0;
final available = int.tryParse(
items
.firstWhere(
@@ -70,7 +58,6 @@ Memory parseMem(String raw) {
return Memory(
total: total,
free: free,
cache: cached,
avail: available,
);
}

View File

@@ -20,12 +20,14 @@ enum SystemType {
return null;
}
bool isSegmentsLenMatch(int len) {
bool isSegmentsLenMatch(int len) => len == segmentsLen;
int get segmentsLen {
switch (this) {
case SystemType.linux:
return len == StatusCmdType.values.length;
return StatusCmdType.values.length;
case SystemType.bsd:
return len == BSDStatusCmdType.values.length;
return BSDStatusCmdType.values.length;
}
}
}

View File

@@ -313,7 +313,8 @@ class ServerProvider extends ChangeNotifier {
}
/// Keep [finished] state, or the UI will be refreshed to [loading] state
/// instead of the 'Temp & Uptime'.
/// instead of the '$Temp | $Uptime'.
/// eg: '32C | 7 days'
if (s.state != ServerState.finished) {
_setServerState(s, ServerState.loading);
}
@@ -330,7 +331,8 @@ class ServerProvider extends ChangeNotifier {
final systemType = SystemType.parse(segments[0]);
if (systemType == null || !systemType.isSegmentsLenMatch(segments.length)) {
_limiter.inc(sid);
s.status.failedInfo = 'Segments not match: ${segments.length}';
s.status.failedInfo =
'Segments not match: expect ${systemType?.segmentsLen}, got ${segments.length}';
_setServerState(s, ServerState.failed);
return;
}

View File

@@ -2,9 +2,9 @@
class BuildData {
static const String name = "ServerBox";
static const int build = 580;
static const int build = 585;
static const String engine = "3.13.6";
static const String buildAt = "2023-10-05 19:51:55";
static const int modifications = 4;
static const int script = 19;
static const String buildAt = "2023-10-13 11:50:42";
static const int modifications = 8;
static const int script = 20;
}

View File

@@ -40,7 +40,6 @@ class InitStatus {
mem: const Memory(
total: 1,
free: 1,
cache: 0,
avail: 1,
),
sysVer: 'Loading...',