LoginSignup
6
14

More than 3 years have passed since last update.

pythonでCPU、メモリ、ディスク使用率をゲットするプログラム

Last updated at Posted at 2019-09-09

psutilをインストール

$ pip install -U psutil

CPU、メモリ、ディスク使用率をゲットするプログラム

resource.py

import psutil

# mem
mem = psutil.virtual_memory()
print(mem.percent)

# cpu
cpu = psutil.cpu_percent(interval=1)
print(cpu)

# disk
disk = psutil.disk_usage('/')
print(disk.percent)

実行結果

$ python resource.py
23.9
0.0
18.4

参考手順

公式サイト

6
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
14