Last active
November 20, 2017 19:23
-
-
Save scottx611x/c2a21c8c545d95f1ace68faee5826bbe to your computer and use it in GitHub Desktop.
Gather `ps` output sorted by memory usage and log to a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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