Skip to content

Instantly share code, notes, and snippets.

@quangnhat185
Created August 25, 2021 13:59
Show Gist options
  • Save quangnhat185/2f96cd304bca58938428309b78229f38 to your computer and use it in GitHub Desktop.
Save quangnhat185/2f96cd304bca58938428309b78229f38 to your computer and use it in GitHub Desktop.
This script is used to extract Memory and CPU usage on Raspberry Pi
import psutil
import time
import logging
import os
import numpy as np
try:
## os.remove("./Data/Pi_ML")
## os.remove("./Data/Pi_CV")
pass
except:
pass
##logging.basicConfig(filename='./Data/Pi_ML',level=logging.INFO, filemode="w")
logging.basicConfig(filename='./Data/Pi_Multi',level=logging.INFO, filemode="w")
####print(psutil.cpu_percent())
####print(psutil.virtual_memory()) # physical memory usage
####print('memory % used:', psutil.virtual_memory()[2])
####print(psutil.cpu_count())
##
##
##
while True:
try:
print("CPU percent: ", psutil.cpu_percent(percpu=True), " Memory percent: ", psutil.virtual_memory()[2])
logging.info("CPU percent: %s Memory percent: %.2f" %(psutil.cpu_percent(percpu=False),psutil.virtual_memory()[2]))
## print('memory % used:', psutil.virtual_memory()[2])
## print(psutil.cpu_times())
time.sleep(0.5)
except KeyboardInterrupt:
break
© 2021 GitHub, Inc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment