def vmstats():
    '''
    .. versionchanged:: 2016.3.2
        Return the virtual memory stats for this minion

    .. versionchanged:: 2016.11.4
        Added support for AIX

    CLI Example:

    .. code-block:: bash

        salt '*' status.vmstats
    '''
    def linux_vmstats():
        '''
        linux specific implementation of vmstats
        '''
        ret = {}
        try:
            with salt.utils.files.fopen('/proc/vmstat', 'r') as fp_:
                stats = salt.utils.stringutils.to_unicode(fp_.read())
        except IOError:
            pass
        else:
            for line in stats.splitlines():
                if not line:
                    continue
                comps = line.split()
                ret[comps[0]] = _number(comps[1])
        return ret

    def generic_vmstats():
        '''
        generic implementation of vmstats
        note: works on FreeBSD, SunOS and OpenBSD (possibly others)
        '''
        ret = {}
        for line in __salt__['cmd.run']('vmstat -s').splitlines():
            comps = line.split()
            if comps[0].isdigit():
                ret[' '.join(comps[1:])] = _number(comps[0].strip())
        return ret

    # dict that returns a function that does the right thing per platform
    get_version = {
        'Linux': linux_vmstats,
        'FreeBSD': generic_vmstats,
        'OpenBSD': generic_vmstats,
        'SunOS': generic_vmstats,
        'AIX': generic_vmstats,
    }

    errmsg = 'This method is unsupported on the current operating system!'
    return get_version.get(__grains__['kernel'], lambda: errmsg)()
def vmstats ( ) : def linux_vmstats ( ) : ret = { } try : with salt . utils . files . fopen ( '/proc/vmstat' , 'r' ) as fp_ : stats = salt . utils . stringutils . to_unicode ( fp_ . read ( ) ) except IOError : pass else : for line in stats . splitlines ( ) : if not line : continue comps = line . split ( ) ret [ comps [ 0 ] ] = _number ( comps [ 1 ] ) return ret def generic_vmstats ( ) : ret = { } for line in __salt__ [ 'cmd.run' ] ( 'vmstat -s' ) . splitlines ( ) : comps = line . split ( ) if comps [ 0 ] . isdigit ( ) : ret [ ' ' . join ( comps [ 1 : ] ) ] = _number ( comps [ 0 ] . strip ( ) ) return ret get_version = { 'Linux' : linux_vmstats , 'FreeBSD' : generic_vmstats , 'OpenBSD' : generic_vmstats , 'SunOS' : generic_vmstats , 'AIX' : generic_vmstats , } errmsg = 'This method is unsupported on the current operating system!' return get_version . get ( __grains__ [ 'kernel' ] , lambda : errmsg ) ( )
.. versionchanged:: 2016.3.2
        Return the virtual memory stats for this minion

    .. versionchanged:: 2016.11.4
        Added support for AIX

    CLI Example:

    .. code-block:: bash

        salt '*' status.vmstats