Skip to content

Instantly share code, notes, and snippets.

@majora2007
Created September 29, 2015 21:32
Show Gist options
  • Save majora2007/e0cb2c80a1641cb7b732 to your computer and use it in GitHub Desktop.
Save majora2007/e0cb2c80a1641cb7b732 to your computer and use it in GitHub Desktop.
Simple way to collect uptime for Plex
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