[增添]添加了CPU核心数量显示stat

This commit is contained in:
makotocc0107
2024-08-30 09:44:05 +08:00
committed by Coding
parent a3566a1449
commit 500c0f9f7d
3 changed files with 49 additions and 22 deletions

45
.idea/workspace.xml generated
View File

@@ -4,8 +4,9 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="596fb1a0-d6fb-4db8-a922-13b01593ce79" name="更改" comment="[增添]添加了系统设备数据显示stats widget"> <list default="true" id="596fb1a0-d6fb-4db8-a922-13b01593ce79" name="更改" comment="[增添]添加了CPU占用率饼图">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <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/CPUStatus.php" beforeDir="false" afterPath="$PROJECT_DIR$/management-panel/app/Filament/Widgets/CPUStatus.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/management-panel/app/Filament/Widgets/SystemStats.php" beforeDir="false" afterPath="$PROJECT_DIR$/management-panel/app/Filament/Widgets/SystemStats.php" afterDir="false" /> <change beforePath="$PROJECT_DIR$/management-panel/app/Filament/Widgets/SystemStats.php" beforeDir="false" afterPath="$PROJECT_DIR$/management-panel/app/Filament/Widgets/SystemStats.php" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
@@ -195,20 +196,20 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent">{
"keyToString": { &quot;keyToString&quot;: {
"RunOnceActivity.ShowReadmeOnStart": "true", &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
"git-widget-placeholder": "master", &quot;git-widget-placeholder&quot;: &quot;master&quot;,
"last_opened_file_path": "E:/data-collection-terminal", &quot;last_opened_file_path&quot;: &quot;E:/data-collection-terminal&quot;,
"node.js.detected.package.eslint": "true", &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
"node.js.detected.package.tslint": "true", &quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
"node.js.selected.package.eslint": "(autodetect)", &quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
"node.js.selected.package.tslint": "(autodetect)", &quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
"nodejs_package_manager_path": "npm", &quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
"php.override.implement.member.chooser.php.doc": "NONE", &quot;php.override.implement.member.chooser.php.doc&quot;: &quot;NONE&quot;,
"vue.rearranger.settings.migration": "true" &quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
} }
}]]></component> }</component>
<component name="RecentsManager"> <component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS"> <key name="CopyFile.RECENT_KEYS">
<recent name="E:\data-collection-terminal\management-panel\app" /> <recent name="E:\data-collection-terminal\management-panel\app" />
@@ -259,7 +260,8 @@
<workItem from="1724743707590" duration="5840000" /> <workItem from="1724743707590" duration="5840000" />
<workItem from="1724806979170" duration="149000" /> <workItem from="1724806979170" duration="149000" />
<workItem from="1724808563307" duration="17821000" /> <workItem from="1724808563307" duration="17821000" />
<workItem from="1724893742147" duration="12344000" /> <workItem from="1724893742147" duration="20821000" />
<workItem from="1724979664477" duration="2248000" />
</task> </task>
<task id="LOCAL-00001" summary="[增添]添加注册"> <task id="LOCAL-00001" summary="[增添]添加注册">
<option name="closed" value="true" /> <option name="closed" value="true" />
@@ -405,7 +407,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1724899660126</updated> <updated>1724899660126</updated>
</task> </task>
<option name="localTasksCounter" value="19" /> <task id="LOCAL-00019" summary="[增添]添加了CPU占用率饼图">
<option name="closed" value="true" />
<created>1724913340798</created>
<option name="number" value="00019" />
<option name="presentableId" value="LOCAL-00019" />
<option name="project" value="LOCAL" />
<updated>1724913340798</updated>
</task>
<option name="localTasksCounter" value="20" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@@ -469,6 +479,7 @@
<MESSAGE value="[修改]删除了updatetoetcd的page页面、widget排布" /> <MESSAGE value="[修改]删除了updatetoetcd的page页面、widget排布" />
<MESSAGE value="[修改]优化了widget的读取显示能够动态显示" /> <MESSAGE value="[修改]优化了widget的读取显示能够动态显示" />
<MESSAGE value="[增添]添加了系统设备数据显示stats widget" /> <MESSAGE value="[增添]添加了系统设备数据显示stats widget" />
<option name="LAST_COMMIT_MESSAGE" value="[增添]添加了系统设备数据显示stats widget" /> <MESSAGE value="[增添]添加了CPU占用率饼图" />
<option name="LAST_COMMIT_MESSAGE" value="[增添]添加了CPU占用率饼图" />
</component> </component>
</project> </project>

View File

@@ -39,8 +39,8 @@ class CPUStatus extends ChartWidget
[ [
'label' => 'CPU 占用情况', 'label' => 'CPU 占用情况',
'data' => $data, 'data' => $data,
'backgroundColor' => ['#FBD1B7', '#E0F5B9'], // 柔和颜色 'backgroundColor' => ['#FF8080', '#E0F5B9'], // 柔和颜色
'borderColor' => ['#FBD1B7', '#E0F5B9'], // 边框颜色 'borderColor' => ['#FF8080', '#E0F5B9'], // 边框颜色
'borderWidth' => 1, // 边框宽度 'borderWidth' => 1, // 边框宽度
], ],
], ],

View File

@@ -43,6 +43,8 @@ class SystemStats extends BaseWidget
$diskUsed = $diskTotal - $diskFree; $diskUsed = $diskTotal - $diskFree;
$diskDisplay = round($diskUsed / (1024 * 1024 * 1024), 2) . ' GB / ' . round($diskTotal / (1024 * 1024 * 1024), 2) . ' GB'; $diskDisplay = round($diskUsed / (1024 * 1024 * 1024), 2) . ' GB / ' . round($diskTotal / (1024 * 1024 * 1024), 2) . ' GB';
// 注释掉网络流量部分
/*
// 获取网络上下行流量 // 获取网络上下行流量
$networkTransmitQuery = 'rate(node_network_transmit_bytes_total[1m])'; $networkTransmitQuery = 'rate(node_network_transmit_bytes_total[1m])';
$networkTransmitResult = $prometheus->query($networkTransmitQuery); $networkTransmitResult = $prometheus->query($networkTransmitQuery);
@@ -57,14 +59,28 @@ class SystemStats extends BaseWidget
}, $networkReceiveResult['data']['result'])) / (1024 * 1024), 2); }, $networkReceiveResult['data']['result'])) / (1024 * 1024), 2);
$networkDisplay = "上传: {$networkTransmit} MB/s\n下载: {$networkReceive} MB/s"; $networkDisplay = "上传: {$networkTransmit} MB/s\n下载: {$networkReceive} MB/s";
*/
// 获取系统启动时间
$uptimeQuery = 'node_boot_time_seconds';
$uptimeResult = $prometheus->query($uptimeQuery);
$bootTime = $uptimeResult['data']['result'][0]['value'][1] ?? 0;
$uptime = now()->timestamp - $bootTime;
$uptimeDisplay = gmdate('H:i:s', $uptime);
// 获取CPU核心数量
$cpuCoresQuery = 'count(node_cpu_seconds_total{mode="system"})';
$cpuCoresResult = $prometheus->query($cpuCoresQuery);
$cpuCores = $cpuCoresResult['data']['result'][0]['value'][1] ?? 0;
return [ return [
BaseWidget\Stat::make('内存占用', $memoryDisplay), BaseWidget\Stat::make('内存占用', $memoryDisplay),
BaseWidget\Stat::make('硬盘占用', $diskDisplay), BaseWidget\Stat::make('硬盘占用', $diskDisplay),
BaseWidget\Stat::make('网络流量', $networkDisplay), BaseWidget\Stat::make('系统运行时间', $uptimeDisplay),
BaseWidget\Stat::make('CPU核心数量', $cpuCores)
]; ];
} }
protected function getPollingInterval(): ?string protected function getPollingInterval(): ?string