-
<PYTHON>시스템 정보 가져오기(CPU, RAM, DISK)Flower in my dev/Python 2015. 4. 21. 14:03123456789101112131415161718192021222324252627282930313233343536373839404142import time, randomimport psutilimport os# Return CPU temperature as a character stringdef getCPUTemperature():res = os.popen('vcgencmd measure_temp').readline()return(res.replace("temp=","").replace("'C\n",""))# Return RAM information (unit=kb) in a list# Index 0: total RAM# Index 1: used RAM# Index 2: free RAMdef getRAMInfo():p = os.popen('free')i = 0while 1:i = i + 1line = p.readline()if i==2:return(line.split()[1:4])# Return % of CPU used by user as a character stringdef getCPUUsage():cpu = psutil.cpu_percent(interval=1)return cpu*10#return(str(os.popen("top -n1 | awk '/Cpu\(s\):/ {print $2}'").readline().strip(\# )))# Return information about disk space as a list (unit included)# Index 0: total disk space# Index 1: used disk space# Index 2: remaining disk space# Index 3: percentage of disk useddef getDiskSpace():p = os.popen("df -h /")i = 0while 1:i = i +1line = p.readline()if i==2:return(line.split()[1:5])
cs psutil 모듈을 설치하여야 동작한다.
pip install psutil
'Flower in my dev > Python' 카테고리의 다른 글
<PYTHON> TCP_Echo_Server (0) 2015.04.21 <PYTHON> UDP_Echo_Server (0) 2015.04.21 <PYTHON>[loop] (0) 2015.04.14 <PYTHON>[리스트, 튜플, 사전] (0) 2015.04.13 <PYTHON>[내장함수] (0) 2015.04.13