From a3566a14495648989b9c9c301c698ac131423b32 Mon Sep 17 00:00:00 2001
From: makotocc0107 <1424018999@qq.com>
Date: Thu, 29 Aug 2024 14:35:40 +0800
Subject: [PATCH] =?UTF-8?q?[=E5=A2=9E=E6=B7=BB]=E6=B7=BB=E5=8A=A0=E4=BA=86?=
=?UTF-8?q?CPU=E5=8D=A0=E7=94=A8=E7=8E=87=E9=A5=BC=E5=9B=BE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.idea/workspace.xml | 44 ++++++++------
.../app/Filament/Widgets/CPUStatus.php | 59 +++++++++++++++++++
.../app/Filament/Widgets/SystemStats.php | 2 +-
3 files changed, 87 insertions(+), 18 deletions(-)
create mode 100644 management-panel/app/Filament/Widgets/CPUStatus.php
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index b85d3d9..e9a40ca 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,9 +4,9 @@
-
+
-
+
@@ -195,19 +195,20 @@
- {
- "keyToString": {
- "RunOnceActivity.ShowReadmeOnStart": "true",
- "git-widget-placeholder": "master",
- "last_opened_file_path": "E:/data-collection-terminal",
- "node.js.detected.package.eslint": "true",
- "node.js.detected.package.tslint": "true",
- "node.js.selected.package.eslint": "(autodetect)",
- "node.js.selected.package.tslint": "(autodetect)",
- "nodejs_package_manager_path": "npm",
- "vue.rearranger.settings.migration": "true"
+
+}]]>
@@ -258,7 +259,7 @@
-
+
@@ -396,7 +397,15 @@
1724835277301
-
+
+
+ 1724899660126
+
+
+
+ 1724899660126
+
+
@@ -459,6 +468,7 @@
-
+
+
\ No newline at end of file
diff --git a/management-panel/app/Filament/Widgets/CPUStatus.php b/management-panel/app/Filament/Widgets/CPUStatus.php
new file mode 100644
index 0000000..c7b5d90
--- /dev/null
+++ b/management-panel/app/Filament/Widgets/CPUStatus.php
@@ -0,0 +1,59 @@
+query($query);
+
+ // 计算使用率和空闲率
+ $cpuUsage = 0;
+ if (isset($cpuUsageResult['data']['result'][0]['value'][1])) {
+ $cpuUsage = floatval($cpuUsageResult['data']['result'][0]['value'][1]);
+ }
+ $cpuIdle = 100 - $cpuUsage;
+
+ $data = [
+ round($cpuUsage, 2),
+ round($cpuIdle, 2),
+ ];
+
+ return [
+ 'labels' => ['CPU 使用率', 'CPU 空闲率'],
+ 'datasets' => [
+ [
+ 'label' => 'CPU 占用情况',
+ 'data' => $data,
+ 'backgroundColor' => ['#FBD1B7', '#E0F5B9'], // 柔和颜色
+ 'borderColor' => ['#FBD1B7', '#E0F5B9'], // 边框颜色
+ 'borderWidth' => 1, // 边框宽度
+ ],
+ ],
+ ];
+ }
+
+ protected function getType(): string
+ {
+ return 'pie'; // 设置为饼图
+ }
+
+ protected function getPollingInterval(): ?string
+ {
+ return '1s'; // 每秒更新一次
+ }
+}
diff --git a/management-panel/app/Filament/Widgets/SystemStats.php b/management-panel/app/Filament/Widgets/SystemStats.php
index 13435a6..36eca7d 100644
--- a/management-panel/app/Filament/Widgets/SystemStats.php
+++ b/management-panel/app/Filament/Widgets/SystemStats.php
@@ -56,7 +56,7 @@ class SystemStats extends BaseWidget
return $item['value'][1] ?? 0;
}, $networkReceiveResult['data']['result'])) / (1024 * 1024), 2);
- $networkDisplay = "上行: {$networkTransmit} MB/s\n下行: {$networkReceive} MB/s";
+ $networkDisplay = "上传: {$networkTransmit} MB/s\n下载: {$networkReceive} MB/s";
return [
BaseWidget\Stat::make('内存占用', $memoryDisplay),