diff --git a/controllers/AdminController.php b/controllers/AdminController.php
index b56b7fc..893496f 100644
--- a/controllers/AdminController.php
+++ b/controllers/AdminController.php
@@ -596,8 +596,8 @@ class AdminController extends Controller
* Get server status
* @return void
*/
- public function actionGetServerStatus(): void
+ public function actionGetSysinfo(): void
{
-
+ //TODO: Implement this method
}
}
diff --git a/utils/SystemInfoHelper.php b/utils/SystemInfoHelper.php
index ca4ff5b..d0f1e50 100644
--- a/utils/SystemInfoHelper.php
+++ b/utils/SystemInfoHelper.php
@@ -568,8 +568,6 @@ class SystemInfoHelper
$sysInfo->detectRam();
$sysInfo->detectServerTime();
$sysInfo->detectServerUptime();
-
-
$sysInfo->detectCpuUsage();
$sysInfo->detectRamUsage();
$sysInfo->detectDataMountPoint();
@@ -593,16 +591,7 @@ class SystemInfoHelper
public static function getSysInfoFre(): SystemInfoHelper
{
$sysInfo = new SystemInfoHelper();
- $sysInfo->detectServerTime();
- $sysInfo->detectServerUptime();
- if ($sysInfo->osType === 1) {
- $sysInfo->detectLoad();
- } else {
- $sysInfo->load = -1;
- }
- $sysInfo->detectCpuUsage();
- $sysInfo->detectRamUsage();
- $sysInfo->detectDataMountPoint();
+ // TODO: Implement getSysInfoFre() method.
return $sysInfo;
}
diff --git a/views/admin/sysinfo.php b/views/admin/sysinfo.php
index f7ae327..396a3eb 100644
--- a/views/admin/sysinfo.php
+++ b/views/admin/sysinfo.php
@@ -3,11 +3,15 @@
/* @var $systemInfo SystemInfoHelper */
+use app\assets\EChartsAsset;
use app\assets\FontAwesomeAsset;
use app\utils\SystemInfoHelper;
use yii\bootstrap5\Html;
+use yii\web\JqueryAsset;
+use yii\web\View;
FontAwesomeAsset::register($this);
+EChartsAsset::register($this);
$this->title = '系统信息';
?>
@@ -27,27 +31,27 @@ $this->title = '系统信息';
- = $systemInfo->hostname ?>
+ = $systemInfo->hostname ?>
OS:
- = $systemInfo->os ?>
+ = $systemInfo->os ?>
CPU:
- = $systemInfo->cpu ?>
+ = $systemInfo->cpu ?>
RAM:
- = $systemInfo->ram ?>
+ = $systemInfo->ram ?>
Server Time:
- = $systemInfo->serverTime ?>
+ = $systemInfo->serverTime ?>
Server Up Time:
- = $systemInfo->serverUpTime ?>
+ = $systemInfo->serverUpTime ?>
@@ -59,8 +63,10 @@ $this->title = '系统信息';
Load
+
+
- Load Average: = $systemInfo->load ?> (Last 1 min)
+ Load Average: = $systemInfo->load ?> (Last 1 min)
@@ -70,8 +76,10 @@ $this->title = '系统信息';
CPU
+
+
- CPU Usage: = $systemInfo->cpuUsage ?>%
+ CPU Usage: = $systemInfo->cpuUsage ?>%
@@ -80,11 +88,13 @@ $this->title = '系统信息';
Memory
+
+
- Memory Usage: = $systemInfo->ramUsage ?>%
+ Memory Usage: = $systemInfo->ramUsage ?>%
- Swap Usage: = $systemInfo->swapUsage ?>%
+ Swap Usage: = $systemInfo->swapUsage ?>%
@@ -99,143 +109,318 @@ $this->title = '系统信息';
-
-
-
Data
- Mount:
-
= $systemInfo->dataMountPoint ?>
-
- File System:
-
= $systemInfo->mp_fs ?>
-
- Size:
-
= $systemInfo->mp_size ?>
-
- Free:
-
= $systemInfo->mp_avail ?>
-
- Used:
-
= $systemInfo->mp_used ?> (= $systemInfo->mp_usage ?>%)
+
+
+
+
Data
+ Mount:
+ = $systemInfo->dataMountPoint ?>
+
+ File System:
+ = $systemInfo->mp_fs ?>
+
+ Size:
+ = $systemInfo->mp_size ?>
+
+ Free:
+ = $systemInfo->mp_avail ?>
+
+ Used:
+ = $systemInfo->mp_used ?> (= $systemInfo->mp_usage ?>%)
+
-
-
-
-
-
- Network
-
-
- Hostname:
- = $systemInfo->hostname ?>
-
-
- DNS:
- = $systemInfo->dns ?>
-
-
- Gateway:
- = $systemInfo->gateway ?>
-
+
+
+
+ Network
+
+
+ Hostname:
+ = $systemInfo->hostname ?>
+
+
+ DNS:
+ = $systemInfo->dns ?>
+
+
+ Gateway:
+ = $systemInfo->gateway ?>
+
-
= $systemInfo->nic['interfaceName'] ?>
- MAC:
-
= $systemInfo->nic['mac'] ?>
+
+
= $systemInfo->nic['interfaceName'] ?>
+ MAC:
+ = $systemInfo->nic['mac'] ?>
+
+ Speed:
+ = $systemInfo->nic['speed'] ?>
+
+ IPv4:
+ = $systemInfo->nic['ipv4'] ?>
+
+ IPv6:
+ = $systemInfo->nic['ipv6'] ?>
+
+
+
+
+
+
+
+
+ Active Users
+
+
+ All:
+ = $systemInfo->users ?>
+
+ Active (within 24h):
+ = $systemInfo->activeUsers ?>
+
+
+
+
+
+
+
+ Share
+
+
+ Link:
+ = $systemInfo->shares ?>
+
+
+
+
+
+ Collection
+
+
+ Collection:
+ = $systemInfo->collections ?>
+
+
+
+
+
+
+
+
+ PHP
+
+
+ Version:
+ = $systemInfo->phpVersion ?>
- Speed:
- = $systemInfo->nic['speed'] ?>
+ Memory Limit:
+ = $systemInfo->memoryLimit ?>
- IPv4:
- = $systemInfo->nic['ipv4'] ?>
+ Max Execution Time:
+ = $systemInfo->maxExecutionTime ?>s
- IPv6:
- = $systemInfo->nic['ipv6'] ?>
+ Upload Max Filesize:
+ = $systemInfo->uploadMaxFilesize ?>
+
+ Post Max Size:
+ = $systemInfo->postMaxSize ?>
+
+ Extension:
+ = $systemInfo->extensions ?>
+
+
+
+
+
+ Database
+
+
+ Type:
+ = $systemInfo->dbType ?>
+
+ Version:
+ = $systemInfo->dbVersion ?>
+
+ Size:
+ = $systemInfo->dbSize ?>
-
-
-
-
- Active Users
-
-
- All:
- = $systemInfo->users ?>
-
- Active (within 24h):
- = $systemInfo->activeUsers ?>
-
-
-
-
-
-
-
- Share
-
-
- Link:
- = $systemInfo->shares ?>
-
-
-
-
-
- Collection
-
-
- Collection:
- = $systemInfo->collections ?>
-
-
-
-
-
-
-
-
- PHP
-
-
- Version:
- = $systemInfo->phpVersion ?>
-
- Memory Limit:
- = $systemInfo->memoryLimit ?>
-
- Max Execution Time:
- = $systemInfo->maxExecutionTime ?>s
-
- Upload Max Filesize:
- = $systemInfo->uploadMaxFilesize ?>
-
- Post Max Size:
- = $systemInfo->postMaxSize ?>
-
- Extension:
- = $systemInfo->extensions ?>
-
-
-
-
-
- Database
-
-
- Type:
- = $systemInfo->dbType ?>
-
- Version:
- = $systemInfo->dbVersion ?>
-
- Size:
- = $systemInfo->dbSize ?>
-
-
-
-
+ serverTime, 11, 8);
+ $mp_free = round(100 - $systemInfo->mp_usage, 2);
+ $script = <<< JS
+var myChart = echarts.init(document.getElementById('cpu-graph'));
+var myChart2 = echarts.init(document.getElementById('memory-graph'));
+var myChart3 = echarts.init(document.getElementById('disk-chart'));
+// check load-graph is exist
+var needLoadGraph = document.getElementById('load-graph');
+// var
+var option = {
+ legend: {
+ data: ['CPU']
+ },
+ xAxis: {
+ type: 'category',
+ boundaryGap: false,
+ data: ["$dataTime","16:51:49"]
+ },
+ yAxis: {
+ type: 'value',
+ min: 0,
+ max: 100
+ },
+ series: [
+ {
+ 'name': 'CPU',
+ data: [$systemInfo->cpuUsage,50],
+ label: {
+ show: true,
+ position: 'top',
+ formatter: '{c}%',
+ emphasis: {
+ scale: 1.5
+ }
+ },
+ type: 'line',
+ smooth: true,
+ areaStyle: {}
+ }
+ ]
+};
+if(needLoadGraph !== null){
+ var myChart1 = echarts.init(needLoadGraph);
+ var option1 = {
+ legend: {
+ data: ['Load']
+ },
+ xAxis: {
+ type: 'category',
+ boundaryGap: false,
+ data: ["$dataTime","16:51:49"]
+ },
+ yAxis: {
+ type: 'value',
+ min: 0,
+ max: 100
+ },
+ series: [
+ {
+ 'name': 'Load',
+ data: [$systemInfo->load,50],
+ label: {
+ show: true,
+ position: 'top',
+ formatter: '{c}%',
+ emphasis: {
+ scale: 1.5
+ }
+ },
+ type: 'line',
+ smooth: true,
+ areaStyle: {}
+ }
+ ]
+ };
+ myChart1.setOption(option1);
+}
+var option2 = {
+ legend: {
+ data: ['RAM', 'SWAP']
+ },
+ xAxis: {
+ type: 'category',
+ boundaryGap: false,
+ data: ["$dataTime","16:51:49"]
+ },
+ yAxis: {
+ type: 'value',
+ min: 0,
+ max: 100
+ },
+ series: [
+ {
+ name: 'RAM',
+ data: [$systemInfo->ramUsage,50],
+ type: 'line',
+ areaStyle: {},
+ smooth: true,
+ lineStyle: {
+ color: 'red'
+ },
+ label: {
+ show: true,
+ position: 'top',
+ formatter: '{c}%',
+ emphasis: {
+ scale: 1.5
+ }
+ }
+ },
+ {
+ name: 'SWAP',
+ data: [$systemInfo->swapUsage,90],
+ type: 'line',
+ areaStyle: {},
+ smooth: true,
+ lineStyle: {
+ color: 'blue'
+ },
+ label: {
+ show: true,
+ position: 'bottom',
+ formatter: '{c}%',
+ emphasis: {
+ scale: 1.5
+ }
+ }
+ }
+ ]
+};
+var option3 = {
+ tooltip: {
+ trigger: 'item',
+ formatter: function(params) {
+ return params.name + ': ' + params.value + '%';
+ }
+ },
+ legend: {
+ top: '5%',
+ left: 'center'
+ },
+ series: [
+ {
+ name: 'Data',
+ type: 'pie',
+ radius: ['40%', '70%'],
+ avoidLabelOverlap: false,
+ padAngle: 5,
+ itemStyle: {
+ borderRadius: 10
+ },
+ label: {
+ show: false,
+ position: 'center'
+ },
+ labelLine: {
+ show: false
+ },
+ data: [
+ { value: $systemInfo->mp_usage, name: 'Used Space' },
+ { value: $mp_free, name: 'Free Space' }
+ ]
+ }
+ ]
+};
+myChart.setOption(option);
+myChart2.setOption(option2);
+myChart3.setOption(option3);
+JS;
+ $this->registerJs($script, View::POS_END);
+ $this->registerJsFile('@web/js/sysinfo-core.js', ['depends' => [JqueryAsset::class, EChartsAsset::class], 'position' => View::POS_END]);
+ ?>
diff --git a/web/js/sysinfo-core.js b/web/js/sysinfo-core.js
new file mode 100644
index 0000000..cfe1a37
--- /dev/null
+++ b/web/js/sysinfo-core.js
@@ -0,0 +1,67 @@
+//dynamic fetch of system information & display
+//every 5 seconds ajax request to fetch system information
+//backport: admin/get-sysinfo
+//return json object with system information
+
+var sysinfo = {
+ init: function () {
+ setInterval(sysinfo.fetch, 5000);
+ },
+ fetch: function () {
+ $.ajax({
+ url: '/admin/get-sysinfo',
+ type: 'GET',
+ dataType: 'json',
+ success: function (data) {
+ sysinfo.display(data);
+ }
+ });
+ },
+ display: function (data) {
+ //TODO: display system information
+ }
+}
+
+// *Some data need to display
+// rdata_hostname: hostname
+// rdata_os: os
+// rdata_cpu: cpu
+// rdata_ram: ram
+// rdata_serverTime: serverTime
+// rdata_serverUpTime: serverUpTime
+// (osType ==2) rdata_load: load
+// rdata_cpuUsage: cpuUsage
+// rdata_ramUsage: ramUsage
+// rdata_swapUsage: swapUsage
+// rdata_dataMountPoint: dataMountPoint
+// rdata_mp_fs: mp_fs
+// rdata_mp_size: mp_size
+// rdata_mp_avail: mp_avail
+// rdata_mp_used: mp_used
+// 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'));
\ No newline at end of file