Retrieves the number of memory shares allocated to the virtual machine.
           For information about how an ESX server uses memory shares to manage
           virtual machine priority, see the vSphere Resource Management Guide.
773293
def GetMemShares(self):
        ''''''
        counter = c_uint()
        ret = vmGuestLib.VMGuestLib_GetMemShares(self.handle.value, byref(counter))
        if ret != VMGUESTLIB_ERROR_SUCCESS: raise VMGuestLibException(ret)
        return counter.value
114920
def shared_memory(attrs=None, where=None):
    '''
    
    '''
    if __grains__['os_family'] in ['RedHat', 'Debian']:
        return _osquery_cmd(table='shared_memory', attrs=attrs, where=where)
    return {'result': False, 'comment': 'Only available on Red Hat or Debian based systems.'}
785994
def __get_size(conn, vm_):
    '''
    
    '''
    size = config.get_cloud_config_value(
        'size', vm_, __opts__, default='n1-standard-1', search_global=False)
    return conn.ex_get_size(size, __get_location(conn, vm_))
275485
function getMemory(rusage) {
  var o = {}, mem = process.memoryUsage();
  o.used_memory = mem.heapUsed;
  o.used_memory_human = bytes.humanize(mem.heapUsed, 2, true);
  o.used_memory_rss = mem.rss;
  o.used_memory_peak = rusage.maxrss;
  o.used_memory_peak_human = bytes.humanize(rusage.maxrss, 2, true);
  return o;
}
1095941
def _determine_storage_repo(session, resource_pool, vm_):
    '''
    
    '''
    storage_repo = ''
    if 'storage_repo' in vm_.keys():
        storage_repo = _get_sr(vm_['storage_repo'], session)
    else:
        storage_repo = None
        if resource_pool:
            default_sr = session.xenapi.pool.get_default_SR(resource_pool)
            sr_record = session.xenapi.SR.get_record(default_sr)
            log.debug('storage repository: %s', sr_record['name_label'])
            storage_repo = default_sr
        else:
            storage_repo = None
    log.debug('storage repository: %s', storage_repo)
    return storage_repo
1186107
def get_memory_banks_per_run(coreAssignment, cgroups):
    """"""
    try:
        # read list of available memory banks
        allMems = set(cgroups.read_allowed_memory_banks())

        result = []
        for cores in coreAssignment:
            mems = set()
            for core in cores:
                coreDir = '/sys/devices/system/cpu/cpu{0}/'.format(core)
                mems.update(_get_memory_banks_listed_in_dir(coreDir))
            allowedMems = sorted(mems.intersection(allMems))
            logging.debug("Memory banks for cores %s are %s, of which we can use %s.", cores, list(mems), allowedMems)

            result.append(allowedMems)

        assert len(result) == len(coreAssignment)

        if any(result) and os.path.isdir('/sys/devices/system/node/'):
            return result
        else:
            # All runs get the empty list of memory regions
            # because this system has no NUMA support
            return None
    except ValueError as e:
        sys.exit("Could not read memory information from kernel: {0}".format(e))
350465
def memory_used(self):
        
        if self._end_memory:
            memory_used = self._end_memory - self._start_memory
            return memory_used
        else:
            return None
336566
def get_cpu_usage(self, cpu_id=0):
        

        cpu_usage = yield from self._hypervisor.send('vm cpu_usage "{name}" {cpu_id}'.format(name=self._name, cpu_id=cpu_id))
        return int(cpu_usage[0])
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()}]
754590
public static long usedMemory() {
        long memory = 0;
        for (MemoryPoolMXBean mp : ManagementFactory.getMemoryPoolMXBeans()) {
            memory += mp.getUsage().getUsed();
        }
        return memory;
    }
615055
def get_system_memory():
    
    # Try to accurately figure out the memory limit if we are in a docker
    # container. Note that this file is not specific to Docker and its value is
    # often much larger than the actual amount of memory.
    docker_limit = None
    memory_limit_filename = "/sys/fs/cgroup/memory/memory.limit_in_bytes"
    if os.path.exists(memory_limit_filename):
        with open(memory_limit_filename, "r") as f:
            docker_limit = int(f.read())

    # Use psutil if it is available.
    psutil_memory_in_bytes = None
    try:
        import psutil
        psutil_memory_in_bytes = psutil.virtual_memory().total
    except ImportError:
        pass

    if psutil_memory_in_bytes is not None:
        memory_in_bytes = psutil_memory_in_bytes
    elif sys.platform == "linux" or sys.platform == "linux2":
        # Handle Linux.
        bytes_in_kilobyte = 1024
        memory_in_bytes = vmstat("total memory") * bytes_in_kilobyte
    else:
        # Handle MacOS.
        memory_in_bytes = sysctl(["sysctl", "hw.memsize"])

    if docker_limit is not None:
        return min(docker_limit, memory_in_bytes)
    else:
        return memory_in_bytes
984961
def GetMemSharedMB(self):
        ''''''
        counter = c_uint()
        ret = vmGuestLib.VMGuestLib_GetMemSharedMB(self.handle.value, byref(counter))
        if ret != VMGUESTLIB_ERROR_SUCCESS: raise VMGuestLibException(ret)
        return counter.value
1107219
def get_vm(self, resource_group_name, vm_name):
        '''
        
        '''
        return self.client.virtual_machines.get(
            resource_group_name, vm_name, expand='instanceView')
567034
def check_mem_usage(soft_percent=None, hard_percent=None):
    
    soft_percent = soft_percent or config.memory.soft_mem_limit
    hard_percent = hard_percent or config.memory.hard_mem_limit
    used_mem_percent = psutil.virtual_memory().percent
    if used_mem_percent > hard_percent:
        raise MemoryError('Using more memory than allowed by configuration '
                          '(Used: %d%% / Allowed: %d%%)! Shutting down.' %
                          (used_mem_percent, hard_percent))
    elif used_mem_percent > soft_percent:
        msg = 'Using over %d%% of the memory in %s!'
        return msg % (used_mem_percent, socket.gethostname())
1372811
def collect(self):
        
        if libvirt is None:
            self.log.error('Unable to import either libvirt')
            return {}
        # Open a restricted (non-root) connection to the hypervisor
        conn = libvirt.openReadOnly(None)
        # Get hardware info
        conninfo = conn.getInfo()
        # Initialize variables
        memallocated = 0
        coresallocated = 0
        totalcores = 0
        results = {}
        domIds = conn.listDomainsID()
        if 0 in domIds:
            # Total cores
            domU = conn.lookupByID(0)
            totalcores = domU.info()[3]
        # Free Space
        s = os.statvfs('/')
        freeSpace = (s.f_bavail * s.f_frsize) / 1024
        # Calculate allocated memory and cores
        for i in domIds:
            # Ignore 0
            if i == 0:
                continue
            domU = conn.lookupByID(i)
            dominfo = domU.info()
            memallocated += dominfo[2]
            if i > 0:
                coresallocated += dominfo[3]
        results = {
            'InstalledMem': conninfo[1],
            'MemAllocated': memallocated / 1024,
            'MemFree': conninfo[1] - (memallocated / 1024),
            'AllocatedCores': coresallocated,
            'DiskFree': freeSpace,
            'TotalCores': totalcores,
            'FreeCores': (totalcores - coresallocated)
        }
        for k in results.keys():
            self.publish(k, results[k], 0)
290473
def get_size(vm_):
    '''
    
    '''
    vm_size = config.get_cloud_config_value('size', vm_, __opts__)
    sizes = avail_sizes()

    if not vm_size:
        return sizes['Small Instance']

    for size in sizes:
        combinations = (six.text_type(sizes[size]['id']), six.text_type(size))
        if vm_size and six.text_type(vm_size) in combinations:
            return sizes[size]
    raise SaltCloudNotFound(
        'The specified size, \'{0}\', could not be found.'.format(vm_size)
    )
1155121
def GetCpuShares(self):
        ''''''
        counter = c_uint()
        ret = vmGuestLib.VMGuestLib_GetCpuShares(self.handle.value, byref(counter))
        if ret != VMGUESTLIB_ERROR_SUCCESS: raise VMGuestLibException(ret)
        return counter.value