Közzétett forrás
Letöltés forrás ZIP
CH-J SM Mobile
Könyvtárak és fájlok böngészése egy adott alkalmazás kiadásához.
CH-J / SM Mobile
134 fájlok
sm-mobile-20261016T050549Z-3678f2a05fa9
Hozzáadva: · Beépített:
1
import 'dart:async';2
import 'dart:convert';3
import 'package:dartssh2/dartssh2.dart';4
import '../core/failure.dart';6
abstract interface class MonitorAdapter {7
Future<Map<String, String>> sample(SSHClient client);8
void cancel();9
}11
class LinuxMonitor implements MonitorAdapter {12
final Set<SSHSession> _active = {};13
int _epoch = 0;14
@override15
void cancel() {16
_epoch++;17
for (final session in _active) {18
session.close();19
}20
_active.clear();21
}23
Future<SSHSession> _execute(24
SSHClient client,25
String command,26
int epoch,27
) async {28
return client29
.execute(command)30
.then((session) {31
if (epoch != _epoch) {32
session.close();33
throw const Failure('cancelled');34
}35
_active.add(session);36
return session;37
})38
.timeout(39
const Duration(seconds: 10),40
onTimeout: () {41
cancel();42
throw TimeoutException('SSH channel');43
},44
);45
}47
static const command = r'''LC_ALL=C; export LC_ALL48
test "$(uname -s)" = Linux || exit 7049
printf 'system='; uname -sr50
printf 'release='; sed -n 's/^PRETTY_NAME=//p' /etc/os-release51
printf 'uptime='; cut -d ' ' -f 1 /proc/uptime52
printf 'load='; cut -d ' ' -f 1-3 /proc/loadavg53
awk '/^MemTotal:/{t=$2}/^MemAvailable:/{a=$2}END{if(t>0)printf "ram=%.1f%% (%d / %d MiB)\n",100*(t-a)/t,(t-a)/1024,t/1024}' /proc/meminfo54
df -Pk / | awk 'NR==2{printf "disk=%s (%s / %s KiB)\n",$5,$3,$2}'55
a=$(awk '/^cpu /{t=0;for(i=2;i<=9;i++)t+=$i;printf "%.0f %.0f\n",t,$5+$6;exit}' /proc/stat)56
sleep 157
b=$(awk '/^cpu /{t=0;for(i=2;i<=9;i++)t+=$i;printf "%.0f %.0f\n",t,$5+$6;exit}' /proc/stat)58
awk -v a="$a" -v b="$b" 'BEGIN{split(a,x," ");split(b,y," ");t=y[1]-x[1];if(t>0)printf "cpu=%.1f%%\n",100*(t-y[2]+x[2])/t}'59
''';60
@override61
Future<Map<String, String>> sample(SSHClient client) async {62
final epoch = _epoch;63
final watch = Stopwatch()..start();64
final ping = await _execute(client, 'true', epoch);65
try {66
await ping.done.timeout(const Duration(seconds: 10));67
} finally {68
ping.close();69
_active.remove(ping);70
}71
final rtt = watch.elapsedMilliseconds;72
final session = await _execute(client, command, epoch);73
final output = StringBuffer();74
var bytes = 0;75
final sub = session.stdout76
.cast<List<int>>()77
.transform(const Utf8Decoder(allowMalformed: true))78
.listen((s) {79
bytes += s.length;80
if (bytes <= 65536) {81
output.write(s);82
} else {83
session.close();84
}85
});86
final err = session.stderr.listen((_) {});87
try {88
await session.done.timeout(const Duration(seconds: 15));89
if (session.exitCode != 0 || bytes > 65536) {90
throw const Failure('unsupportedSystem');91
}92
return {93
'rtt': '$rtt ms',94
for (final line in output.toString().split('\n'))95
if (line.contains('='))96
line.substring(0, line.indexOf('=')): line.substring(97
line.indexOf('=') + 1,98
),99
};100
} finally {101
await sub.cancel();102
await err.cancel();103
session.close();104
_active.remove(session);105
}106
}107
}SHA-256
88d23fd89e0631ecbcc92bdd3771193581dcd9b793b80f47ccae946124784256CH-J Proprietary Software License 1.14 · A forrás a CH-J Proprietary Software License 1.14 alatt található. Rendelkezése nem változtatja meg a licenc feltételeit, és nem ad további jogokat.
Archive SHA-256
c486a807e4828998b9c57ab0f2e760f7980b31965fe118e89d3e1a5a2b65be65