Created
September 29, 2015 21:32
-
-
Save majora2007/e0cb2c80a1641cb7b732 to your computer and use it in GitHub Desktop.
Simple way to collect uptime for Plex
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 time | |
import psutil | |
process = None | |
sleep_time_secs = 10 | |
if __name__ == '__main__': | |
while True: | |
if process is None: | |
all_pids = psutil.pids() | |
for p in all_pids: | |
proc = psutil.Process(p) | |
if proc.name() == 'Plex.exe': | |
process = proc | |
break | |
else: | |
with open('system-monitor.log', 'w') as outfile: | |
outfile.write('Starting collection of ' + process.name() + '\n') | |
outfile.write('CPU Percent: ' + str(process.cpu_percent(interval=1.0)) + '\n') | |
outfile.write('Memory Percent: ' + str(process.memory_percent()) + '\n') | |
outfile.write('Uptime (secs): ' + str((datetime.datetime.now() - datetime.datetime.fromtimestamp(process.create_time())).total_seconds()) + '\n') | |
print 'Sleeping...' | |
time.sleep(sleep_time_secs) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment