def get_memory_usage(output_dict):
my_dict = {}
memory_usage = psutil.virtual_memory()
memory_total_gb = float(memory_usage.total)/(1024*1024*1024)
memory_used_gb = float(memory_usage.used)/(1024*1024*1024)
memory_available_gb = float(memory_usage.available)/(1024*1024*1024)
memory_buffers_gb = float(memory_usage.buffers)/(1024*1024*1024)
my_dict["ram_total_gb"] = "{:.2f}".format(memory_total_gb)
my_dict["ram_used_gb"] = "{:.2f}".format(memory_used_gb)
my_dict["ram_available_gb"] = "{:.2f}".format(memory_available_gb)
my_dict["ram_buffers_gb"] = "{:.2f}".format(memory_buffers_gb)
percent_ratio = float(my_dict["ram_used_gb"])*100/float(my_dict["ram_total_gb"])
my_dict["used_percentage"] = "%s(%sgb/%sgb)" % \
("{:.2f}".format(percent_ratio) + "%", \
my_dict["ram_used_gb"], my_dict["ram_total_gb"])
output_dict["ram"] = my_dict
# https://stackoverflow.com/questions/276052/how-to-get-current-cpu-and-ram-usage-in-python
评论列表
文章目录