mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 23:34:24 +01:00
Finish server detail page
This commit is contained in:
@@ -6,6 +6,7 @@ class Cpu2Status {
|
||||
Cpu2Status(this.pre, this.now);
|
||||
|
||||
double usedPercent({int coreIdx = 0}) {
|
||||
if (now.length != pre.length) return 0;
|
||||
final idleDelta = now[coreIdx].idle - pre[coreIdx].idle;
|
||||
final totalDelta = now[coreIdx].total - pre[coreIdx].total;
|
||||
final used = idleDelta / totalDelta;
|
||||
@@ -15,4 +16,31 @@ class Cpu2Status {
|
||||
Cpu2Status update(List<CpuStatus> newStatus) {
|
||||
return Cpu2Status(now, newStatus);
|
||||
}
|
||||
|
||||
int get coresCount => now.length;
|
||||
|
||||
int get totalDelta => now[0].total - pre[0].total;
|
||||
|
||||
double get user {
|
||||
if (now.length != pre.length) return 0;
|
||||
final delta = now[0].user - pre[0].user;
|
||||
final used = delta / totalDelta;
|
||||
return used.isNaN ? 0 : used * 100;
|
||||
}
|
||||
|
||||
double get sys {
|
||||
if (now.length != pre.length) return 0;
|
||||
final delta = now[0].sys - pre[0].sys;
|
||||
final used = delta / totalDelta;
|
||||
return used.isNaN ? 0 : used * 100;
|
||||
}
|
||||
|
||||
double get nice {
|
||||
if (now.length != pre.length) return 0;
|
||||
final delta = now[0].nice - pre[0].nice;
|
||||
final used = delta / totalDelta;
|
||||
return used.isNaN ? 0 : used * 100;
|
||||
}
|
||||
|
||||
double get idle => 100 - usedPercent();
|
||||
}
|
||||
|
||||
@@ -4,34 +4,35 @@ class DiskInfo {
|
||||
"mountPath": "",
|
||||
"mountLocation": "",
|
||||
"usedPercent": 0,
|
||||
"used": "",=
|
||||
"used": "",
|
||||
"size": "",
|
||||
"avail": ""
|
||||
}
|
||||
*/
|
||||
|
||||
String? mountPath;
|
||||
String? mountLocation;
|
||||
double? usedPercent;
|
||||
String? used;
|
||||
String? size;
|
||||
String? avail;
|
||||
late String mountPath;
|
||||
late String mountLocation;
|
||||
late int usedPercent;
|
||||
late String used;
|
||||
late String size;
|
||||
late String avail;
|
||||
|
||||
DiskInfo({
|
||||
DiskInfo(
|
||||
this.mountPath,
|
||||
this.mountLocation,
|
||||
this.usedPercent,
|
||||
this.used,
|
||||
this.size,
|
||||
this.avail,
|
||||
});
|
||||
);
|
||||
|
||||
DiskInfo.fromJson(Map<String, dynamic> json) {
|
||||
mountPath = json["mountPath"]?.toString();
|
||||
mountLocation = json["mountLocation"]?.toString();
|
||||
usedPercent = double.parse(json["usedPercent"]);
|
||||
used = json["used"]?.toString();
|
||||
size = json["size"]?.toString();
|
||||
avail = json["avail"]?.toString();
|
||||
mountPath = json["mountPath"].toString();
|
||||
mountLocation = json["mountLocation"].toString();
|
||||
usedPercent = int.parse(json["usedPercent"]);
|
||||
used = json["used"].toString();
|
||||
size = json["size"].toString();
|
||||
avail = json["avail"].toString();
|
||||
}
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
|
||||
14
lib/data/model/linux_icon.dart
Normal file
14
lib/data/model/linux_icon.dart
Normal file
@@ -0,0 +1,14 @@
|
||||
class LinuxIcons {
|
||||
List<String> db;
|
||||
|
||||
LinuxIcons(this.db);
|
||||
|
||||
String? search(String sysVer) {
|
||||
for (var item in db) {
|
||||
if (sysVer.contains(item)) {
|
||||
return 'assets/linux/$item.png';
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -29,10 +29,10 @@ class ServerStatus {
|
||||
*/
|
||||
|
||||
late Cpu2Status cpu2Status;
|
||||
late List<int?> memList;
|
||||
late List<int> memList;
|
||||
late String sysVer;
|
||||
late String uptime;
|
||||
late List<DiskInfo?> disk;
|
||||
late List<DiskInfo> disk;
|
||||
late TcpStatus tcp;
|
||||
|
||||
ServerStatus(this.cpu2Status, this.memList, this.sysVer, this.uptime,
|
||||
|
||||
@@ -11,23 +11,25 @@ class TcpStatus {
|
||||
}
|
||||
*/
|
||||
|
||||
int? maxConn;
|
||||
int? active;
|
||||
int? passive;
|
||||
int? fail;
|
||||
late int maxConn;
|
||||
late int active;
|
||||
late int passive;
|
||||
late int fail;
|
||||
|
||||
TcpStatus({
|
||||
TcpStatus(
|
||||
this.maxConn,
|
||||
this.active,
|
||||
this.passive,
|
||||
this.fail,
|
||||
});
|
||||
);
|
||||
|
||||
TcpStatus.fromJson(Map<String, dynamic> json) {
|
||||
maxConn = json["maxConn"]?.toInt();
|
||||
active = json["active"]?.toInt();
|
||||
passive = json["passive"]?.toInt();
|
||||
fail = json["fail"]?.toInt();
|
||||
maxConn = json["maxConn"].toInt();
|
||||
active = json["active"].toInt();
|
||||
passive = json["passive"].toInt();
|
||||
fail = json["fail"].toInt();
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
data["maxConn"] = maxConn;
|
||||
|
||||
@@ -32,16 +32,8 @@ class ServerProvider extends BusyProvider {
|
||||
[100, 0],
|
||||
'',
|
||||
'',
|
||||
[
|
||||
DiskInfo(
|
||||
mountLocation: '/',
|
||||
mountPath: '/',
|
||||
used: '0',
|
||||
size: '0',
|
||||
avail: '0',
|
||||
usedPercent: 0)
|
||||
],
|
||||
TcpStatus(maxConn: 0, active: 0, passive: 0, fail: 0));
|
||||
[DiskInfo('/', '/', 0, '0', '0', '0')],
|
||||
TcpStatus(0, 0, 0, 0));
|
||||
|
||||
Future<void> loadLocalData() async {
|
||||
setBusyState(true);
|
||||
@@ -199,13 +191,13 @@ class ServerProvider extends BusyProvider {
|
||||
if (idx == 2) {
|
||||
final vals = item.split(RegExp(r'\s{1,}'));
|
||||
return TcpStatus(
|
||||
maxConn: vals[5].i,
|
||||
active: vals[6].i,
|
||||
passive: vals[7].i,
|
||||
fail: vals[8].i);
|
||||
vals[5].i,
|
||||
vals[6].i,
|
||||
vals[7].i,
|
||||
vals[8].i);
|
||||
}
|
||||
}
|
||||
return TcpStatus(maxConn: 0, active: 0, passive: 0, fail: 0);
|
||||
return TcpStatus(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
List<DiskInfo> _getDisk(String disk) {
|
||||
@@ -216,13 +208,8 @@ class ServerProvider extends BusyProvider {
|
||||
continue;
|
||||
}
|
||||
final vals = item.split(RegExp(r'\s{1,}'));
|
||||
list.add(DiskInfo(
|
||||
mountPath: vals[1],
|
||||
mountLocation: vals[5],
|
||||
usedPercent: double.parse(vals[4].replaceFirst('%', '')),
|
||||
used: vals[2],
|
||||
size: vals[1],
|
||||
avail: vals[3]));
|
||||
list.add(DiskInfo(vals[0], vals[5],
|
||||
int.parse(vals[4].replaceFirst('%', '')), vals[2], vals[1], vals[3]));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,8 @@
|
||||
|
||||
class BuildData {
|
||||
static const String name = "ToolBox";
|
||||
static const int build = 30;
|
||||
static const String engine =
|
||||
"Flutter 2.5.3 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 18116933e7 (11 days ago) • 2021-10-15 10:46:35 -0700\nEngine • revision d3ea636dc5\nTools • Dart 2.14.4\n";
|
||||
static const String buildAt = "2021-10-26 17:55:37.268093";
|
||||
static const int modifications = 0;
|
||||
static const int build = 40;
|
||||
static const String engine = "Flutter 2.5.3 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 18116933e7 (13 days ago) • 2021-10-15 10:46:35 -0700\nEngine • revision d3ea636dc5\nTools • Dart 2.14.4\n";
|
||||
static const String buildAt = "2021-10-28 19:02:21.118303";
|
||||
static const int modifications = 17;
|
||||
}
|
||||
|
||||
4
lib/data/res/linux_icons.dart
Normal file
4
lib/data/res/linux_icons.dart
Normal file
@@ -0,0 +1,4 @@
|
||||
import 'package:toolbox/data/model/linux_icon.dart';
|
||||
|
||||
final linuxIcons = LinuxIcons(['ubuntu', 'arch', 'centos', 'debian', 'fedora',
|
||||
'opensuse', 'kali']);
|
||||
Reference in New Issue
Block a user