public function getRam()
    {
        $return = [];
        $return['swapTotal'] = 0;
        $return['swapFree'] = 0;
        $return['swapInfo'] = [];

        // Get amount of real hard ram, in bytes
        $return['total'] = $this->sysctl['hw.physmem'];

        // Get real
        try {
            $vmstat = $this->exec->exec('vmstat');
            if (preg_match('/\s\d\s\d\s\d\s+\d+\s+(\d+)/', $vmstat, $vmstat_match)) {
                $hard_ram_free = $vmstat_match[1];
                $return['type'] = 'Physical';
                $return['free'] = $return['total'] - ($hard_ram_free * 1024);
            }
        } catch (Exception $e) {
            Errors::add('Linfo Core', 'Error using `vmstat` to get memory usage usage');
        }

        // Get swap
        try {
            $swapinfo = $this->exec->exec('swapctl', '-k');
            @preg_match_all('/^(\S+)\s+(\d+)\s+(\d+)\s+(\d+)/m', $swapinfo, $sm, PREG_SET_ORDER);
            foreach ($sm as $swap) {
                $return['swapTotal'] += $swap[2] * 1024;
                $return['swapFree'] += (($swap[2] - $swap[3]) * 1024);
                $ft = is_file($swap[1]) ? @filetype($swap[1]) : 'Unknown'; // TODO: I'd rather it be Partition or File
                $return['swapInfo'][] = array(
                    'device' => $swap[1],
                    'size' => $swap[2] * 1024,
                    'used' => $swap[3] * 1024,
                    'type' => ucfirst($ft),
                );
            }
        } catch (Exception $e) {
            Errors::add('Linfo Core', 'Error using `swapctl` to get swap usage');
        }

        // Give it
        return $return;
    }
public function getRam()
    {
        $return = [];
        $return['swapTotal'] = 0;
        $return['swapFree'] = 0;
        $return['swapInfo'] = [];

        // Get amount of real hard ram, in bytes
        $return['total'] = $this->sysctl['hw.physmem'];

        // Get real
        try {
            $vmstat = $this->exec->exec('vmstat');
            if (preg_match('/\s\d\s\d\s\d\s+\d+\s+(\d+)/', $vmstat, $vmstat_match)) {
                $hard_ram_free = $vmstat_match[1];
                $return['type'] = 'Physical';
                $return['free'] = $return['total'] - ($hard_ram_free * 1024);
            }
        } catch (Exception $e) {
            Errors::add('Linfo Core', 'Error using `vmstat` to get memory usage usage');
        }

        // Get swap
        try {
            $swapinfo = $this->exec->exec('swapctl', '-k');
            @preg_match_all('/^(\S+)\s+(\d+)\s+(\d+)\s+(\d+)/m', $swapinfo, $sm, PREG_SET_ORDER);
            foreach ($sm as $swap) {
                $return['swapTotal'] += $swap[2] * 1024;
                $return['swapFree'] += (($swap[2] - $swap[3]) * 1024);
                $ft = is_file($swap[1]) ? @filetype($swap[1]) : 'Unknown'; // TODO: I'd rather it be Partition or File
                $return['swapInfo'][] = array(
                    'device' => $swap[1],
                    'size' => $swap[2] * 1024,
                    'used' => $swap[3] * 1024,
                    'type' => ucfirst($ft),
                );
            }
        } catch (Exception $e) {
            Errors::add('Linfo Core', 'Error using `swapctl` to get swap usage');
        }

        // Give it
        return $return;
    }
public function getRam ( ) { $ return = [ ] ; $ return [ 'swapTotal' ] = 0 ; $ return [ 'swapFree' ] = 0 ; $ return [ 'swapInfo' ] = [ ] ; // Get amount of real hard ram, in bytes $ return [ 'total' ] = $ this -> sysctl [ 'hw.physmem' ] ; // Get real try { $ vmstat = $ this -> exec -> exec ( 'vmstat' ) ; if ( preg_match ( '/\s\d\s\d\s\d\s+\d+\s+(\d+)/' , $ vmstat , $ vmstat_match ) ) { $ hard_ram_free = $ vmstat_match [ 1 ] ; $ return [ 'type' ] = 'Physical' ; $ return [ 'free' ] = $ return [ 'total' ] - ( $ hard_ram_free * 1024 ) ; } } catch ( Exception $ e ) { Errors :: add ( 'Linfo Core' , 'Error using `vmstat` to get memory usage usage' ) ; } // Get swap try { $ swapinfo = $ this -> exec -> exec ( 'swapctl' , '-k' ) ; @ preg_match_all ( '/^(\S+)\s+(\d+)\s+(\d+)\s+(\d+)/m' , $ swapinfo , $ sm , PREG_SET_ORDER ) ; foreach ( $ sm as $ swap ) { $ return [ 'swapTotal' ] += $ swap [ 2 ] * 1024 ; $ return [ 'swapFree' ] += ( ( $ swap [ 2 ] - $ swap [ 3 ] ) * 1024 ) ; $ ft = is_file ( $ swap [ 1 ] ) ? @ filetype ( $ swap [ 1 ] ) : 'Unknown' ; // TODO: I'd rather it be Partition or File $ return [ 'swapInfo' ] [ ] = array ( 'device' => $ swap [ 1 ] , 'size' => $ swap [ 2 ] * 1024 , 'used' => $ swap [ 3 ] * 1024 , 'type' => ucfirst ( $ ft ) , ) ; } } catch ( Exception $ e ) { Errors :: add ( 'Linfo Core' , 'Error using `swapctl` to get swap usage' ) ; } // Give it return $ return ; }
Get memory usage statistics
Get memory usage statistics