mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 15:24:35 +01:00
new: container stats (#272)
This commit is contained in:
@@ -40,7 +40,7 @@ enum ContainerErrType {
|
||||
invalidVersion,
|
||||
cmdNoPrefix,
|
||||
segmentsNotMatch,
|
||||
parsePsItem,
|
||||
parsePs,
|
||||
parseImages,
|
||||
parseStats,
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:toolbox/core/extension/context/locale.dart';
|
||||
import 'package:toolbox/core/extension/numx.dart';
|
||||
import 'package:toolbox/data/model/container/type.dart';
|
||||
|
||||
abstract final class ContainerPs {
|
||||
@@ -9,7 +11,14 @@ abstract final class ContainerPs {
|
||||
String? get cmd;
|
||||
bool get running;
|
||||
|
||||
String? cpu;
|
||||
String? mem;
|
||||
String? net;
|
||||
String? disk;
|
||||
|
||||
factory ContainerPs.fromRawJson(String s, ContainerType typ) => typ.ps(s);
|
||||
|
||||
void parseStats(String s);
|
||||
}
|
||||
|
||||
final class PodmanPs implements ContainerPs {
|
||||
@@ -23,6 +32,11 @@ final class PodmanPs implements ContainerPs {
|
||||
final List<String>? names;
|
||||
final int? startedAt;
|
||||
|
||||
String? cpu;
|
||||
String? mem;
|
||||
String? net;
|
||||
String? disk;
|
||||
|
||||
PodmanPs({
|
||||
this.command,
|
||||
this.created,
|
||||
@@ -42,6 +56,23 @@ final class PodmanPs implements ContainerPs {
|
||||
@override
|
||||
bool get running => exited != true;
|
||||
|
||||
@override
|
||||
void parseStats(String s) {
|
||||
final stats = json.decode(s);
|
||||
final cpuD = (stats['CPU'] as double? ?? 0).toStringAsFixed(1);
|
||||
final cpuAvgD = (stats['AvgCPU'] as double? ?? 0).toStringAsFixed(1);
|
||||
cpu = '$cpuD% / ${l10n.pingAvg} $cpuAvgD%';
|
||||
final memLimit = (stats['MemLimit'] as int? ?? 0).bytes2Str;
|
||||
final memUsage = (stats['MemUsage'] as int? ?? 0).bytes2Str;
|
||||
mem = '$memUsage / $memLimit';
|
||||
final netIn = (stats['NetInput'] as int? ?? 0).bytes2Str;
|
||||
final netOut = (stats['NetOutput'] as int? ?? 0).bytes2Str;
|
||||
net = '↓ $netIn / ↑ $netOut';
|
||||
final diskIn = (stats['BlockInput'] as int? ?? 0).bytes2Str;
|
||||
final diskOut = (stats['BlockOutput'] as int? ?? 0).bytes2Str;
|
||||
disk = '${l10n.read} $diskOut / ${l10n.write} $diskIn';
|
||||
}
|
||||
|
||||
factory PodmanPs.fromRawJson(String str) =>
|
||||
PodmanPs.fromJson(json.decode(str));
|
||||
|
||||
@@ -84,6 +115,11 @@ final class DockerPs implements ContainerPs {
|
||||
final String? names;
|
||||
final String? state;
|
||||
|
||||
String? cpu;
|
||||
String? mem;
|
||||
String? net;
|
||||
String? disk;
|
||||
|
||||
DockerPs({
|
||||
this.command,
|
||||
this.createdAt,
|
||||
@@ -102,6 +138,15 @@ final class DockerPs implements ContainerPs {
|
||||
@override
|
||||
bool get running => state == 'running';
|
||||
|
||||
@override
|
||||
void parseStats(String s) {
|
||||
final stats = json.decode(s);
|
||||
cpu = stats['CPUPerc'];
|
||||
mem = stats['MemUsage'];
|
||||
net = stats['NetIO'];
|
||||
disk = stats['BlockIO'];
|
||||
}
|
||||
|
||||
factory DockerPs.fromRawJson(String str) =>
|
||||
DockerPs.fromJson(json.decode(str));
|
||||
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
import 'dart:convert';
|
||||
|
||||
class Containerd {
|
||||
final ContainerdClient client;
|
||||
|
||||
Containerd({
|
||||
required this.client,
|
||||
});
|
||||
|
||||
factory Containerd.fromRawJson(String str) =>
|
||||
Containerd.fromJson(json.decode(str));
|
||||
|
||||
String toRawJson() => json.encode(toJson());
|
||||
|
||||
factory Containerd.fromJson(Map<String, dynamic> json) => Containerd(
|
||||
client: ContainerdClient.fromJson(json["Client"]),
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"Client": client.toJson(),
|
||||
};
|
||||
}
|
||||
|
||||
class ContainerdClient {
|
||||
final String apiVersion;
|
||||
final String version;
|
||||
final String goVersion;
|
||||
final String gitCommit;
|
||||
final String builtTime;
|
||||
final String os;
|
||||
|
||||
ContainerdClient({
|
||||
required this.apiVersion,
|
||||
required this.version,
|
||||
required this.goVersion,
|
||||
required this.gitCommit,
|
||||
required this.builtTime,
|
||||
required this.os,
|
||||
});
|
||||
|
||||
factory ContainerdClient.fromRawJson(String str) =>
|
||||
ContainerdClient.fromJson(json.decode(str));
|
||||
|
||||
String toRawJson() => json.encode(toJson());
|
||||
|
||||
factory ContainerdClient.fromJson(Map<String, dynamic> json) =>
|
||||
ContainerdClient(
|
||||
apiVersion: json["ApiVersion"],
|
||||
version: json["Version"],
|
||||
goVersion: json["GoVersion"],
|
||||
gitCommit: json["GitCommit"],
|
||||
builtTime: json["BuildTime"],
|
||||
os: json["Os"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"ApiVersion": apiVersion,
|
||||
"Version": version,
|
||||
"GoVersion": goVersion,
|
||||
"GitCommit": gitCommit,
|
||||
"BuildTime": builtTime,
|
||||
"Os": os,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user