Skip to content
프로젝트

소개

Python에서 프로세스와 시스템을 모니터링하기 위한 크로스 플랫폼 라이브러리

시스템 및 인프라

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
+1
in 7 days
+4
in 15 days
+12
in 1 month
+23

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original
psutil

Process and System Utilities for Python

Documentation    Blog    Forum    Who uses psutil   

Downloads Binary packages Latest version
Linux, Windows, macOS FreeBSD, NetBSD, OpenBSD Documentation

About

psutil is a cross-platform library for retrieving information about running processes and system utilization (CPU, memory, disks, network, sensors) in Python. It is useful mainly for system monitoring, profiling, limiting process resources, and managing running processes. It implements many functionalities offered by UNIX command line tool such as ps, top, free, iotop, netstat, ifconfig, lsof and others (see shell equivalents). Psutil supports the following platforms:

  • Linux
  • Windows
  • macOS
  • FreeBSD, OpenBSD, NetBSD
  • Sun Solaris
  • AIX

Adoption

psutil is among the top 100 most-downloaded packages on PyPI, with 420+ million downloads per month and 800,000+ GitHub repositories using it. See also adoptions and alternatives.

Install

pip install psutil

For platform-specific details see installation.

Documentation

psutil documentation is available at https://psutil.io.

Sponsors

Example usages

For the full API with more examples, see the API overview and API reference.

CPU

>>> import psutil
>>> psutil.cpu_percent(interval=1, percpu=True)
[4.0, 6.9, 3.7, 9.2]
>>> psutil.cpu_count(logical=False)
2
>>> psutil.cpu_freq()
scpufreq(current=931.42, min=800.0, max=3500.0)

Memory

>>> psutil.memory_physical()
smem(total=10367352832, available=6472179712, percent=37.6, used=8186245120, free=2181107712, ...)
>>> psutil.memory_swap()
sswap(total=2097147904, used=296128512, free=1801019392, percent=14.1, sin=304193536, sout=677842944)

Disks

>>> psutil.disk_partitions()
[sdiskpart(device='/dev/sda1', mountpoint='/', fstype='ext4', opts='rw,nosuid'),
 sdiskpart(device='/dev/sda2', mountpoint='/home', fstype='ext', opts='rw')]
>>> psutil.disk_usage('/')
sdiskusage(total=21378641920, used=4809781248, free=15482871808, percent=22.5)

Network

>>> psutil.net_io_counters(pernic=True)
{'eth0': snetio(bytes_sent=485291293, bytes_recv=6004858642, ...),
 'lo': snetio(bytes_sent=2838627, bytes_recv=2838627, ...)}
>>> psutil.net_connections(kind='tcp')
[sconn(fd=115, family=2, type=1, laddr=addr(ip='10.0.0.1', port=48776), raddr=addr(ip='93.186.135.91', port=80), status='ESTABLISHED', pid=1254),
 ...]

Sensors

>>> psutil.sensors_temperatures()
{'coretemp': [shwtemp(label='Physical id 0', current=52.0, high=100.0, critical=100.0),
              shwtemp(label='Core 0', current=45.0, high=100.0, critical=100.0)]}
>>> psutil.sensors_battery()
sbattery(percent=93, secsleft=16628, power_plugged=False)

Processes

>>> p = psutil.Process(7055)
>>> p.name()
'python3'
>>> p.exe()
'/usr/bin/python3'
>>> p.cpu_percent(interval=1.0)
12.1
>>> p.memory_info()
pmem(rss=3164160, vms=4410163, shared=897433, text=302694, data=2422374)
>>> p.net_connections(kind='tcp')
[pconn(fd=115, family=2, type=1, laddr=addr(ip='10.0.0.1', port=48776), raddr=addr(ip='93.186.135.91', port=80), status='ESTABLISHED')]
>>> p.open_files()
[popenfile(path='/home/giampaolo/monit.py', fd=3, position=0, mode='r', flags=32768)]
>>>
>>> for p in psutil.process_iter(['pid', 'name']):
...     print(p.snapshot.pid, p.snapshot.name)
...
1 systemd
2 kthreadd
3 ksoftirqd/0
...

License

BSD-3

관련 프로젝트 살펴보기

불러오는 중…