I am trying to convert total physical memory into stick value, ie 128gb, 64gb..etc.
if I take the value of total ram from my servers, example 16826298368, and run this code I get and expected output of 16gb. Which is great. But as the memory values increases, it begins to drift.
Example: 134931955712 produces 126GB where 128GB is expected.
Example: 67519483904 produces 63GB where 64GB is expected.
So my question is, how can I modify to get the expected output consistently as the value changes? The memory value is provided by a few different bits of code depending on the OS. We use psutil on Solaris for example. psutil.virtual_memory().total
def transform_memory(data):
for x in ["bytes", " KB", " MB", " GB"]:
if data < 1024.0:
return "%3.1f%s" % (math.ceil(data), x)
data /= 1024.0
return "%3.1f%s" % (data, " TB")