Return information about physical and virtual memory on the system

    Returns:
        dict: A dictionary of information about memory on the system

    CLI Example:

    .. code-block:: bash

        salt * status.meminfo
544792
def meminfo():
    '''
    
    '''
    # Get physical memory
    vm_total, vm_available, vm_percent, vm_used, vm_free = psutil.virtual_memory()
    # Get swap memory
    swp_total, swp_used, swp_free, swp_percent, _, _ = psutil.swap_memory()

    def get_unit_value(memory):
        symbols = ('K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')
        prefix = {}
        for i, s in enumerate(symbols):
            prefix[s] = 1 << (i + 1) * 10
        for s in reversed(symbols):
            if memory >= prefix[s]:
                value = float(memory) / prefix[s]
                return {'unit': s,
                        'value': value}
        return {'unit': 'B',
                'value': memory}

    return {'VmallocTotal': get_unit_value(vm_total),
            'VmallocUsed': get_unit_value(vm_used),
            'VmallocFree': get_unit_value(vm_free),
            'VmallocAvail': get_unit_value(vm_available),
            'SwapTotal': get_unit_value(swp_total),
            'SwapUsed': get_unit_value(swp_used),
            'SwapFree': get_unit_value(swp_free)}
127837
def memory():
    '''
    
    '''

    # test defaults
    # --memory-block-size = 10M
    # --memory-total-size = 1G

    # We test memory read / write against global / local scope of memory
    # Test data
    memory_oper = ['read', 'write']
    memory_scope = ['local', 'global']

    # Initializing the test variables
    test_command = 'sysbench --num-threads=64 --test=memory '
    test_command += '--memory-oper={0} --memory-scope={1} '
    test_command += '--memory-block-size=1K --memory-total-size=32G run '
    result = None
    ret_val = {}

    # Test begins!
    for oper in memory_oper:
        for scope in memory_scope:
            key = 'Operation: {0} Scope: {1}'.format(oper, scope)
            run_command = test_command.format(oper, scope)
            result = __salt__['cmd.run'](run_command)
            ret_val[key] = _parser(result)

    return ret_val
998308
def memory
      @pagesize ||= Vmstat.pagesize
      has_available = false

      total = free = active = inactive = pageins = pageouts = available = 0
      procfs_file("meminfo") do |file|
        content = file.read(2048) # the requested information is in the first bytes

        content.scan(/(\w+):\s+(\d+) kB/) do |name, kbytes|
          pages = (kbytes.to_i * 1024) / @pagesize

          case name
            when "MemTotal" then total = pages
            when "MemFree" then free = pages
            when "MemAvailable"
                available = pages
                has_available = true
            when "Active" then active = pages
            when "Inactive" then inactive = pages
          end
        end
      end

      procfs_file("vmstat") do |file|
        content = file.read

        if content =~ /pgpgin\s+(\d+)/
          pageins = $1.to_i
        end

        if content =~ /pgpgout\s+(\d+)/
          pageouts = $1.to_i
        end
      end

      mem_klass = has_available ? LinuxMemory : Memory
      mem_klass.new(@pagesize, total-free-active-inactive, active,
                    inactive, free, pageins, pageouts).tap do |mem|
        mem.available = available if has_available
      end
    end
446123
def _memory_data(self, log_prefix):
        
        machine_data = psutil.virtual_memory()

        process = psutil.Process()
        process_data = {
            'memory_info': process.get_memory_info(),
            'ext_memory_info': process.get_ext_memory_info(),
            'memory_percent': process.get_memory_percent(),
            'cpu_percent': process.get_cpu_percent(),
        }

        log.info(u"%s Machine memory usage: %s; Process memory usage: %s", log_prefix, machine_data, process_data)
        return {
            'machine_data': machine_data,
            'process_data': process_data,
        }
364319
def _get_vm_info(self):
        

        vm_info = {}
        results = yield from self.manager.execute("showvminfo", [self._vmname, "--machinereadable"])
        for info in results:
            try:
                name, value = info.split('=', 1)
            except ValueError:
                continue
            vm_info[name.strip('"')] = value.strip('"')
        return vm_info
567205
private static long getSizeOfPhysicalMemory() {
		switch (OperatingSystem.getCurrentOperatingSystem()) {
			case LINUX:
				return getSizeOfPhysicalMemoryForLinux();
				
			case WINDOWS:
				return getSizeOfPhysicalMemoryForWindows();
				
			case MAC_OS:
				return getSizeOfPhysicalMemoryForMac();
				
			case FREE_BSD:
				return getSizeOfPhysicalMemoryForFreeBSD();
				
			case UNKNOWN:
				LOG.error("Cannot determine size of physical memory for unknown operating system");
				return -1;
				
			default:
				LOG.error("Unrecognized OS");
				return -1;
		}
	}
1289110
def get_info(self):
        '''  '''
        return {
            'Connected': self.is_connected(),
            'Port': self.port,
            'Bytes Waiting': self.ser.in_waiting if self.ser else 0
        }
827431
def system_info(self):
        """"""
        res = self.client.service.SystemInfo()
        res = {ustr(x[0]): x[1] for x in res[0]}

        to_str = lambda arr: '.'.join([ustr(x) for x in arr[0]])
        res['OSVersion'] = to_str(res['OSVersion'])
        res['RuntimeVersion'] = to_str(res['RuntimeVersion'])
        res['Version'] = to_str(res['Version'])

        res['Name'] = ustr(res['Name'])
        res['Server'] = ustr(res['Server'])
        res['LocalNameCheck'] = ustr(res['LocalNameCheck'])
        res['UserHostAddress'] = ustr(res['UserHostAddress'])

        return res
699121
def _system(self, *args, **kwargs):
        '''
        
        '''
        sysinfo = SysInfo(__grains__.get("kernel"))

        data = dict()
        data['cpu'] = sysinfo._get_cpu()
        data['disks'] = sysinfo._get_fs()
        data['mounts'] = sysinfo._get_mounts()
        data['memory'] = sysinfo._get_mem()
        data['network'] = sysinfo._get_network()
        data['os'] = sysinfo._get_os()

        return data
629770
def read_meminfo():
    
    data = {}
    with open("/proc/meminfo", "rb") as meminfo_file:
        for row in meminfo_file:
            fields = row.split()
            # Example content:
            # MemTotal:                3801016 kB
            # MemFree:                 1840972 kB
            # MemAvailable:        3287752 kB
            # HugePages_Total:             0
            data[fields[0].decode("ascii")[:-1]] = int(fields[1]) * 1024
    return data
338028
def machine_info():
    
    import psutil
    BYTES_IN_GIG = 1073741824.0
    free_bytes = psutil.virtual_memory().total
    return [{"memory": float("%.1f" % (free_bytes / BYTES_IN_GIG)), "cores": multiprocessing.cpu_count(),
             "name": socket.gethostname()}]
542178
def _calc_mem_info(self, unit, meminfo, memory):
        
        if memory:
            total_mem_kib = meminfo["MemTotal:"]
            used_mem_kib = (
                total_mem_kib
                - meminfo["MemFree:"]
                - (
                    meminfo["Buffers:"]
                    + meminfo["Cached:"]
                    + (meminfo["SReclaimable:"] - meminfo["Shmem:"])
                )
            )
        else:
            total_mem_kib = meminfo["SwapTotal:"]
            used_mem_kib = total_mem_kib - meminfo["SwapFree:"]

        used_percent = 100 * used_mem_kib / total_mem_kib

        unit = "B" if unit == "dynamic" else unit
        (total, total_unit) = self.py3.format_units(total_mem_kib * 1024, unit)
        (used, used_unit) = self.py3.format_units(used_mem_kib * 1024, unit)
        return total, total_unit, used, used_unit, used_percent
234179
def _osx_memdata():
    '''
    
    '''
    grains = {'mem_total': 0, 'swap_total': 0}

    sysctl = salt.utils.path.which('sysctl')
    if sysctl:
        mem = __salt__['cmd.run']('{0} -n hw.memsize'.format(sysctl))
        swap_total = __salt__['cmd.run']('{0} -n vm.swapusage'.format(sysctl)).split()[2].replace(',', '.')
        if swap_total.endswith('K'):
            _power = 2**10
        elif swap_total.endswith('M'):
            _power = 2**20
        elif swap_total.endswith('G'):
            _power = 2**30
        swap_total = float(swap_total[:-1]) * _power

        grains['mem_total'] = int(mem) // 1024 // 1024
        grains['swap_total'] = int(swap_total) // 1024 // 1024
    return grains
137458
def system_info(data):
    '''
    
    '''
    if not data:
        return {}
    info = {
        'software': _parse_software(data),
        'hardware': _parse_hardware(data),
        'plugins': _parse_plugins(data),
    }
    return {'nxos': info}
921719
def info(name):
    '''
    
    '''
    try:
        grinfo = grp.getgrnam(name)
    except KeyError:
        return {}
    else:
        return {'name': grinfo.gr_name,
                'passwd': grinfo.gr_passwd,
                'gid': grinfo.gr_gid,
                'members': grinfo.gr_mem}
219043
def info():
    '''
    
    '''
    response = salt.utils.http.query(
        "{0}/v2/info".format(_base_url()),
        decode_type='json',
        decode=True,
    )
    return response['dict']
495307
def get_meminfo(opts):
    ''' 
    '''
    meminfo = MemInfo()
    outunit = opts.outunit
    try:
        with open(memfname) as infile:
            lines = infile.readlines()
    except IOError:
        return None

    for line in lines:                      # format: 'MemTotal:  511456 kB\n'
        tokens = line.split()
        if tokens:
            name, value = tokens[0][:-1].lower(), tokens[1]  # rm :
            if len(tokens) == 2:
                continue
            unit = tokens[2].lower()

            # parse_result to bytes  TODO
            value = int(value)
            if   unit == 'kb': value = value * 1024  # most likely
            elif unit ==  'b': value = value
            elif unit == 'mb': value = value * 1024 * 1024
            elif unit == 'gb': value = value * 1024 * 1024 * 1024

            setattr(meminfo, name, value / outunit)

    cache = meminfo.cached + meminfo.buffers
    meminfo.used = meminfo.memtotal - meminfo.memfree - cache
    meminfo.swapused = (meminfo.swaptotal - meminfo.swapcached -
                        meminfo.swapfree)
    return meminfo