How to use the psutil.virtual_memory function in psutil

To help you get started, we’ve selected a few psutil examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NagiosEnterprises / ncpa / agent / listener / psapi.py View on Github external
    mem_virt_total = RunnableNode('total', method=lambda: (ps.virtual_memory().total, 'B'))
    mem_virt_available = RunnableNode('available', method=lambda: (ps.virtual_memory().available, 'B'))
github AppScale / appscale / Hermes / stats / statistics.py View on Github external
on the machine
    """
    timestamp = time.mktime(datetime.utcnow().timetuple())

    # CPU usage
    cpu_times = psutil.cpu_times()
    cpu = NodeCPU(
      user=cpu_times.user, system=cpu_times.system, idle=cpu_times.idle,
      percent=psutil.cpu_percent(), count=psutil.cpu_count()
    )

    # AvgLoad
    loadavg = NodeLoadAvg(os.getloadavg())

    # Memory usage
    virtual = psutil.virtual_memory()
    memory = NodeMemory(
      total=virtual.total, available=virtual.available, used=virtual.used)

    # Swap usage
    swap_mem = psutil.swap_memory()
    swap = NodeSwap(
      total=swap_mem.total, free=swap_mem.free, used=swap_mem.used
    )

    # Disk usage
    partitions = psutil.disk_partitions(all=True)
    partitions_dict = {}
    for part in partitions:
      usage = psutil.disk_usage(part.mountpoint)
      partitions_dict[part.mountpoint] = NodePartition(
        total=usage.total, used=usage.used, free=usage.free
github Peter92 / MouseTracks / core / os / __init__.py View on Github external
def memory_usage(self):
            try:
                memory_size = psutil.virtual_memory().total
            except (psutil.NoSuchProcess, AttributeError):
                return 0
            return int(memory_size * self.percentage_memory_usage() / 100)
github isobar-us / multilabel-image-classification-tensorflow / tf-object-detection-sagemaker / resources / tensorflow-models / official / utils / logs / logger.py View on Github external
def _collect_memory_info(run_info):
  try:
    # Note: psutil is not installed in the TensorFlow OSS tree.
    # It is installable via pip.
    import psutil   # pylint: disable=g-import-not-at-top
    vmem = psutil.virtual_memory()
    run_info["machine_config"]["memory_total"] = vmem.total
    run_info["machine_config"]["memory_available"] = vmem.available
  except ImportError:
    tf.logging.warn("'psutil' not imported. Memory info will not be logged.")
github ct2034 / dockeROS / vfkredge_client / rest_robot_client.py View on Github external
"""Getting mac address for uuid"""
mac = get_mac()
doc['uuid']=mac

"""
If 'mem' keyword is passed as argument to this script,
the memory information of the robot is sent as PUT
"""
try:
    is_mem_info = sys.argv[1]
except: 
    is_mem_info = "config"
    
if is_mem_info == "mem":
    doc['cpu_usg'] = psutil.cpu_percent()
    doc['ram_usg'] = psutil.virtual_memory().percent


"""Sending Json command to Server Robot"""
put_ip = 'http PUT ' + server_ip + ':8000/things < rob_config.json'
put_ip = 'http PUT localhost:8000/things < rob_config.json'

try:
    subprocess.call(put_ip, shell=True)

except falcon.HTTP_503:
    print("Attempting to reconnect in 10 secs..")
    print("61!")
    time.sleep(10)
    #var = connect_server(put_ip)
    while var != 0:
        time.sleep(10)
github sdvillal / jagged / jagged / benchmarks / utils.py View on Github external
def available_ram():
    return psutil.virtual_memory().available
github juglab / n2v / n2v / data / generate.py View on Github external
def _memory_check(n_required_memory_bytes, thresh_free_frac=0.5, thresh_abs_bytes=1024*1024**2):
    try:
        # raise ImportError
        import psutil
        mem = psutil.virtual_memory()
        mem_frac = n_required_memory_bytes / mem.available
        if mem_frac > 1:
            raise MemoryError('Not enough available memory.')
        elif mem_frac > thresh_free_frac:
            print('Warning: will use at least %.0f MB (%.1f%%) of available memory.\n' % (n_required_memory_bytes/1024**2,100*mem_frac), file=sys.stderr)
            sys.stderr.flush()
    except ImportError:
        if n_required_memory_bytes > thresh_abs_bytes:
            print('Warning: will use at least %.0f MB of memory.\n' % (n_required_memory_bytes/1024**2), file=sys.stderr)
            sys.stderr.flush()
github fluiddyn / transonic / transonic / dist.py View on Github external
def get_num_jobs(self):
        try:
            num_jobs = int(os.environ[self.num_jobs_env_var])
        except KeyError:
            import multiprocessing

            num_jobs = multiprocessing.cpu_count()

            try:
                from psutil import virtual_memory
            except ImportError:
                pass
            else:
                avail_memory_in_Go = virtual_memory().available / 1e9
                limit_num_jobs = round(avail_memory_in_Go / 3)
                num_jobs = min(num_jobs, limit_num_jobs)
        return num_jobs