Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

psutil virtual memory units of measurement?

Tags:

When running psutil.virtual_memory() i'm getting output like this:

    >>psutil.virtual_memory()
    vmem(total=8374149120L, available=1247768576L)

But what unit of measurement are these values? The documentation simply claims that its the "total physical memory available" but nothing more. I'm trying to translate it into values that the user can actually relate to (ie GBs).

Thanks in advance

like image 939
user3063850 Avatar asked Feb 15 '14 02:02

user3063850


People also ask

How does psutil work?

Psutil is a Python cross-platform library used to access system details and process utilities. It is used to keep track of various resources utilization in the system. Usage of resources like CPU, memory, disks, network, sensors can be monitored.

What is Psutil?

psutil (process and system utilities) is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network, sensors) in Python. It is useful mainly for system monitoring, profiling and limiting process resources and management of running processes.


2 Answers

why not use bit shift operator: if you want to display in human readable way, just like this!

values = psutil.virtual_memory()

display in MB format

total = values.total >> 20

display in GB format

total = values.total >> 30
like image 181
ha2ar6 Avatar answered Sep 29 '22 19:09

ha2ar6


1024^3 = Byte to Gigabyte
So I think this work:

import psutil
memory = psutil.virtual_memory().total / (1024.0 ** 3)
print(memory)
like image 43
Ardi Nusawan Avatar answered Sep 29 '22 19:09

Ardi Nusawan