new & opt

new: `net` total in & out bytes
opt: i18n for `ssh`
opt: disk path ignore
This commit is contained in:
lollipopkit
2023-02-02 13:11:21 +08:00
parent 469b9fe8cd
commit c479d18714
10 changed files with 103 additions and 72 deletions

View File

@@ -1,3 +1,5 @@
import '../../res/misc.dart';
class DiskInfo {
/*
{
@@ -26,3 +28,24 @@ class DiskInfo {
this.avail,
);
}
List<DiskInfo> parseDisk(String raw) {
final list = <DiskInfo>[];
final items = raw.split('\n');
items.removeAt(0);
for (var item in items) {
if (item.isEmpty) {
continue;
}
final vals = item.split(numReg);
list.add(DiskInfo(
vals[0],
vals[5],
int.parse(vals[4].replaceFirst('%', '')),
vals[2],
vals[1],
vals[3],
));
}
return list;
}

View File

@@ -36,6 +36,13 @@ class NetSpeed {
return buildStandardOutput(speedInBytesPerSecond);
}
String totalIn({String? device}) {
if (_old[0].device == '' || _now[0].device == '') return '0kb';
final idx = deviceIdx(device);
final totalInBytes = _now[idx].bytesIn;
return totalInBytes.toInt().convertBytes;
}
String speedOut({String? device}) {
if (_old[0].device == '' || _now[0].device == '') return '0kb/s';
final idx = deviceIdx(device);
@@ -44,6 +51,13 @@ class NetSpeed {
return buildStandardOutput(speedOutBytesPerSecond);
}
String totalOut({String? device}) {
if (_old[0].device == '' || _now[0].device == '') return '0kb';
final idx = deviceIdx(device);
final totalOutBytes = _now[idx].bytesOut;
return totalOutBytes.toInt().convertBytes;
}
int deviceIdx(String? device) {
if (device != null) {
for (var item in _now) {
@@ -55,10 +69,15 @@ class NetSpeed {
return 0;
}
String buildStandardOutput(double speed) =>
'${speed.convertBytes.toLowerCase()}/s';
String buildStandardOutput(double speed) => '${speed.convertBytes}/s';
}
/// [raw] example:
/// Inter-| Receive | Transmit
/// face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
/// lo: 45929941 269112 0 0 0 0 0 0 45929941 269112 0 0 0 0 0 0
/// eth0: 48481023 505772 0 0 0 0 0 0 36002262 202307 0 0 0 0 0 0
/// 1635752901
List<NetSpeedPart> parseNetSpeed(String raw) {
final split = raw.split('\n');
if (split.length < 4) {

View File

@@ -1,4 +1,5 @@
import '../../../core/extension/stringx.dart';
import '../../res/misc.dart';
///
/// Code generated by jsonToDartModel https://ashamp.github.io/jsonToDartModel/
@@ -42,8 +43,6 @@ class TcpStatus {
}
}
final numReg = RegExp(r'\s{1,}');
TcpStatus? parseTcp(String raw) {
final lines = raw.split('\n');
final idx = lines.lastWhere((element) => element.startsWith('Tcp:'),

View File

@@ -186,12 +186,6 @@ class ServerProvider extends BusyProvider {
}
}
/// [raw] example:
/// Inter-| Receive | Transmit
/// face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
/// lo: 45929941 269112 0 0 0 0 0 0 45929941 269112 0 0 0 0 0 0
/// eth0: 48481023 505772 0 0 0 0 0 0 36002262 202307 0 0 0 0 0 0
/// 1635752901
Future<void> _getNetSpeed(ServerPrivateInfo spi, String raw) async {
final info = _servers.firstWhere((e) => e.spi == spi);
info.status.netSpeed.update(await compute(parseNetSpeed, raw));
@@ -211,8 +205,10 @@ class ServerProvider extends BusyProvider {
final cpus = await compute(parseCPU, raw);
if (cpus.isNotEmpty) {
info.status.cpu
.update(cpus, await compute(parseCPUTemp, [tempType, tempValue]));
info.status.cpu.update(
cpus,
await compute(parseCPUTemp, [tempType, tempValue]),
);
}
}
@@ -229,25 +225,14 @@ class ServerProvider extends BusyProvider {
}
}
void _getDisk(ServerPrivateInfo spi, String raw) {
Future<void> _getDisk(ServerPrivateInfo spi, String raw) async {
final info = _servers.firstWhere((e) => e.spi == spi);
final list = <DiskInfo>[];
final items = raw.split('\n');
for (var item in items) {
if (items.indexOf(item) == 0 || item.isEmpty) {
continue;
}
final vals = item.split(numReg);
list.add(DiskInfo(vals[0], vals[5],
int.parse(vals[4].replaceFirst('%', '')), vals[2], vals[1], vals[3]));
}
info.status.disk = list;
info.status.disk = await compute(parseDisk, raw);
}
Future<void> _getMem(ServerPrivateInfo spi, String raw) async {
final info = _servers.firstWhere((e) => e.spi == spi);
final mem = await compute(parseMem, raw);
info.status.mem = mem;
info.status.mem = await compute(parseMem, raw);
}
Future<String?> runSnippet(String id, Snippet snippet) async {

View File

@@ -2,9 +2,9 @@
class BuildData {
static const String name = "ServerBox";
static const int build = 210;
static const int build = 211;
static const String engine =
"Flutter 3.7.0 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision b06b8b2710 (9 days ago) • 2023-01-23 16:55:55 -0800\nEngine • revision b24591ed32\nTools • Dart 2.19.0 • DevTools 2.20.1\n";
static const String buildAt = "2023-02-01 23:36:32.789406";
static const int modifications = 0;
static const String buildAt = "2023-02-02 12:40:53.962160";
static const int modifications = 5;
}

View File

@@ -1 +1,3 @@
const serverMaxTryTimes = 7;
final numReg = RegExp(r'\s{1,}');