public function getProcessStats()
    {

        // Time?
        if (!empty($this->settings['timer'])) {
            $t = new Timer('Process Stats');
        }

        // We'll return this after stuffing it with useful info
        $result = array(
            'exists' => true,
            'totals' => array(
                'running' => 0,
                'zombie' => 0,
                'sleeping' => 0,
                'stopped' => 0,
                'idle' => 0,
            ),
            'proc_total' => 0,
            'threads' => false, // I'm not sure how to get this
        );

        // Use ps
        try {
            // Get it
            $ps = $this->exec->exec('ps', 'ax');

            // Match them
            preg_match_all('/^\s*\d+\s+[\w?]+\s+([A-Z])\S*\s+.+$/m', $ps, $processes, PREG_SET_ORDER);

            // Get total
            $result['proc_total'] = count($processes);

            // Go through
            foreach ($processes as $process) {
                switch ($process[1]) {
                    case 'S':
                    case 'I':
                        $result['totals']['sleeping']++;
                    break;
                    case 'Z':
                        $result['totals']['zombie']++;
                    break;
                    case 'R':
                    case 'D':
                        $result['totals']['running']++;
                    break;
                    case 'T':
                        $result['totals']['stopped']++;
                    break;
                    case 'W':
                        $result['totals']['idle']++;
                    break;
                }
            }
        } catch (Exception $e) {
            Errors::add('Linfo Core', 'Error using `ps` to get process info');
        }

        // Give
        return $result;
    }
public function getProcessStats()
    {

        // Time?
        if (!empty($this->settings['timer'])) {
            $t = new Timer('Process Stats');
        }

        // We'll return this after stuffing it with useful info
        $result = array(
            'exists' => true,
            'totals' => array(
                'running' => 0,
                'zombie' => 0,
                'sleeping' => 0,
                'stopped' => 0,
                'idle' => 0,
            ),
            'proc_total' => 0,
            'threads' => false, // I'm not sure how to get this
        );

        // Use ps
        try {
            // Get it
            $ps = $this->exec->exec('ps', 'ax');

            // Match them
            preg_match_all('/^\s*\d+\s+[\w?]+\s+([A-Z])\S*\s+.+$/m', $ps, $processes, PREG_SET_ORDER);

            // Get total
            $result['proc_total'] = count($processes);

            // Go through
            foreach ($processes as $process) {
                switch ($process[1]) {
                    case 'S':
                    case 'I':
                        $result['totals']['sleeping']++;
                    break;
                    case 'Z':
                        $result['totals']['zombie']++;
                    break;
                    case 'R':
                    case 'D':
                        $result['totals']['running']++;
                    break;
                    case 'T':
                        $result['totals']['stopped']++;
                    break;
                    case 'W':
                        $result['totals']['idle']++;
                    break;
                }
            }
        } catch (Exception $e) {
            Errors::add('Linfo Core', 'Error using `ps` to get process info');
        }

        // Give
        return $result;
    }
public function getProcessStats ( ) { // Time? if ( ! empty ( $ this -> settings [ 'timer' ] ) ) { $ t = new Timer ( 'Process Stats' ) ; } // We'll return this after stuffing it with useful info $ result = array ( 'exists' => true , 'totals' => array ( 'running' => 0 , 'zombie' => 0 , 'sleeping' => 0 , 'stopped' => 0 , 'idle' => 0 , ) , 'proc_total' => 0 , 'threads' => false , // I'm not sure how to get this ) ; // Use ps try { // Get it $ ps = $ this -> exec -> exec ( 'ps' , 'ax' ) ; // Match them preg_match_all ( '/^\s*\d+\s+[\w?]+\s+([A-Z])\S*\s+.+$/m' , $ ps , $ processes , PREG_SET_ORDER ) ; // Get total $ result [ 'proc_total' ] = count ( $ processes ) ; // Go through foreach ( $ processes as $ process ) { switch ( $ process [ 1 ] ) { case 'S' : case 'I' : $ result [ 'totals' ] [ 'sleeping' ] ++ ; break ; case 'Z' : $ result [ 'totals' ] [ 'zombie' ] ++ ; break ; case 'R' : case 'D' : $ result [ 'totals' ] [ 'running' ] ++ ; break ; case 'T' : $ result [ 'totals' ] [ 'stopped' ] ++ ; break ; case 'W' : $ result [ 'totals' ] [ 'idle' ] ++ ; break ; } } } catch ( Exception $ e ) { Errors :: add ( 'Linfo Core' , 'Error using `ps` to get process info' ) ; } // Give return $ result ; }
Get stats on processes
Get stats on processes