[增添]添加了系统设备数据显示stats widget
This commit is contained in:
18
.idea/workspace.xml
generated
18
.idea/workspace.xml
generated
@@ -4,7 +4,7 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="596fb1a0-d6fb-4db8-a922-13b01593ce79" name="更改" comment="[修改]删除了updatetoetcd的page页面、widget排布">
|
||||
<list default="true" id="596fb1a0-d6fb-4db8-a922-13b01593ce79" name="更改" comment="[修改]优化了widget的读取显示,能够动态显示">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/management-panel/app/Filament/Widgets/PrometheusMemory.php" beforeDir="false" afterPath="$PROJECT_DIR$/management-panel/app/Filament/Widgets/PrometheusMemory.php" afterDir="false" />
|
||||
</list>
|
||||
@@ -257,7 +257,8 @@
|
||||
<workItem from="1724743649380" duration="22000" />
|
||||
<workItem from="1724743707590" duration="5840000" />
|
||||
<workItem from="1724806979170" duration="149000" />
|
||||
<workItem from="1724808563307" duration="17382000" />
|
||||
<workItem from="1724808563307" duration="17821000" />
|
||||
<workItem from="1724893742147" duration="5355000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="[增添]添加注册">
|
||||
<option name="closed" value="true" />
|
||||
@@ -387,7 +388,15 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1724832839806</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="17" />
|
||||
<task id="LOCAL-00017" summary="[修改]优化了widget的读取显示,能够动态显示">
|
||||
<option name="closed" value="true" />
|
||||
<created>1724835277301</created>
|
||||
<option name="number" value="00017" />
|
||||
<option name="presentableId" value="LOCAL-00017" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1724835277301</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="18" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
@@ -449,6 +458,7 @@
|
||||
<MESSAGE value="[增添]添加了Prometheus服务、对应的widget展示(待美化)" />
|
||||
<MESSAGE value="[修改]修改美化了了widget样式,折线图展示" />
|
||||
<MESSAGE value="[修改]删除了updatetoetcd的page页面、widget排布" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="[修改]删除了updatetoetcd的page页面、widget排布" />
|
||||
<MESSAGE value="[修改]优化了widget的读取显示,能够动态显示" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="[修改]优化了widget的读取显示,能够动态显示" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -7,7 +7,7 @@ use Filament\Widgets\ChartWidget;
|
||||
|
||||
class PrometheusMemory extends ChartWidget
|
||||
{
|
||||
protected static ?int $sort = 3;
|
||||
protected static ?int $sort = 4;
|
||||
|
||||
protected static ?string $heading = '内存占用率';
|
||||
|
||||
@@ -44,7 +44,7 @@ class PrometheusMemory extends ChartWidget
|
||||
'borderColor' => '#4CAF50',
|
||||
'backgroundColor' => 'rgba(76, 175, 80, 0.2)',
|
||||
'fill' => true,
|
||||
'tension' => 0.4,
|
||||
'tension' => 0.2,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
74
management-panel/app/Filament/Widgets/SystemStats.php
Normal file
74
management-panel/app/Filament/Widgets/SystemStats.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Services\PrometheusService;
|
||||
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
|
||||
|
||||
class SystemStats extends BaseWidget
|
||||
{
|
||||
protected static ?int $sort = 3;
|
||||
|
||||
protected function getCards(): array
|
||||
{
|
||||
$prometheus = new PrometheusService();
|
||||
|
||||
// 获取内存总量
|
||||
$memoryTotalQuery = 'node_memory_MemTotal_bytes';
|
||||
$memoryTotalResult = $prometheus->query($memoryTotalQuery);
|
||||
$memoryTotal = $memoryTotalResult['data']['result'][0]['value'][1] ?? 0;
|
||||
|
||||
// 获取已用内存
|
||||
$memoryAvailableQuery = 'node_memory_MemAvailable_bytes';
|
||||
$memoryAvailableResult = $prometheus->query($memoryAvailableQuery);
|
||||
$memoryAvailable = $memoryAvailableResult['data']['result'][0]['value'][1] ?? 0;
|
||||
|
||||
$memoryUsed = $memoryTotal - $memoryAvailable;
|
||||
$memoryDisplay = round($memoryUsed / (1024 * 1024 * 1024), 2) . ' GB / ' . round($memoryTotal / (1024 * 1024 * 1024), 2) . ' GB';
|
||||
|
||||
// 获取硬盘总量
|
||||
$diskTotalQuery = 'node_filesystem_size_bytes{fstype!="rootfs",fstype!="tmpfs",fstype!="squashfs"}';
|
||||
$diskTotalResult = $prometheus->query($diskTotalQuery);
|
||||
$diskTotal = array_sum(array_map(function ($item) {
|
||||
return $item['value'][1] ?? 0;
|
||||
}, $diskTotalResult['data']['result']));
|
||||
|
||||
// 获取已用硬盘
|
||||
$diskFreeQuery = 'node_filesystem_free_bytes{fstype!="rootfs",fstype!="tmpfs",fstype!="squashfs"}';
|
||||
$diskFreeResult = $prometheus->query($diskFreeQuery);
|
||||
$diskFree = array_sum(array_map(function ($item) {
|
||||
return $item['value'][1] ?? 0;
|
||||
}, $diskFreeResult['data']['result']));
|
||||
|
||||
$diskUsed = $diskTotal - $diskFree;
|
||||
$diskDisplay = round($diskUsed / (1024 * 1024 * 1024), 2) . ' GB / ' . round($diskTotal / (1024 * 1024 * 1024), 2) . ' GB';
|
||||
|
||||
// 获取网络上下行流量
|
||||
$networkTransmitQuery = 'rate(node_network_transmit_bytes_total[1m])';
|
||||
$networkTransmitResult = $prometheus->query($networkTransmitQuery);
|
||||
$networkTransmit = round(array_sum(array_map(function ($item) {
|
||||
return $item['value'][1] ?? 0;
|
||||
}, $networkTransmitResult['data']['result'])) / (1024 * 1024), 2);
|
||||
|
||||
$networkReceiveQuery = 'rate(node_network_receive_bytes_total[1m])';
|
||||
$networkReceiveResult = $prometheus->query($networkReceiveQuery);
|
||||
$networkReceive = round(array_sum(array_map(function ($item) {
|
||||
return $item['value'][1] ?? 0;
|
||||
}, $networkReceiveResult['data']['result'])) / (1024 * 1024), 2);
|
||||
|
||||
$networkDisplay = "上行: {$networkTransmit} MB/s\n下行: {$networkReceive} MB/s";
|
||||
|
||||
return [
|
||||
BaseWidget\Stat::make('内存占用', $memoryDisplay),
|
||||
BaseWidget\Stat::make('硬盘占用', $diskDisplay),
|
||||
BaseWidget\Stat::make('网络流量', $networkDisplay),
|
||||
];
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function getPollingInterval(): ?string
|
||||
{
|
||||
return "1s";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user