2024-04-14 17:25:06 +08:00
//dynamic fetch of system information & display
2024-04-15 16:42:56 +08:00
//every * seconds ajax request to fetch system information
2024-04-14 17:25:06 +08:00
//backport: admin/get-sysinfo
//return json object with system information
var sysinfo = {
init : function ( ) {
2024-04-15 16:10:28 +08:00
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.)
2024-04-15 16:42:56 +08:00
// For Linux users, the interval can be set to 500ms (Recommend: 1000ms)
2024-04-14 17:25:06 +08:00
} ,
fetch : function ( ) {
$ . ajax ( {
2024-04-15 16:10:28 +08:00
url : 'index.php?r=admin%2Fget-sysinfo' ,
2024-04-14 17:25:06 +08:00
type : 'GET' ,
dataType : 'json' ,
success : function ( data ) {
sysinfo . display ( data ) ;
2024-04-15 16:10:28 +08:00
} ,
error : function ( xhr , status , error ) {
console . log ( 'Error: ' + error . message ) ;
2024-04-14 17:25:06 +08:00
}
} ) ;
} ,
display : function ( data ) {
2024-04-15 16:10:28 +08:00
// 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' }
]
} ]
} ) ;
2024-04-14 17:25:06 +08:00
}
}
2024-04-15 16:10:28 +08:00
sysinfo . init ( ) ;
// *Some data need to refresh display
2024-04-14 17:25:06 +08:00
// rdata_serverTime: serverTime
// rdata_serverUpTime: serverUpTime
// (osType ==2) rdata_load: load
// rdata_cpuUsage: cpuUsage
// rdata_ramUsage: ramUsage
// rdata_swapUsage: swapUsage
// rdata_mp_avail: mp_avail
// rdata_mp_used: mp_used
// rdata_mp_usage: mp_usage