diff --git a/ChangeLog b/ChangeLog index 3155456f85..b50722ad33 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 diff --git a/js/server_status_monitor.js b/js/server_status_monitor.js index 902988ac74..81fbf29be7 100644 --- a/js/server_status_monitor.js +++ b/js/server_status_monitor.js @@ -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 diff --git a/libraries/Advisor.class.php b/libraries/Advisor.class.php index fdfc83a4e9..adbaa79244 100644 --- a/libraries/Advisor.class.php +++ b/libraries/Advisor.class.php @@ -36,7 +36,7 @@ class Advisor } // 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']; diff --git a/libraries/sysinfo.lib.php b/libraries/sysinfo.lib.php index fcb6487298..5bb2342bea 100644 --- a/libraries/sysinfo.lib.php +++ b/libraries/sysinfo.lib.php @@ -13,24 +13,43 @@ if (! defined('PHPMYADMIN')) { 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; @@ -112,7 +131,7 @@ class WINNT } } -class Linux +class PMA_sysinfoLinux { public $os = 'Linux'; @@ -137,3 +156,54 @@ class Linux 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(); + } +} diff --git a/server_status.php b/server_status.php index 4a062a1322..2b49d278a9 100644 --- a/server_status.php +++ b/server_status.php @@ -128,12 +128,13 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { 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']; @@ -143,13 +144,20 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { $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();