From a6dd4ad2771e565a12d743063f8cc5f0fe1ac9fa Mon Sep 17 00:00:00 2001
From: makotocc0107 <1424018999@qq.com>
Date: Wed, 28 Aug 2024 16:54:37 +0800
Subject: [PATCH] =?UTF-8?q?[=E4=BF=AE=E6=94=B9]=E4=BC=98=E5=8C=96=E4=BA=86?=
=?UTF-8?q?widget=E7=9A=84=E8=AF=BB=E5=8F=96=E6=98=BE=E7=A4=BA=EF=BC=8C?=
=?UTF-8?q?=E8=83=BD=E5=A4=9F=E5=8A=A8=E6=80=81=E6=98=BE=E7=A4=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.idea/workspace.xml | 21 ++++++++++++-------
.../app/Filament/Widgets/PrometheusMemory.php | 12 +++++++----
2 files changed, 21 insertions(+), 12 deletions(-)
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 075570f..3b30406 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,13 +4,9 @@
-
+
-
-
-
-
@@ -261,7 +257,7 @@
-
+
@@ -383,7 +379,15 @@
1724831975781
-
+
+
+ 1724832839806
+
+
+
+ 1724832839806
+
+
@@ -444,6 +448,7 @@
-
+
+
\ No newline at end of file
diff --git a/management-panel/app/Filament/Widgets/PrometheusMemory.php b/management-panel/app/Filament/Widgets/PrometheusMemory.php
index 4cb08b8..c734018 100644
--- a/management-panel/app/Filament/Widgets/PrometheusMemory.php
+++ b/management-panel/app/Filament/Widgets/PrometheusMemory.php
@@ -15,19 +15,22 @@ class PrometheusMemory extends ChartWidget
{
$prometheus = new PrometheusService();
+
+// 查询过去 1 分钟内的每 6 秒一个数据点
$memoryUsageRange = $prometheus->queryRange(
- '(1 - (avg_over_time(node_memory_MemAvailable_bytes[1h]) / avg_over_time(node_memory_MemTotal_bytes[1h]))) * 100',
- now()->subHour()->timestamp,
+ '(1 - (avg_over_time(node_memory_MemAvailable_bytes[1m]) / avg_over_time(node_memory_MemTotal_bytes[1m]))) * 100',
+ now()->subMinutes(1)->timestamp,
now()->timestamp,
- 360 // 每6分钟一个数据点
+ 6 // 每6秒一个数据点
);
$labels = [];
$data = [];
if (!empty($memoryUsageRange['data']['result'][0]['values'])) {
+ date_default_timezone_set('Asia/Shanghai');
foreach ($memoryUsageRange['data']['result'][0]['values'] as $index => $value) {
- $labels[] = 'Point ' . ($index + 1);
+ $labels[] = date('H:i:s', $value[0]); // 格式化时间戳为小时:分钟:秒
$data[] = round($value[1], 2); // 取出每个时间点的内存使用率,并保留两位小数
}
}
@@ -41,6 +44,7 @@ class PrometheusMemory extends ChartWidget
'borderColor' => '#4CAF50',
'backgroundColor' => 'rgba(76, 175, 80, 0.2)',
'fill' => true,
+ 'tension' => 0.4,
],
],
];