Change CPU Algorithm. Update README imgs

This commit is contained in:
LollipopKit
2021-10-28 00:39:12 +08:00
parent b8acd38b17
commit 6a0aa00f05
10 changed files with 125 additions and 52 deletions

View 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;
}
}

View File

@@ -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>[];