본문으로 바로가기
 

psutil documentation — psutil 5.7.2 documentation

psutil documentation About psutil (python system and process utilities) is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network, sensors) in Python. It is useful mainly for system moni

psutil.readthedocs.io

 

파이썬 psutil 모듈 사용하기 : 시스템 정보 구하기

psutil documentation — psutil 5.7.2 documentation psutil documentation About psutil (python system and process utilities) is a cross-platform library for retrieving information on running processes..

jvvp.tistory.com

디스크 정보 구하기

디스크 정보는 다음 함수로 구합니다.

  • psutil.disk_partitions() : 마운트 되어있는 디스크의 장치 및 경로, 타입 정보
  • psutil.disk_usage(path) : 해당 경로를 포함하는 파티션의 통계 정보
  • psutil.disk_io_counters(perdisk=False, nowrap=True) : 디스크 I/O 의 통계 정보

마운트 되어있는 디스크들의 장치 및 경로 타입을 정보를 구합니다.

>>> import psutil
>>>
>>> psutil.disk_partitions()
[sdiskpart(device='C:\\', mountpoint='C:\\', fstype='NTFS', opts='rw,fixed'), sdiskpart(device='D:\\', mountpoint='D:\\', fstype='NTFS', opts='rw,fixed'), sdiskpart(device='E:\\', mountpoint='E:\\', fstype='NTFS', opts='rw,fixed'), sdiskpart(device='F:\\', mountpoint='F:\\', fstype='NTFS', opts='rw,fixed'), sdiskpart(device='G:\\', mountpoint='G:\\', fstype='', opts='fixed'), sdiskpart(device='H:\\', mountpoint='H:\\', fstype='NTFS', opts='rw,fixed')]

 

해당 경로의 디스크 정보

>>> psutil.disk_usage('E:')
sdiskusage(total=214748360704, used=70166200320, free=144582160384, percent=32.7)

 

다음과 같이 활용 가능합니다.

import psutil
from time import sleep

partitions = psutil.disk_partitions()
for p in partitions:
    print(p.mountpoint, p.fstype, end=' ')
    try:
        du = psutil.disk_usage(p.mountpoint)
        print(f'{du.percent}%')
    except:
        pass
더보기
C:\ NTFS 64.8%
D:\ NTFS 13.7%
E:\ NTFS 32.7%
F:\ NTFS 0.1%
G:\  H:\ NTFS 28.3%

 

BitLorBitLocker 로 암호화로 잠겨 있으면, 다음 에러 발생

OSError: [WinError -2144272384] 이 드라이브는 BitLocker 드라이브 암호화로 잠겨 있습니다. 제어판에서 이 드라이브의 잠금을 해제해야 
합니다: 'G'