系统信息显示功能实装(3/3)

*前端实现
This commit is contained in:
Chenx221 2024-04-15 16:10:28 +08:00
parent 2a20dea8cf
commit 636d7d0605
Signed by: chenx221
GPG Key ID: D7A9EC07024C3021
3 changed files with 206 additions and 98 deletions

View File

@ -12,6 +12,7 @@ use yii\web\View;
FontAwesomeAsset::register($this); FontAwesomeAsset::register($this);
EChartsAsset::register($this); EChartsAsset::register($this);
$this->registerCssFile('@web/css/sysinfo-style.css');
$this->title = '系统信息'; $this->title = '系统信息';
?> ?>
@ -55,9 +56,9 @@ $this->title = '系统信息';
</p> </p>
</div> </div>
<hr> <hr>
<div> <div class="row">
<?php if ($systemInfo->osType === 2): ?> <?php if ($systemInfo->osType === 2): ?>
<div> <div class="col-xxl-6">
<h2> <h2>
<i class="fa-solid fa-bars-progress"></i> <i class="fa-solid fa-bars-progress"></i>
Load Load
@ -70,7 +71,7 @@ $this->title = '系统信息';
</p> </p>
</div> </div>
<?php endif; ?> <?php endif; ?>
<div> <div class="col-xxl-6">
<h2> <h2>
<i class="fa-solid fa-microchip"></i> <i class="fa-solid fa-microchip"></i>
CPU CPU
@ -82,7 +83,7 @@ $this->title = '系统信息';
CPU Usage: <span id="rdata_cpuUsage"><?= $systemInfo->cpuUsage ?></span>% CPU Usage: <span id="rdata_cpuUsage"><?= $systemInfo->cpuUsage ?></span>%
</p> </p>
</div> </div>
<div> <div class="col-xxl-6">
<h2> <h2>
<i class="fa-solid fa-memory"></i> <i class="fa-solid fa-memory"></i>
Memory Memory
@ -106,12 +107,14 @@ $this->title = '系统信息';
Disk Disk
</h2> </h2>
</div> </div>
<div> <div class="row">
<div> <div class="row col-md-6 group-content">
<!-- disk chart --> <!-- disk chart -->
<div id="disk-chart" style="width: 600px;height:400px;"> <div class="col-xl-6">
<div id="disk-chart" style="width: 300px;height:250px;">
</div>
</div> </div>
<div> <div class="col-xl-6" style="padding-top: 50px">
<h3>Data</h3> <h3>Data</h3>
Mount: Mount:
<span id="rdata_dataMountPoint"><?= $systemInfo->dataMountPoint ?></span> <span id="rdata_dataMountPoint"><?= $systemInfo->dataMountPoint ?></span>
@ -149,70 +152,71 @@ $this->title = '系统信息';
Gateway: Gateway:
<span id="rdata_gateway"><?= $systemInfo->gateway ?></span> <span id="rdata_gateway"><?= $systemInfo->gateway ?></span>
</p> </p>
<div> <br>
<div> <div class="row">
<div> <div class="group-content col-md-4">
<h3 id="rdata_interfaceName"><?= $systemInfo->nic['interfaceName'] ?></h3> <h3 id="rdata_interfaceName"><?= $systemInfo->nic['interfaceName'] ?></h3>
MAC: MAC:
<span id="rdata_mac"><?= $systemInfo->nic['mac'] ?></span> <span id="rdata_mac"><?= $systemInfo->nic['mac'] ?></span>
<br> <br>
Speed: Speed:
<span id="rdata_speed"><?= $systemInfo->nic['speed'] ?></span> <span id="rdata_speed"><?= $systemInfo->nic['speed'] ?></span>
<br> <br>
IPv4: IPv4:
<span id="rdata_ipv4"><?= $systemInfo->nic['ipv4'] ?></span> <span id="rdata_ipv4"><?= $systemInfo->nic['ipv4'] ?></span>
<br> <br>
IPv6: IPv6:
<span id="rdata_ipv6"><?= $systemInfo->nic['ipv6'] ?></span> <span id="rdata_ipv6"><?= $systemInfo->nic['ipv6'] ?></span>
</div>
</div> </div>
</div> </div>
</div> </div>
<hr> <hr>
<div> <div class="row">
<h2> <div class="col-md-4">
<i class="fa-solid fa-users"></i> <h2>
Active Users <i class="fa-solid fa-users"></i>
</h2> Active Users
<div> </h2>
All: <div class="group-content">
<span id="rdata_users"><?= $systemInfo->users ?></span> All:
<br> <span id="rdata_users"><?= $systemInfo->users ?></span>
Active (within 24h): <br>
<span id="rdata_activeUsers"><?= $systemInfo->activeUsers ?></span> Active (within 24h):
<span id="rdata_activeUsers"><?= $systemInfo->activeUsers ?></span>
</div>
</div> </div>
</div> </div>
<hr> <hr>
<div> <div class="row">
<div> <div class="col-md-4">
<h2> <h2>
<i class="fa-solid fa-share-nodes"></i> <i class="fa-solid fa-share-nodes"></i>
Share Share
</h2> </h2>
<div> <div class="group-content">
Link: Link:
<span id="rdata_shares"><?= $systemInfo->shares ?></span> <span id="rdata_shares"><?= $systemInfo->shares ?></span>
</div> </div>
</div> </div>
<div> <div class="col-md-4">
<h2> <h2>
<i class="fa-solid fa-paper-plane"></i> <i class="fa-solid fa-paper-plane"></i>
Collection Collection
</h2> </h2>
<div> <div class="group-content">
Collection: Link:
<span id="rdata_collections"><?= $systemInfo->collections ?></span> <span id="rdata_collections"><?= $systemInfo->collections ?></span>
</div> </div>
</div> </div>
</div> </div>
<hr> <hr>
<div> <div class="row">
<div> <div class="col-md-6">
<h2> <h2>
<i class="fa-brands fa-php"></i> <i class="fa-brands fa-php"></i>
PHP PHP
</h2> </h2>
<div> <div class="group-content">
Version: Version:
<span id="rdata_phpVersion"><?= $systemInfo->phpVersion ?></span> <span id="rdata_phpVersion"><?= $systemInfo->phpVersion ?></span>
<br> <br>
@ -232,12 +236,12 @@ $this->title = '系统信息';
<span id="rdata_extensions"><?= $systemInfo->extensions ?></span> <span id="rdata_extensions"><?= $systemInfo->extensions ?></span>
</div> </div>
</div> </div>
<div> <div class="col-md-6">
<h2> <h2>
<i class="fa-solid fa-database"></i> <i class="fa-solid fa-database"></i>
Database Database
</h2> </h2>
<div> <div class="group-content">
Type: Type:
<span id="rdata_dbType"><?= $systemInfo->dbType ?></span> <span id="rdata_dbType"><?= $systemInfo->dbType ?></span>
<br> <br>
@ -268,7 +272,7 @@ var option = {
xAxis: { xAxis: {
type: 'category', type: 'category',
boundaryGap: false, boundaryGap: false,
data: ["$dataTime","16:51:49"] data: ["$dataTime"]
}, },
yAxis: { yAxis: {
type: 'value', type: 'value',
@ -278,12 +282,14 @@ var option = {
series: [ series: [
{ {
'name': 'CPU', 'name': 'CPU',
data: [$systemInfo->cpuUsage,50], data: [$systemInfo->cpuUsage],
label: { label: {
show: true, show: true,
position: 'top', position: 'top',
formatter: '{c}%', formatter: '{c}%'
emphasis: { },
emphasis: {
label: {
scale: 1.5 scale: 1.5
} }
}, },
@ -302,7 +308,7 @@ if(needLoadGraph !== null){
xAxis: { xAxis: {
type: 'category', type: 'category',
boundaryGap: false, boundaryGap: false,
data: ["$dataTime","16:51:49"] data: ["$dataTime"]
}, },
yAxis: { yAxis: {
type: 'value', type: 'value',
@ -312,12 +318,14 @@ if(needLoadGraph !== null){
series: [ series: [
{ {
'name': 'Load', 'name': 'Load',
data: [$systemInfo->load,50], data: [$systemInfo->load],
label: { label: {
show: true, show: true,
position: 'top', position: 'top',
formatter: '{c}%', formatter: '{c}%'
emphasis: { },
emphasis: {
label: {
scale: 1.5 scale: 1.5
} }
}, },
@ -336,7 +344,7 @@ var option2 = {
xAxis: { xAxis: {
type: 'category', type: 'category',
boundaryGap: false, boundaryGap: false,
data: ["$dataTime","16:51:49"] data: ["$dataTime"]
}, },
yAxis: { yAxis: {
type: 'value', type: 'value',
@ -346,7 +354,7 @@ var option2 = {
series: [ series: [
{ {
name: 'RAM', name: 'RAM',
data: [$systemInfo->ramUsage,50], data: [$systemInfo->ramUsage],
type: 'line', type: 'line',
areaStyle: {}, areaStyle: {},
smooth: true, smooth: true,
@ -357,14 +365,16 @@ var option2 = {
show: true, show: true,
position: 'top', position: 'top',
formatter: '{c}%', formatter: '{c}%',
emphasis: { },
emphasis: {
label: {
scale: 1.5 scale: 1.5
} }
} }
}, },
{ {
name: 'SWAP', name: 'SWAP',
data: [$systemInfo->swapUsage,90], data: [$systemInfo->swapUsage],
type: 'line', type: 'line',
areaStyle: {}, areaStyle: {},
smooth: true, smooth: true,
@ -374,11 +384,13 @@ var option2 = {
label: { label: {
show: true, show: true,
position: 'bottom', position: 'bottom',
formatter: '{c}%', formatter: '{c}%'
emphasis: { },
emphasis: {
label: {
scale: 1.5 scale: 1.5
} }
} },
} }
] ]
}; };

24
web/css/sysinfo-style.css Normal file
View File

@ -0,0 +1,24 @@
.system-info p{
margin-bottom: 0;
}
.system-info h2{
margin-top: 22px;
margin-bottom: 22px;
}
.system-info .group-content{
border: 2px solid #ededed;
border-radius:10px;
padding: 16px;
}
.system-info .group-content span{
color: #6b6b6b;
}
#load-graph,#cpu-graph,#memory-graph{
padding-top: 35px;
border: 2px solid #ededed;
border-radius:10px;
}
#disk-chart{
padding-top: 10px;
}

View File

@ -5,63 +5,135 @@
var sysinfo = { var sysinfo = {
init: function () { init: function () {
setInterval(sysinfo.fetch, 5000); setInterval(sysinfo.fetch, 2000);
// WARNING
// For Windows users, the interval should be equal or greater than 1500ms, because the system information gathering process is slow. (Please dynamically adjust the interval based on system performance.)
// For Linux users, the interval can be set to below 1000ms.
}, },
fetch: function () { fetch: function () {
$.ajax({ $.ajax({
url: '/admin/get-sysinfo', url: 'index.php?r=admin%2Fget-sysinfo',
type: 'GET', type: 'GET',
dataType: 'json', dataType: 'json',
success: function (data) { success: function (data) {
sysinfo.display(data); sysinfo.display(data);
},
error: function (xhr, status, error) {
console.log('Error: ' + error.message);
} }
}); });
}, },
display: function (data) { display: function (data) {
//TODO: display system information // serverTime
$('#rdata_serverTime').text(data.serverTime);
// serverUpTime
$('#rdata_serverUpTime').text(data.serverUpTime);
// load
$('#rdata_load').text(data.load);
// cpuUsage
$('#rdata_cpuUsage').text(data.cpuUsage);
// ramUsage
$('#rdata_ramUsage').text(data.ramUsage);
// swapUsage
$('#rdata_swapUsage').text(data.swapUsage);
// mp_avail
$('#rdata_mp_avail').text(data.mp_avail);
// mp_used
$('#rdata_mp_used').text(data.mp_used);
// mp_usage
$('#rdata_mp_usage').text(data.mp_usage);
// cpu graph
var cpuData_x = myChart.getOption().xAxis[0].data;
var cpuData = myChart.getOption().series[0].data;
cpuData_x.push(data.serverTime.substr(11, 8));
cpuData.push(data.cpuUsage);
if (cpuData_x.length > 10) {
cpuData_x.shift();
}
if (cpuData.length > 10) {
cpuData.shift();
}
myChart.setOption({
xAxis: [{
data: cpuData_x
}],
series: [{
data: cpuData
}]
})
// load graph
if (data.osType === 1) {
var loadData_x = myChart1.getOption().xAxis[0].data;
var loadData = myChart1.getOption().series[0].data;
loadData_x.push(data.serverTime.substr(11, 8));
loadData.push(data.load);
if (loadData_x.length > 10) {
loadData_x.shift();
}
if (loadData.length > 10) {
loadData.shift();
}
myChart1.setOption({
xAxis: [{
data: loadData_x
}],
series: [{
data: loadData
}]
});
}
// memory graph
var memoryData_x = myChart2.getOption().xAxis[0].data;
var memoryData = myChart2.getOption().series[0].data;
var swapData = myChart2.getOption().series[1].data;
memoryData_x.push(data.serverTime.substr(11, 8));
memoryData.push(data.ramUsage);
swapData.push(data.swapUsage);
if (memoryData_x.length > 10) {
memoryData_x.shift();
}
if (memoryData.length > 10) {
memoryData.shift();
}
if (swapData.length > 10) {
swapData.shift();
}
myChart2.setOption({
xAxis: [{
data: memoryData_x
}],
series: [{
data: memoryData
},{
data: swapData
}]
});
// disk chart
var free = 100-data.mp_usage;
myChart3.setOption({
series: [{
data: [
{ value: data.mp_usage, name: 'Used Space' },
{ value: free, name: 'Free Space' }
]
}]
});
} }
} }
sysinfo.init();
// *Some data need to display // *Some data need to refresh display
// rdata_hostname: hostname
// rdata_os: os
// rdata_cpu: cpu
// rdata_ram: ram
// rdata_serverTime: serverTime // rdata_serverTime: serverTime
// rdata_serverUpTime: serverUpTime // rdata_serverUpTime: serverUpTime
// (osType ==2) rdata_load: load // (osType ==2) rdata_load: load
// rdata_cpuUsage: cpuUsage // rdata_cpuUsage: cpuUsage
// rdata_ramUsage: ramUsage // rdata_ramUsage: ramUsage
// rdata_swapUsage: swapUsage // rdata_swapUsage: swapUsage
// rdata_dataMountPoint: dataMountPoint
// rdata_mp_fs: mp_fs
// rdata_mp_size: mp_size
// rdata_mp_avail: mp_avail // rdata_mp_avail: mp_avail
// rdata_mp_used: mp_used // rdata_mp_used: mp_used
// rdata_mp_usage: mp_usage // rdata_mp_usage: mp_usage
// rdata_hostname2: hostname
// rdata_dns: dns
// rdata_gateway: gateway
// rdata_interfaceName: nic[interfaceName]
// rdata_mac: nic[mac]
// rdata_speed: nic[speed]
// rdata_ipv4: nic[ipv4]
// rdata_ipv6: nic[ipv6]
// rdata_users: users
// rdata_activeUsers: activeUsers
// rdata_shares: shares
// rdata_collections: collections
// rdata_phpVersion: phpVersion
// rdata_memoryLimit: memoryLimit
// rdata_maxExecutionTime: maxExecutionTime
// rdata_uploadMaxFilesize: uploadMaxFilesize
// rdata_postMaxSize: postMaxSize
// rdata_extensions: extensions
// rdata_dbType: dbType
// rdata_dbVersion: dbVersion
// rdata_dbSize: dbSize
// var myChart = echarts.init(document.getElementById('cpu-graph'));
// var myChart1 = echarts.init(document.getElementById('load-graph'));
// var myChart2 = echarts.init(document.getElementById('memory-graph'));
// var myChart3 = echarts.init(document.getElementById('disk-chart'));