Skip to main content

psutil is a cross-platform library for retrieving information onrunning processes and system utilization (CPU, memory, disks, network)in Python.

Project description

Download this month Latest version License Travis

Summary

psutil (python system and process utilities) is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network) in Python. It is useful mainly for system monitoring, profiling and limiting process resources and management of running processes. It implements many functionalities offered by command line tools such as: ps, top, lsof, netstat, ifconfig, who, df, kill, free, nice, ionice, iostat, iotop, uptime, pidof, tty, taskset, pmap. It currently supports Linux, Windows, OSX, FreeBSD and Sun Solaris, both 32-bit and 64-bit architectures, with Python versions from 2.6 to 3.4 (users of Python 2.4 and 2.5 may use 2.1.3 version). PyPy is also known to work.

Example applications

top nettop iotop

See also:

Example usages

CPU

>>> import psutil
>>> psutil.cpu_times()
scputimes(user=3961.46, nice=169.729, system=2150.659, idle=16900.540, iowait=629.59, irq=0.0, softirq=19.42, steal=0.0, guest=0, nice=0.0)
>>>
>>> for x in range(3):
...     psutil.cpu_percent(interval=1)
...
4.0
5.9
3.8
>>>
>>> for x in range(3):
...     psutil.cpu_percent(interval=1, percpu=True)
...
[4.0, 6.9, 3.7, 9.2]
[7.0, 8.5, 2.4, 2.1]
[1.2, 9.0, 9.9, 7.2]
>>>
>>>
>>> for x in range(3):
...     psutil.cpu_times_percent(interval=1, percpu=False)
...
scputimes(user=1.5, nice=0.0, system=0.5, idle=96.5, iowait=1.5, irq=0.0, softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0)
scputimes(user=1.0, nice=0.0, system=0.0, idle=99.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0)
scputimes(user=2.0, nice=0.0, system=0.0, idle=98.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0)
>>>
>>> psutil.cpu_count()
4
>>> psutil.cpu_count(logical=False)
2
>>>

Memory

>>> psutil.virtual_memory()
svmem(total=8374149120L, available=2081050624L, percent=75.1, used=8074080256L, free=300068864L, active=3294920704, inactive=1361616896, buffers=529895424L, cached=1251086336)
>>> psutil.swap_memory()
sswap(total=2097147904L, used=296128512L, free=1801019392L, 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)
>>>
>>> psutil.disk_io_counters(perdisk=False)
sdiskio(read_count=719566, write_count=1082197, read_bytes=18626220032, write_bytes=24081764352, read_time=5023392, write_time=63199568)
>>>

Network

>>> psutil.net_io_counters(pernic=True)
{'eth0': netio(bytes_sent=485291293, bytes_recv=6004858642, packets_sent=3251564, packets_recv=4787798, errin=0, errout=0, dropin=0, dropout=0),
 'lo': netio(bytes_sent=2838627, bytes_recv=2838627, packets_sent=30567, packets_recv=30567, errin=0, errout=0, dropin=0, dropout=0)}
>>>
>>> psutil.net_connections()
[pconn(fd=115, family=2, type=1, laddr=('10.0.0.1', 48776), raddr=('93.186.135.91', 80), status='ESTABLISHED', pid=1254),
 pconn(fd=117, family=2, type=1, laddr=('10.0.0.1', 43761), raddr=('72.14.234.100', 80), status='CLOSING', pid=2987),
 pconn(fd=-1, family=2, type=1, laddr=('10.0.0.1', 60759), raddr=('72.14.234.104', 80), status='ESTABLISHED', pid=None),
 pconn(fd=-1, family=2, type=1, laddr=('10.0.0.1', 51314), raddr=('72.14.234.83', 443), status='SYN_SENT', pid=None)
 ...]

Other system info

>>> psutil.users()
[user(name='giampaolo', terminal='pts/2', host='localhost', started=1340737536.0),
 user(name='giampaolo', terminal='pts/3', host='localhost', started=1340737792.0)]
>>>
>>> psutil.boot_time()
1365519115.0
>>>

Process management

>>> import psutil
>>> psutil.pids()
[1, 2, 3, 4, 5, 6, 7, 46, 48, 50, 51, 178, 182, 222, 223, 224,
 268, 1215, 1216, 1220, 1221, 1243, 1244, 1301, 1601, 2237, 2355,
 2637, 2774, 3932, 4176, 4177, 4185, 4187, 4189, 4225, 4243, 4245,
 4263, 4282, 4306, 4311, 4312, 4313, 4314, 4337, 4339, 4357, 4358,
 4363, 4383, 4395, 4408, 4433, 4443, 4445, 4446, 5167, 5234, 5235,
 5252, 5318, 5424, 5644, 6987, 7054, 7055, 7071]
>>>
>>> p = psutil.Process(7055)
>>> p.name()
'python'
>>> p.exe()
'/usr/bin/python'
>>> p.cwd()
'/home/giampaolo'
>>> p.cmdline()
['/usr/bin/python', 'main.py']
>>>
>>> p.status()
'running'
>>> p.username()
'giampaolo'
>>> p.create_time()
1267551141.5019531
>>> p.terminal()
'/dev/pts/0'
>>>
>>> p.uids()
puids(real=1000, effective=1000, saved=1000)
>>> p.gids()
pgids(real=1000, effective=1000, saved=1000)
>>>
>>> p.cpu_times()
pcputimes(user=1.02, system=0.31)
>>> p.cpu_percent(interval=1.0)
12.1
>>> p.cpu_affinity()
[0, 1, 2, 3]
>>> p.cpu_affinity([0])  # set
>>>
>>> p.memory_percent()
0.63423
>>>
>>> p.memory_info()
pmem(rss=7471104, vms=68513792)
>>> p.memory_info_ex()
extmem(rss=9662464, vms=49192960, shared=3612672, text=2564096, lib=0, data=5754880, dirty=0)
>>> p.memory_maps()
[pmmap_grouped(path='/lib/x86_64-linux-gnu/libutil-2.15.so', rss=16384, anonymous=8192, swap=0),
 pmmap_grouped(path='/lib/x86_64-linux-gnu/libc-2.15.so', rss=6384, anonymous=15, swap=0),
 pmmap_grouped(path='/lib/x86_64-linux-gnu/libcrypto.so.1.0.0', rss=34124, anonymous=1245, swap=0),
 pmmap_grouped(path='[heap]', rss=54653, anonymous=8192, swap=0),
 pmmap_grouped(path='[stack]', rss=1542, anonymous=166, swap=0),
 ...]
>>>
>>> p.io_counters()
pio(read_count=478001, write_count=59371, read_bytes=700416, write_bytes=69632)
>>>
>>> p.open_files()
[popenfile(path='/home/giampaolo/svn/psutil/somefile', fd=3)]
>>>
>>> p.connections()
[pconn(fd=115, family=2, type=1, laddr=('10.0.0.1', 48776), raddr=('93.186.135.91', 80), status='ESTABLISHED'),
 pconn(fd=117, family=2, type=1, laddr=('10.0.0.1', 43761), raddr=('72.14.234.100', 80), status='CLOSING'),
 pconn(fd=119, family=2, type=1, laddr=('10.0.0.1', 60759), raddr=('72.14.234.104', 80), status='ESTABLISHED'),
 pconn(fd=123, family=2, type=1, laddr=('10.0.0.1', 51314), raddr=('72.14.234.83', 443), status='SYN_SENT')]
>>>
>>> p.num_threads()
4
>>> p.num_fds()
8
>>> p.threads()
[pthread(id=5234, user_time=22.5, system_time=9.2891),
 pthread(id=5235, user_time=0.0, system_time=0.0),
 pthread(id=5236, user_time=0.0, system_time=0.0),
 pthread(id=5237, user_time=0.0707, system_time=1.1)]
>>>
>>> p.num_ctx_switches()
pctxsw(voluntary=78, involuntary=19)
>>>
>>> p.nice()
0
>>> p.nice(10)  # set
>>>
>>> p.ionice(psutil.IOPRIO_CLASS_IDLE)  # IO priority (Win and Linux only)
>>> p.ionice()
pionice(ioclass=3, value=0)
>>>
>>> p.rlimit(psutil.RLIMIT_NOFILE, (5, 5))  # set resource limits (Linux only)
>>> p.rlimit(psutil.RLIMIT_NOFILE)
(5, 5)
>>>
>>> p.suspend()
>>> p.resume()
>>>
>>> p.terminate()
>>> p.wait(timeout=3)
0
>>>
>>> psutil.test()
USER         PID %CPU %MEM     VSZ     RSS TTY        START    TIME  COMMAND
root           1  0.0  0.0   24584    2240            Jun17   00:00  init
root           2  0.0  0.0       0       0            Jun17   00:00  kthreadd
root           3  0.0  0.0       0       0            Jun17   00:05  ksoftirqd/0
...
giampaolo  31475  0.0  0.0   20760    3024 /dev/pts/0 Jun19   00:00  python2.4
giampaolo  31721  0.0  2.2  773060  181896            00:04   10:30  chrome
root       31763  0.0  0.0       0       0            00:05   00:00  kworker/0:1
>>>

Further process APIs

>>> for p in psutil.process_iter():
...     print(p)
...
psutil.Process(pid=1, name='init')
psutil.Process(pid=2, name='kthreadd')
psutil.Process(pid=3, name='ksoftirqd/0')
...
>>>
>>> def on_terminate(proc):
...     print("process {} terminated".format(proc))
...
>>> # waits for multiple processes to terminate
>>> gone, alive = psutil.wait_procs(procs_list, 3, callback=on_terminate)
>>>

Mailing list

http://groups.google.com/group/psutil/

Timeline

Release history Release notifications | RSS feed

This version

2.2.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

psutil-2.2.0.tar.gz (223.7 kB view details)

Uploaded Source

Built Distributions

psutil-2.2.0.win-amd64-py3.4.exe (316.4 kB view details)

Uploaded Source

psutil-2.2.0.win-amd64-py3.3.exe (316.4 kB view details)

Uploaded Source

psutil-2.2.0.win-amd64-py2.7.exe (318.0 kB view details)

Uploaded Source

psutil-2.2.0.win32-py3.4.exe (283.1 kB view details)

Uploaded Source

psutil-2.2.0.win32-py3.3.exe (283.1 kB view details)

Uploaded Source

psutil-2.2.0.win32-py2.7.exe (288.2 kB view details)

Uploaded Source

psutil-2.2.0.win32-py2.6.exe (288.4 kB view details)

Uploaded Source

psutil-2.2.0-cp34-none-win_amd64.whl (84.0 kB view details)

Uploaded CPython 3.4 Windows x86-64

psutil-2.2.0-cp34-none-win32.whl (81.9 kB view details)

Uploaded CPython 3.4 Windows x86

psutil-2.2.0-cp33-none-win_amd64.whl (84.0 kB view details)

Uploaded CPython 3.3 Windows x86-64

psutil-2.2.0-cp33-none-win32.whl (81.9 kB view details)

Uploaded CPython 3.3 Windows x86

psutil-2.2.0-cp27-none-win_amd64.whl (84.1 kB view details)

Uploaded CPython 2.7 Windows x86-64

psutil-2.2.0-cp27-none-win32.whl (81.9 kB view details)

Uploaded CPython 2.7 Windows x86

psutil-2.2.0-cp26-none-win32.whl (82.1 kB view details)

Uploaded CPython 2.6 Windows x86

File details

Details for the file psutil-2.2.0.tar.gz.

File metadata

  • Download URL: psutil-2.2.0.tar.gz
  • Upload date:
  • Size: 223.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for psutil-2.2.0.tar.gz
Algorithm Hash digest
SHA256 b15cc9e7cad0991bd1cb806fa90ea85ba3a95d0f1226625ecef993294ad61521
MD5 b8f5ce3c47edc5e4491ef05a61387116
BLAKE2b-256 bae4760f64a8a5a5f1b95f3ce17c0d51134952f930caf1218e6ce21902f6c4ab

See more details on using hashes here.

File details

Details for the file psutil-2.2.0.win-amd64-py3.4.exe.

File metadata

File hashes

Hashes for psutil-2.2.0.win-amd64-py3.4.exe
Algorithm Hash digest
SHA256 5e4508ca6822839f25310bfc14c050e60362dc29ddea6f5eac91de2c7423a471
MD5 ddfff92a84f3889515a689e9b9bebade
BLAKE2b-256 dd4631505418bd950b09d28c6c21be76a4a51d593ec06b412539797080c0aa6b

See more details on using hashes here.

File details

Details for the file psutil-2.2.0.win-amd64-py3.3.exe.

File metadata

File hashes

Hashes for psutil-2.2.0.win-amd64-py3.3.exe
Algorithm Hash digest
SHA256 fc6d348f603ae8465992a7edbc7c62cc16f0493bdd43aa609dcb7437992cac96
MD5 cb1c00188a87be9eefc425d7ff4699f9
BLAKE2b-256 32f1e98caa1f6be7ba49dfafa0fbb63f50ffa191d316a1b2b3ec431d97ebf494

See more details on using hashes here.

File details

Details for the file psutil-2.2.0.win-amd64-py2.7.exe.

File metadata

File hashes

Hashes for psutil-2.2.0.win-amd64-py2.7.exe
Algorithm Hash digest
SHA256 623baf2a213adc99cbc067e1db04b9e578eb4c38d9535c903e04b6d1ded10cab
MD5 36c71bda3b30b53961d1dc2e2286bc61
BLAKE2b-256 30a8d1754e9e5492717d1c1afb30970f0677056052859f1af935b48c72c6cd68

See more details on using hashes here.

File details

Details for the file psutil-2.2.0.win32-py3.4.exe.

File metadata

File hashes

Hashes for psutil-2.2.0.win32-py3.4.exe
Algorithm Hash digest
SHA256 4a0d8a192d1523a3f02a4028bf4ac296f7da92c935464d302618bd639c03a2c6
MD5 b3f4677505a775b73075d55959e57454
BLAKE2b-256 17fbae589efdfd076d1961e1f858c969d234a63e26f648a79b3fac0409e95c2f

See more details on using hashes here.

File details

Details for the file psutil-2.2.0.win32-py3.3.exe.

File metadata

File hashes

Hashes for psutil-2.2.0.win32-py3.3.exe
Algorithm Hash digest
SHA256 9db585f37d56381c37738e03aa8beb0b501b26adc7c70660ff182e0473f2cb0a
MD5 cb6ce79107737c412dfa6d7d7f65e48a
BLAKE2b-256 12c4cb75d51edb425ff77e2af5bb32e405ed41beb124ad062fb927bbe135c709

See more details on using hashes here.

File details

Details for the file psutil-2.2.0.win32-py2.7.exe.

File metadata

File hashes

Hashes for psutil-2.2.0.win32-py2.7.exe
Algorithm Hash digest
SHA256 83eb1739b7c87a21a65224d77217325e582199bedd0141b29dac81b4e4144c62
MD5 39faeeec6fa60188193e81f48d5fd31c
BLAKE2b-256 7a305bb6644318f2279caf5d334f32df19fe4b2bce11ef418af32124e16f8e98

See more details on using hashes here.

File details

Details for the file psutil-2.2.0.win32-py2.6.exe.

File metadata

File hashes

Hashes for psutil-2.2.0.win32-py2.6.exe
Algorithm Hash digest
SHA256 1f93ccdf415da40f15a84ab6d9d32ddda61bb1b20079dae602356e087f408d28
MD5 80bb19f113f37387974c9319ffdc8006
BLAKE2b-256 9c0df360da29c906dafd825edccc219e70dab73370ad2c287fa5baa9f7fa370b

See more details on using hashes here.

File details

Details for the file psutil-2.2.0-cp34-none-win_amd64.whl.

File metadata

File hashes

Hashes for psutil-2.2.0-cp34-none-win_amd64.whl
Algorithm Hash digest
SHA256 3636879fcbde2b0b63db08abd0e3673c2cc72bb14075e46e15f98774b0c78236
MD5 0cdd1937d11309a6d994466e5c5b991d
BLAKE2b-256 82edce9c4281fd8a944a725c0f9a5d77f32295777ab22f54b4f706a51d59edd3

See more details on using hashes here.

File details

Details for the file psutil-2.2.0-cp34-none-win32.whl.

File metadata

File hashes

Hashes for psutil-2.2.0-cp34-none-win32.whl
Algorithm Hash digest
SHA256 84299c41b251bef2a8b0812d651f4715209b3c4dfebe4a5df0f103bbdec78221
MD5 efd6ac1842c920c28ecfbb20b23f9c61
BLAKE2b-256 ef0e0cf2fea8f6e2e5ef84797eefc2c5ce561123e2417d7b931a6c54f9f8d413

See more details on using hashes here.

File details

Details for the file psutil-2.2.0-cp33-none-win_amd64.whl.

File metadata

File hashes

Hashes for psutil-2.2.0-cp33-none-win_amd64.whl
Algorithm Hash digest
SHA256 d664a896feb10ec5bf4c43f4df8b6c7fceeb94677004cc9cf8c9f35b52c0e4fc
MD5 be765be2c56fb82b7e3e674c142dbeae
BLAKE2b-256 bd08112807380b8e7b76de8c84f920234a0ebed35e6511271f93f900f691a10c

See more details on using hashes here.

File details

Details for the file psutil-2.2.0-cp33-none-win32.whl.

File metadata

File hashes

Hashes for psutil-2.2.0-cp33-none-win32.whl
Algorithm Hash digest
SHA256 73013822a953fc4e3fb269256ec01b261752c590e23851e666201d1bfd32a3a9
MD5 c89b8821ffea289732efa88f8aaf6f70
BLAKE2b-256 668d3143623c2f5bc264197727854040fdc02e3175b4ad991490586db7a512ed

See more details on using hashes here.

File details

Details for the file psutil-2.2.0-cp27-none-win_amd64.whl.

File metadata

File hashes

Hashes for psutil-2.2.0-cp27-none-win_amd64.whl
Algorithm Hash digest
SHA256 bbe719046986568ed3e84ce66ed617eebc46251ea8193566b3707abdf635afe6
MD5 bf7e1bde1137645935b56987838d6c0a
BLAKE2b-256 28284e4f94c9778ed16163f6c3dd696ce5e331121ac1600308830a3e98fa979a

See more details on using hashes here.

File details

Details for the file psutil-2.2.0-cp27-none-win32.whl.

File metadata

File hashes

Hashes for psutil-2.2.0-cp27-none-win32.whl
Algorithm Hash digest
SHA256 6ad0e79b95f57a20f0cace08a063b0fc33fd83da1e5e501bc800bc69329a4501
MD5 e8b6dca0853655120fc91eb61c408bc3
BLAKE2b-256 6ae696a4b4976f0eca169715d975b8c669b78b9afca58f9aadf261915694b73e

See more details on using hashes here.

File details

Details for the file psutil-2.2.0-cp26-none-win32.whl.

File metadata

File hashes

Hashes for psutil-2.2.0-cp26-none-win32.whl
Algorithm Hash digest
SHA256 c92d2853ac52d5aaf8c2366435fb74892f7503daf2cf56b785f1ecadbf68e712
MD5 e588998d4c9bde34e71cb59226ad8bb7
BLAKE2b-256 3c65f5bd2f8b54f14d950596c0c63d7b0f98b6dc779f7c61ac0dd2e9fc7e5e74

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page