Skip to content

Instantly share code, notes, and snippets.

@usuyama
Created October 17, 2019 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save usuyama/3420762bd6f2919fa9f799b0b8fdbe4b to your computer and use it in GitHub Desktop.
Save usuyama/3420762bd6f2919fa9f799b0b8fdbe4b to your computer and use it in GitHub Desktop.
print system memory usage Linux/Ubuntu Python
def print_memory_usage():
import os
lines = os.popen('free -t -m').readlines()
tot_m, used_m, free_m = map(int, lines[-1].split()[1:])
for l in lines:
print(l.rstrip())
return {'total_memory': tot_m, 'used_memory': used_m, 'free_memory': free_m}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment