mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 23:34:24 +01:00
Change CPU Algorithm. Update README imgs
This commit is contained in:
63
lib/data/model/cpu_percent.dart
Normal file
63
lib/data/model/cpu_percent.dart
Normal file
@@ -0,0 +1,63 @@
|
||||
///
|
||||
/// Code generated by jsonToDartModel https://ashamp.github.io/jsonToDartModel/
|
||||
///
|
||||
class CpuStatus {
|
||||
/*
|
||||
{
|
||||
"user": 0,
|
||||
"sys": 0,
|
||||
"nice": 0,
|
||||
"idel": 0,
|
||||
"wa": 0,
|
||||
"hi": 0,
|
||||
"si": 0,
|
||||
"st": 0
|
||||
}
|
||||
*/
|
||||
late String id;
|
||||
late double user;
|
||||
late double sys;
|
||||
late double nice;
|
||||
late double idle;
|
||||
late double iowait;
|
||||
late double irq;
|
||||
late double softirq;
|
||||
|
||||
CpuStatus(
|
||||
this.id,
|
||||
this.user,
|
||||
this.sys,
|
||||
this.nice,
|
||||
this.idle,
|
||||
this.iowait,
|
||||
this.irq,
|
||||
this.softirq,
|
||||
);
|
||||
CpuStatus.fromJson(Map<String, dynamic> json) {
|
||||
id = json["id"];
|
||||
user = json["user"]?.toInt();
|
||||
sys = json["sys"]?.toInt();
|
||||
nice = json["nice"]?.toInt();
|
||||
idle = json["idle"]?.toInt();
|
||||
iowait = json["iowait"]?.toInt();
|
||||
irq = json["irq"]?.toInt();
|
||||
softirq = json["softirq"]?.toInt();
|
||||
}
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
data["id"] = id;
|
||||
data["user"] = user;
|
||||
data["sys"] = sys;
|
||||
data["nice"] = nice;
|
||||
data["idle"] = idle;
|
||||
data["iowait"] = iowait;
|
||||
data["irq"] = irq;
|
||||
data["softirq"] = softirq;
|
||||
return data;
|
||||
}
|
||||
|
||||
double get calculateUsedPercent {
|
||||
final used = idle / (user + sys + nice + iowait + irq + softirq + idle);
|
||||
return used.isNaN ? 0 : used;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:toolbox/data/model/cpu_percent.dart';
|
||||
import 'package:toolbox/data/model/disk_info.dart';
|
||||
import 'package:toolbox/data/model/tcp_status.dart';
|
||||
|
||||
@@ -27,7 +28,7 @@ class ServerStatus {
|
||||
}
|
||||
*/
|
||||
|
||||
double? cpuPercent;
|
||||
List<CpuStatus>? cpuPercent;
|
||||
List<int?>? memList;
|
||||
String? sysVer;
|
||||
String? uptime;
|
||||
@@ -42,7 +43,10 @@ class ServerStatus {
|
||||
this.disk,
|
||||
this.tcp});
|
||||
ServerStatus.fromJson(Map<String, dynamic> json) {
|
||||
cpuPercent = double.parse(json["cpuPercent"]);
|
||||
cpuPercent = [];
|
||||
for (var item in json["cpuPercent"]) {
|
||||
cpuPercent!.add(CpuStatus.fromJson(item));
|
||||
}
|
||||
if (json["memList"] != null) {
|
||||
final v = json["memList"];
|
||||
final arr0 = <int>[];
|
||||
|
||||
Reference in New Issue
Block a user