Skip to content

Commit

Permalink
Merge branch 'QA_3_5'
Browse files Browse the repository at this point in the history
Conflicts:
	server_status.php
  • Loading branch information
mynetx committed Sep 4, 2012
2 parents 0354ea0 + 2fce20d commit 8091167
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 10 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Expand Up @@ -63,6 +63,7 @@ VerboseMultiSubmit, ReplaceHelpImg
- bug #3559925 [privileges] Incorrect updating of the list of users
- bug #3561224 [edit] cell edit date field with empty date fills in current date
- bug #3559955 [edit] current_date from function drop down fails on update
- add support for Solaris and FreeBSD system load and memory display in server status

3.5.2.2 (2012-08-12)
- [security] Fixed XSS vulnerabilities, see PMASA-2012-4
Expand Down
39 changes: 39 additions & 0 deletions js/server_status_monitor.js
Expand Up @@ -192,6 +192,45 @@ $(function() {
}
});
break;

case 'SunOS':
$.extend(presetCharts, {
'cpu': {
title: PMA_messages['strSystemCPUUsage'],
series: [ {
label: PMA_messages['strAverageLoad']
} ],
nodes: [ {
dataPoints: [{ type: 'cpu', name: 'loadavg'}]
} ],
maxYLabel: []
},
'memory': {
title: PMA_messages['strSystemMemory'],
series: [
{ label: PMA_messages['strUsedMemory'], fill:true, stackSeries: true},
{ label: PMA_messages['strFreeMemory'], fill:true, stackSeries: true}
],
nodes: [
{ dataPoints: [{ type: 'memory', name: 'MemUsed' }], valueDivisor: 1024 },
{ dataPoints: [{ type: 'memory', name: 'MemFree' }], valueDivisor: 1024 }
],
maxYLabel: []
},
'swap': {
title: PMA_messages['strSystemSwap'],
series: [
{ label: PMA_messages['strUsedSwap'], fill:true, stackSeries: true},
{ label: PMA_messages['strFreeSwap'], fill:true, stackSeries: true}
],
nodes: [
{ dataPoints: [{ type: 'memory', name: 'SwapUsed' }], valueDivisor: 1024 },
{ dataPoints: [{ type: 'memory', name: 'SwapFree' }], valueDivisor: 1024 }
],
maxYLabel: []
}
});
break;
}

// Default setting for the chart grid
Expand Down
2 changes: 1 addition & 1 deletion libraries/Advisor.class.php
Expand Up @@ -36,7 +36,7 @@ function run()
}
// Add total memory to variables as well
include_once 'libraries/sysinfo.lib.php';
$sysinfo = getSysInfo();
$sysinfo = PMA_getSysInfo();
$memory = $sysinfo->memory();
$this->variables['system_memory'] = $memory['MemTotal'];

Expand Down
84 changes: 77 additions & 7 deletions libraries/sysinfo.lib.php
Expand Up @@ -13,24 +13,43 @@
exit;
}

/**
* Wrap the PHP_OS constant
*
* @return string
*/
function PMA_getSysInfoOs()
{
$php_os = PHP_OS;

// look for common UNIX-like systems
$unix_like = array('FreeBSD');
if (in_array($php_os, $unix_like)) {
$php_os = 'Linux';
}

return ucfirst($php_os);
}

/**
* @return array
*/
function getSysInfo()
function PMA_getSysInfo()
{
$supported = array('Linux', 'WINNT');
$php_os = PMA_getSysInfoOs();
$supported = array('Linux', 'WINNT', 'SunOS');

$sysinfo = array();

if (in_array(PHP_OS, $supported)) {
return eval("return new ".PHP_OS."();");
if (in_array($php_os, $supported)) {
return eval("return new PMA_sysinfo".$php_os."();");
}

return $sysinfo;
return new PMA_Sysinfo_Default;
}


class WINNT
class PMA_sysinfoWinnt
{
private $_wmi;

Expand Down Expand Up @@ -112,7 +131,7 @@ function memory()
}
}

class Linux
class PMA_sysinfoLinux
{
public $os = 'Linux';

Expand All @@ -137,3 +156,54 @@ function memory()
return $mem;
}
}

class PMA_sysinfoSunos
{
public $os = 'SunOS';

private function _kstat($key)
{
if ($m = shell_exec('kstat -p d '.$key)) {
list($key, $value) = preg_split("/\t/", trim($m), 2);
return $value;
} else {
return '';
}
}

public function loadavg() {
$load1 = $this->_kstat('unix:0:system_misc:avenrun_1min');

return array('loadavg' => $load1);
}

public function memory() {
preg_match_all('/^(MemTotal|MemFree|Cached|Buffers|SwapCached|SwapTotal|SwapFree):\s+(.*)\s*kB/im', file_get_contents('/proc/meminfo'), $matches);

$pagesize = $this->_kstat('unix:0:seg_cache:slab_size');
$mem['MemTotal'] = $this->_kstat('unix:0:system_pages:pagestotal') * $pagesize;
$mem['MemUsed'] = $this->_kstat('unix:0:system_pages:pageslocked') * $pagesize;
$mem['MemFree'] = $this->_kstat('unix:0:system_pages:pagesfree') * $pagesize;
$mem['SwapTotal'] = $this->_kstat('unix:0:vminfo:swap_avail') / 1024;
$mem['SwapUsed'] = $this->_kstat('unix:0:vminfo:swap_alloc') / 1024;
$mem['SwapFree'] = $this->_kstat('unix:0:vminfo:swap_free') / 1024;

foreach ($mem as $idx=>$value)
$mem[$idx] = intval($value);

return $mem;
}
}

class PMA_sysinfoDefault
{
public $os = PHP_OS;

public function loadavg() {
return array('loadavg' => 0);
}

public function memory() {
return array();
}
}
12 changes: 10 additions & 2 deletions server_status.php
Expand Up @@ -128,12 +128,13 @@
case 'cpu':
if (!$sysinfo) {
include_once 'libraries/sysinfo.lib.php';
$sysinfo = getSysInfo();
$sysinfo = PMA_getSysInfo();
}
if (!$cpuload) {
$cpuload = $sysinfo->loadavg();
}

<<<<<<< HEAD
if (PHP_OS == 'Linux') {
$ret[$chart_id][$node_id][$point_id]['idle']
= $cpuload['idle'];
Expand All @@ -143,13 +144,20 @@
$ret[$chart_id][$node_id][$point_id]['value']
= $cpuload['loadavg'];
}
=======
if (PMA_getSysInfoOs() == 'Linux') {
$ret[$chart_id][$node_id][$point_id]['idle'] = $cpuload['idle'];
$ret[$chart_id][$node_id][$point_id]['busy'] = $cpuload['busy'];
} else
$ret[$chart_id][$node_id][$point_id]['value'] = $cpuload['loadavg'];
>>>>>>> QA_3_5

break;

case 'memory':
if (!$sysinfo) {
include_once 'libraries/sysinfo.lib.php';
$sysinfo = getSysInfo();
$sysinfo = PMA_getSysInfo();
}
if (!$memory) {
$memory = $sysinfo->memory();
Expand Down

0 comments on commit 8091167

Please sign in to comment.