Skip to content

Instantly share code, notes, and snippets.

@scottx611x
Last active November 20, 2017 19:23
Show Gist options
  • Save scottx611x/c2a21c8c545d95f1ace68faee5826bbe to your computer and use it in GitHub Desktop.
Save scottx611x/c2a21c8c545d95f1ace68faee5826bbe to your computer and use it in GitHub Desktop.
Gather `ps` output sorted by memory usage and log to a file
import datetime
import sys
import time
from subprocess import check_output
try:
filename = sys.argv[1]
except IndexError as e:
print "Must specify a filename."
sys.exit(1)
while True:
with open(filename, "a") as f:
output = check_output("ps aux --sort -rss".split(" "))
timestamp = datetime.datetime.fromtimestamp(
time.time()
).strftime('%Y-%m-%d %H:%M:%S')
f.write("\nTIMESTAMP: {}\nTOP OUTPUT:\n{}\n".format(timestamp, output))
time.sleep(1800)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment