示例#1
0
/**
 * @return array
 */
function PMA_getSysInfo()
{
    $php_os = PMA_getSysInfoOs();
    $supported = array('Linux', 'WINNT', 'SunOS');
    $sysinfo = array();
    if (in_array($php_os, $supported)) {
        return eval("return new PMA_sysinfo" . $php_os . "();");
    }
    return new PMA_Sysinfo_Default();
}
示例#2
0
/**
 * Gets sysinfo class mathing current OS
 *
 * @return PMA_SysInfo|mixed sysinfo class
 */
function PMA_getSysInfo()
{
    $php_os = PMA_getSysInfoOs();
    $supported = array('Linux', 'WINNT', 'SunOS');
    if (in_array($php_os, $supported)) {
        $class_name = 'PMA_SysInfo' . $php_os;
        $ret = new $class_name();
        if ($ret->supported()) {
            return $ret;
        }
    }
    return new PMA_SysInfo();
}
示例#3
0
/**
 * Gets sysinfo class mathing current OS
 *
 * @return sysinfo class
 */
function PMA_getSysInfo()
{
    $php_os = PMA_getSysInfoOs();
    $supported = array('Linux', 'WINNT', 'SunOS');
    $sysinfo = array();
    if (in_array($php_os, $supported)) {
        $ret = eval("return new PMA_SysInfo" . $php_os . "();");
        if ($ret->supported()) {
            return $ret;
        }
    }
    return new PMA_SysInfo();
}
/**
 * Gets sysinfo class mathing current OS
 *
 * @return \PMA\libraries\SysInfo|mixed sysinfo class
 */
function PMA_getSysInfo()
{
    $php_os = PMA_getSysInfoOs();
    $supported = array('Linux', 'WINNT', 'SunOS');
    if (in_array($php_os, $supported)) {
        $class_name = 'PMA\\libraries\\SysInfo' . $php_os;
        /** @var \PMA\libraries\SysInfo $ret */
        $ret = new $class_name();
        if ($ret->supported()) {
            return $ret;
        }
    }
    return new \PMA\libraries\SysInfo();
}
/**
 * Switch called to get JSON for charting data
 *
 * @param string $type       Type
 * @param string $pName      Name
 * @param array  $serverVars Server variable values
 * @param array  $statusVars Status variable values
 * @param array  $ret        Real-time charting data
 * @param mixed  $sysinfo    System info
 * @param mixed  $cpuload    CPU load
 * @param mixed  $memory     Memory
 *
 * @return array
 */
function PMA_getJsonForChartingDataSwitch($type, $pName, $serverVars, $statusVars, $ret, $sysinfo, $cpuload, $memory)
{
    switch ($type) {
        /* We only collect the status and server variables here to
         * read them all in one query,
         * and only afterwards assign them.
         * Also do some white list filtering on the names
         */
        case 'servervar':
            if (!preg_match('/[^a-zA-Z_]+/', $pName)) {
                $serverVars[] = $pName;
            }
            break;
        case 'statusvar':
            if (!preg_match('/[^a-zA-Z_]+/', $pName)) {
                $statusVars[] = $pName;
            }
            break;
        case 'proc':
            $result = $GLOBALS['dbi']->query('SHOW PROCESSLIST');
            $ret['value'] = $GLOBALS['dbi']->numRows($result);
            break;
        case 'cpu':
            if (!$sysinfo) {
                include_once 'libraries/sysinfo.lib.php';
                $sysinfo = PMA_getSysInfo();
            }
            if (!$cpuload) {
                $cpuload = $sysinfo->loadavg();
            }
            if (PMA_getSysInfoOs() == 'Linux') {
                $ret['idle'] = $cpuload['idle'];
                $ret['busy'] = $cpuload['busy'];
            } else {
                $ret['value'] = $cpuload['loadavg'];
            }
            break;
        case 'memory':
            if (!$sysinfo) {
                include_once 'libraries/sysinfo.lib.php';
                $sysinfo = PMA_getSysInfo();
            }
            if (!$memory) {
                $memory = $sysinfo->memory();
            }
            $ret['value'] = isset($memory[$pName]) ? $memory[$pName] : 0;
            break;
    }
    return array($serverVars, $statusVars, $ret);
}
示例#6
0
                        case 'proc':
                            $result = PMA_DBI_query('SHOW PROCESSLIST');
                            $ret[$chart_id][$node_id][$point_id]['value']
                                = PMA_DBI_num_rows($result);
                            break;

                        case 'cpu':
                            if (!$sysinfo) {
                                include_once 'libraries/sysinfo.lib.php';
                                $sysinfo = PMA_getSysInfo();
                            }
                            if (!$cpuload) {
                                $cpuload = $sysinfo->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'];
                            }

                            break;

                        case 'memory':
                            if (!$sysinfo) {
                                include_once 'libraries/sysinfo.lib.php';
                                $sysinfo = PMA_getSysInfo();
示例#7
0
 /**
  * Test for OS detection
  *
  * @param string $os       OS name as returned by PHP_OS
  * @param string $expected Expected detected OS name
  *
  * @return void
  *
  * @dataProvider sysInfoOsProvider
  */
 public function testGetSysInfoOs($os, $expected)
 {
     $this->assertEquals($expected, PMA_getSysInfoOs($os));
 }
/**
 * Returns JSon for real-time charting data
 *
 * @return Array
 */
function PMA_getJsonForChartingData()
{
    $ret = json_decode($_REQUEST['requiredData'], true);
    $statusVars = array();
    $serverVars = array();
    $sysinfo = $cpuload = $memory = 0;
    $pName = '';
    /* Accumulate all required variables and data */
    // For each chart
    foreach ($ret as $chart_id => $chartNodes) {
        // For each data series
        foreach ($chartNodes as $node_id => $nodeDataPoints) {
            // For each data point in the series (usually just 1)
            foreach ($nodeDataPoints as $point_id => $dataPoint) {
                $pName = $dataPoint['name'];
                switch ($dataPoint['type']) {
                    /* We only collect the status and server variables here to
                     * read them all in one query,
                     * and only afterwards assign them.
                     * Also do some white list filtering on the names
                     */
                    case 'servervar':
                        if (!preg_match('/[^a-zA-Z_]+/', $pName)) {
                            $serverVars[] = $pName;
                        }
                        break;
                    case 'statusvar':
                        if (!preg_match('/[^a-zA-Z_]+/', $pName)) {
                            $statusVars[] = $pName;
                        }
                        break;
                    case 'proc':
                        $result = $GLOBALS['dbi']->query('SHOW PROCESSLIST');
                        $ret[$chart_id][$node_id][$point_id]['value'] = $GLOBALS['dbi']->numRows($result);
                        break;
                    case 'cpu':
                        if (!$sysinfo) {
                            include_once 'libraries/sysinfo.lib.php';
                            $sysinfo = PMA_getSysInfo();
                        }
                        if (!$cpuload) {
                            $cpuload = $sysinfo->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'];
                        }
                        break;
                    case 'memory':
                        if (!$sysinfo) {
                            include_once 'libraries/sysinfo.lib.php';
                            $sysinfo = PMA_getSysInfo();
                        }
                        if (!$memory) {
                            $memory = $sysinfo->memory();
                        }
                        $ret[$chart_id][$node_id][$point_id]['value'] = $memory[$pName];
                        break;
                }
                /* switch */
            }
            /* foreach */
        }
        /* foreach */
    }
    /* foreach */
    // Retrieve all required status variables
    if (count($statusVars)) {
        $statusVarValues = $GLOBALS['dbi']->fetchResult("SHOW GLOBAL STATUS WHERE Variable_name='" . implode("' OR Variable_name='", $statusVars) . "'", 0, 1);
    } else {
        $statusVarValues = array();
    }
    // Retrieve all required server variables
    if (count($serverVars)) {
        $serverVarValues = $GLOBALS['dbi']->fetchResult("SHOW GLOBAL VARIABLES WHERE Variable_name='" . implode("' OR Variable_name='", $serverVars) . "'", 0, 1);
    } else {
        $serverVarValues = array();
    }
    // ...and now assign them
    foreach ($ret as $chart_id => $chartNodes) {
        foreach ($chartNodes as $node_id => $nodeDataPoints) {
            foreach ($nodeDataPoints as $point_id => $dataPoint) {
                switch ($dataPoint['type']) {
                    case 'statusvar':
                        $ret[$chart_id][$node_id][$point_id]['value'] = $statusVarValues[$dataPoint['name']];
                        break;
                    case 'servervar':
                        $ret[$chart_id][$node_id][$point_id]['value'] = $serverVarValues[$dataPoint['name']];
                        break;
                }
            }
        }
    }
    $ret['x'] = microtime(true) * 1000;
    return $ret;
}