mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
feat: display cpu model (#477)
This commit is contained in:
@@ -192,6 +192,7 @@ enum StatusCmdType {
|
||||
'for f in /sys/class/power_supply/*/uevent; do cat "\$f"; echo; done'),
|
||||
nvidia._('nvidia-smi -q -x'),
|
||||
sensors._('sensors'),
|
||||
cpuBrand._('cat /proc/cpuinfo | grep "model name"'),
|
||||
;
|
||||
|
||||
final String cmd;
|
||||
@@ -210,6 +211,7 @@ enum BSDStatusCmdType {
|
||||
mem._('top -l 1 | grep PhysMem'),
|
||||
//temp,
|
||||
host._('hostname'),
|
||||
cpuBrand._('sysctl -n machdep.cpu.brand_string'),
|
||||
;
|
||||
|
||||
final String cmd;
|
||||
|
||||
@@ -4,11 +4,14 @@ import 'package:fl_chart/fl_chart.dart';
|
||||
import 'package:server_box/data/model/server/time_seq.dart';
|
||||
import 'package:server_box/data/res/status.dart';
|
||||
|
||||
/// Capacity of the FIFO queue
|
||||
const _kCap = 30;
|
||||
|
||||
class Cpus extends TimeSeq<List<SingleCpuCore>> {
|
||||
Cpus(super.init1, super.init2);
|
||||
|
||||
final Map<String, int> brand = {};
|
||||
|
||||
@override
|
||||
void onUpdate() {
|
||||
_coresCount = now.length;
|
||||
@@ -175,6 +178,22 @@ class SingleCpuCore extends TimeSeqIface<SingleCpuCore> {
|
||||
}
|
||||
}
|
||||
|
||||
final class CpuBrand {
|
||||
static Map<String, int> parse(String raw) {
|
||||
final lines = raw.split('\n');
|
||||
// {brand: count}
|
||||
final brands = <String, int>{};
|
||||
for (var line in lines) {
|
||||
if (line.contains('model name')) {
|
||||
final model = line.split(':').last.trim();
|
||||
final count = brands[model] ?? 0;
|
||||
brands[model] = count + 1;
|
||||
}
|
||||
}
|
||||
return brands;
|
||||
}
|
||||
}
|
||||
|
||||
final _bsdCpuPercentReg = RegExp(r'(\d+\.\d+)%');
|
||||
|
||||
/// TODO: Change this implementation to parse cpu status on BSD system
|
||||
|
||||
@@ -71,6 +71,9 @@ Future<ServerStatus> _getLinuxStatus(ServerStatusUpdateReq req) async {
|
||||
try {
|
||||
final cpus = SingleCpuCore.parse(StatusCmdType.cpu.find(segments));
|
||||
req.ss.cpu.update(cpus);
|
||||
final brand = CpuBrand.parse(StatusCmdType.cpuBrand.find(segments));
|
||||
req.ss.cpu.brand.clear();
|
||||
req.ss.cpu.brand.addAll(brand);
|
||||
} catch (e, s) {
|
||||
Loggers.app.warning(e, s);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user