mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2026-02-07 16:54:55 +01:00
new & opt.
- new: ssh discontinuity test - opt.: server cmds - opt.: check ssh client status before exec cmds - new: #124 notify on discontinuity
This commit is contained in:
@@ -83,6 +83,7 @@ extension EnumX on Enum {
|
||||
}
|
||||
|
||||
enum StatusCmdType {
|
||||
time,
|
||||
net,
|
||||
sys,
|
||||
cpu,
|
||||
|
||||
@@ -88,7 +88,9 @@ List<OneTimeCpuStatus> parseCPU(String raw) {
|
||||
int.parse(matches[3]),
|
||||
int.parse(matches[4]),
|
||||
int.parse(matches[5]),
|
||||
int.parse(matches[6])));
|
||||
int.parse(matches[6]),
|
||||
),
|
||||
);
|
||||
}
|
||||
return cpus;
|
||||
}
|
||||
|
||||
@@ -3,10 +3,11 @@ import 'package:toolbox/core/extension/numx.dart';
|
||||
import 'time_seq.dart';
|
||||
|
||||
class NetSpeedPart extends TimeSeqIface<NetSpeedPart> {
|
||||
String device;
|
||||
BigInt bytesIn;
|
||||
BigInt bytesOut;
|
||||
BigInt time;
|
||||
final String device;
|
||||
final BigInt bytesIn;
|
||||
final BigInt bytesOut;
|
||||
final int time;
|
||||
|
||||
NetSpeedPart(this.device, this.bytesIn, this.bytesOut, this.time);
|
||||
|
||||
@override
|
||||
@@ -18,7 +19,7 @@ class NetSpeed extends TimeSeq<NetSpeedPart> {
|
||||
|
||||
List<String> get devices => now.map((e) => e.device).toList();
|
||||
|
||||
BigInt get _timeDiff => now[0].time - pre[0].time;
|
||||
BigInt get _timeDiff => BigInt.from(now[0].time - pre[0].time);
|
||||
|
||||
double _speedIn(int i) => (now[i].bytesIn - pre[i].bytesIn) / _timeDiff;
|
||||
double _speedOut(int i) => (now[i].bytesOut - pre[i].bytesOut) / _timeDiff;
|
||||
@@ -96,14 +97,12 @@ class NetSpeed extends TimeSeq<NetSpeedPart> {
|
||||
/// 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) {
|
||||
List<NetSpeedPart> parseNetSpeed(String raw, int time) {
|
||||
final split = raw.split('\n');
|
||||
if (split.length < 4) {
|
||||
return [];
|
||||
}
|
||||
|
||||
final time = BigInt.parse(split[split.length - 1]);
|
||||
final results = <NetSpeedPart>[];
|
||||
for (final item in split.sublist(2, split.length - 1)) {
|
||||
final data = item.trim().split(':');
|
||||
|
||||
@@ -15,7 +15,10 @@ class ServerStatusUpdateReq {
|
||||
|
||||
Future<ServerStatus> getStatus(ServerStatusUpdateReq req) async {
|
||||
final segments = req.segments;
|
||||
final net = parseNetSpeed(StatusCmdType.net.find(segments));
|
||||
|
||||
final time = int.parse(StatusCmdType.time.find(segments));
|
||||
|
||||
final net = parseNetSpeed(StatusCmdType.net.find(segments), time);
|
||||
req.ss.netSpeed.update(net);
|
||||
|
||||
final sys = _parseSysVer(
|
||||
|
||||
@@ -219,7 +219,7 @@ class ServerProvider extends ChangeNotifier {
|
||||
return;
|
||||
}
|
||||
|
||||
if (s.state.shouldConnect) {
|
||||
if (s.state.shouldConnect || (s.client?.isClosed ?? true)) {
|
||||
_setServerState(s, ServerState.connecting);
|
||||
|
||||
final time1 = DateTime.now();
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
class BuildData {
|
||||
static const String name = "ServerBox";
|
||||
static const int build = 474;
|
||||
static const int build = 476;
|
||||
static const String engine = "3.10.6";
|
||||
static const String buildAt = "2023-08-16 15:42:48.857532";
|
||||
static const int modifications = 24;
|
||||
static const String buildAt = "2023-08-17 18:45:06.973608";
|
||||
static const int modifications = 5;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,8 @@ const serverBoxDir = r'$HOME/.config/server_box';
|
||||
const shellPath = '$serverBoxDir/mobile_app.sh';
|
||||
|
||||
const statusCmds = [
|
||||
'cat /proc/net/dev && date +%s',
|
||||
'date +%s',
|
||||
'cat /proc/net/dev',
|
||||
'cat /etc/os-release | grep PRETTY_NAME',
|
||||
'cat /proc/stat | grep cpu',
|
||||
'uptime',
|
||||
|
||||
@@ -31,7 +31,7 @@ NetSpeedPart get _initNetSpeedPart => NetSpeedPart(
|
||||
'',
|
||||
BigInt.zero,
|
||||
BigInt.zero,
|
||||
BigInt.zero,
|
||||
0,
|
||||
);
|
||||
NetSpeed get initNetSpeed => NetSpeed(
|
||||
[_initNetSpeedPart],
|
||||
|
||||
Reference in New Issue
Block a user