株式会社ヴァンデミックシステム

Blog

<スポンサーリンク>

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

参考手順

公式サイト

<スポンサーリンク>

コメントを残す

Allowed tags:  you may use these HTML tags and attributes: <a href="">, <strong>, <em>, <h1>, <h2>, <h3>
Please note:  all comments go through moderation.

*

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)