OLD | NEW |
1 | |
2 | |
3 | |
4 <html> | 1 <html> |
5 <head> | 2 <head> |
6 <title>psutil</title> | 3 <title>Home</title> |
7 </head> | 4 </head> |
8 <body> | 5 <body> |
9 | 6 |
10 | 7 |
11 | 8 |
12 | 9 |
13 <div id="wikicontent"> | 10 |
14 <table width="100%" border="0" cellspacing="0" cellpadding="0"> | 11 <div> |
| 12 <table> |
15 <tr> | 13 <tr> |
16 | 14 |
17 <td class="vt" id="wikimaincol" width="100%"> | |
18 | 15 |
19 <div id="wikiheader" style="margin-bottom:1em"> | 16 <td style="vertical-align:top; padding-left:5px"> |
20 | 17 |
21 | 18 <div id="wikicontent"> |
22 </div> | 19 <div class="vt" id="wikimaincol"> |
23 <h1><a name="Summary"></a>Summary<a href="#Summary" class="section_anchor"></a>
</h1><p>psutil is a module providing an interface for retrieving information on
running processes and system utilization (CPU, memory) in a portable way by usin
g Python, implementing many functionalities offered by command line tools like <
strong>ps</strong>, <strong>top</strong>, <strong>kill</strong> and Windows <str
ong>task manager</strong>. </p><p>It currently supports <strong>Linux</strong>,
<strong>OS X</strong>, <strong>FreeBSD</strong> and <strong>Windows</strong> wit
h Python versions from <strong>2.4</strong> to <strong>3.1</strong> by using a u
nique code base. </p><h1><a name="Example_usage"></a>Example usage<a href="#Exam
ple_usage" class="section_anchor"></a></h1><h3><a name="process_management"></a>
process management<a href="#process_management" class="section_anchor"></a></h3>
<pre class="prettyprint">>>> import psutil | 20 <h1><a name="Summary"></a>Summary<a href="#Summary" class="section_anchor"></a>
</h1><p>psutil is a module providing an interface for retrieving information on
all running processes and system utilization (CPU, disk, memory) in a portable w
ay by using <strong>Python</strong>, implementing many functionalities offered b
y command line tools such as: </p><ul><li>ps </li><li>top </li><li>df </li><li>k
ill </li><li>free </li><li>lsof </li><li>netstat </li><li>nice </li><li>ionice
</li><li>uptime </li><li>tty </li></ul><p>It currently supports <strong>Linux</s
trong>, <strong>Windows</strong>, <strong>OSX</strong> and <strong>FreeBSD</stro
ng> both <strong>32-bit</strong> and <strong>64-bit</strong> with Python version
s from <strong>2.4</strong> to <strong>3.3</strong> by using a single code base.
</p><p><a href="http://code.google.com/p/psutil/#Donate" rel="nofollow"></a> </
p><h1><a name="Example_usages"></a>Example usages<a href="#Example_usages" class
="section_anchor"></a></h1><h3><a name="CPU"></a>CPU<a href="#CPU" class="sectio
n_anchor"></a></h3><pre class="prettyprint">>>> import psutil |
| 21 >>> psutil.cpu_times() |
| 22 cputimes(user=3961.46, nice=169.729, system=2150.659, idle=16900.540, iowait=629
.509, irq=0.0, softirq=19.422) |
| 23 >>> |
| 24 >>> for x in range(3): |
| 25 ... psutil.cpu_percent(interval=1) |
| 26 ... |
| 27 4.0 |
| 28 5.9 |
| 29 3.8 |
| 30 >>> |
| 31 >>> for x in range(3): |
| 32 ... psutil.cpu_percent(interval=1, percpu=True) |
| 33 ... |
| 34 [4.0, 34.2] |
| 35 [7.0, 8.5] |
| 36 [1.2, 9.0] |
| 37 >>></pre><h3><a name="Memory"></a>Memory<a href="#Memory" class="sectio
n_anchor"></a></h3><pre class="prettyprint">>>> psutil.phymem_usage() |
| 38 usage(total=4153868288, used=2854199296, free=1299668992, percent=34.6) |
| 39 >>> psutil.virtmem_usage() |
| 40 usage(total=2097147904, used=4096, free=2097143808, percent=0.0) |
| 41 >>></pre><h3><a name="Disks"></a>Disks<a href="#Disks" class="section_a
nchor"></a></h3><pre class="prettyprint">>>> psutil.get_partitions() |
| 42 [partition(device='/dev/sda3', mountpoint='/', fstype='
ext4'), |
| 43 partition(device='/dev/sda7', mountpoint='/home', fstype=&#
x27;ext4')] |
| 44 >>> |
| 45 >>> psutil.disk_usage('/') |
| 46 usage(total=21378641920, used=4809781248, free=15482871808, percent=22.5) |
| 47 >>></pre><h3><a name="Process_management"></a>Process management<a href
="#Process_management" class="section_anchor"></a></h3><pre class="prettyprint">
>>> import psutil |
24 >>> psutil.get_pid_list() | 48 >>> psutil.get_pid_list() |
25 [1, 2, 3, 4, 5, 6, 7, 46, 48, 50, 51, 178, 182, 222, 223, 224, | 49 [1, 2, 3, 4, 5, 6, 7, 46, 48, 50, 51, 178, 182, 222, 223, 224, |
26 268, 1215, 1216, 1220, 1221, 1243, 1244, 1301, 1601, 2237, 2355, | 50 268, 1215, 1216, 1220, 1221, 1243, 1244, 1301, 1601, 2237, 2355, |
27 2637, 2774, 3932, 4176, 4177, 4185, 4187, 4189, 4225, 4243, 4245, | 51 2637, 2774, 3932, 4176, 4177, 4185, 4187, 4189, 4225, 4243, 4245, |
28 4263, 4282, 4306, 4311, 4312, 4313, 4314, 4337, 4339, 4357, 4358, | 52 4263, 4282, 4306, 4311, 4312, 4313, 4314, 4337, 4339, 4357, 4358, |
29 4363, 4383, 4395, 4408, 4433, 4443, 4445, 4446, 5167, 5234, 5235, | 53 4363, 4383, 4395, 4408, 4433, 4443, 4445, 4446, 5167, 5234, 5235, |
30 5252, 5318, 5424, 5644, 6987, 7054, 7055, 7071] | 54 5252, 5318, 5424, 5644, 6987, 7054, 7055, 7071] |
| 55 >>> |
31 >>> p = psutil.Process(7055) | 56 >>> p = psutil.Process(7055) |
32 >>> p.name | 57 >>> p.name |
33 'python' | 58 'python' |
34 >>> p.path | 59 >>> p.exe |
35 '/usr/bin' | 60 '/usr/bin/python' |
36 >>> p.cmdline | 61 >>> p.cmdline |
37 ['/usr/bin/python', '-O', 'run.py'] | 62 ['/usr/bin/python', 'main.py'] |
38 >>> p.uid | 63 >>> str(p.status) |
39 1000 | 64 'running' |
40 >>> p.gid | 65 >>> |
41 1000 | 66 >>> p.uids |
| 67 user(real=1000, effective=1000, saved=1000) |
| 68 >>> p.gids |
| 69 group(real=1000, effective=1000, saved=1000) |
42 >>> p.username | 70 >>> p.username |
43 'jake' | 71 'giampaolo' |
44 >>> p.create_time | 72 >>> p.create_time |
45 1267551141.5019531 | 73 1267551141.5019531 |
46 >>> p.get_cpu_percent() | 74 >>> p.get_cpu_percent(interval=1.0) |
47 12.31243 | 75 12.1 |
48 >>> p.get_memory_percent() | 76 >>> p.get_memory_percent() |
49 0.63423 | 77 0.63423 |
50 >>> rss, vms = p.get_memory_info() | 78 >>> p.get_memory_info() |
51 >>> "Resident memory: %s KB" %(rss / 1024) | 79 meminfo(rss=7471104, vms=68513792) |
52 'Resident memory: 3768 KB' | 80 >>> p.get_io_counters() |
53 >>> "Virtual memory: %s KB" %(vms / 1024) | 81 io(read_count=478001, write_count=59371, read_bytes=700416, write_bytes=69632) |
54 'Virtual memory: 6176 KB' | 82 >>> |
| 83 >>> p.get_open_files() |
| 84 [openfile(path='/home/giampaolo/svn/psutil/somefile', fd=3)] |
| 85 >>> |
| 86 >>> p.get_connections() |
| 87 [connection(fd=115, family=2, type=1, local_address=('10.0.0.1', 48776
), remote_address=('93.186.135.91', 80), status='ESTABLISHED'
;), |
| 88 connection(fd=117, family=2, type=1, local_address=('10.0.0.1', 43761
), remote_address=('72.14.234.100', 80), status='CLOSING'), |
| 89 connection(fd=119, family=2, type=1, local_address=('10.0.0.1', 60759
), remote_address=('72.14.234.104', 80), status='ESTABLISHED'
;), |
| 90 connection(fd=123, family=2, type=1, local_address=('10.0.0.1', 51314
), remote_address=('72.14.234.83', 443), status='SYN_SENT')] |
| 91 >>> |
| 92 >>> p.get_threads() |
| 93 [thread(id=5234, user_time=22.5, system_time=9.2891), |
| 94 thread(id=5235, user_time=0.0, system_time=0.0), |
| 95 thread(id=5236, user_time=0.0, system_time=0.0), |
| 96 thread(id=5237, user_time=0.0707, system_time=1.1)] |
| 97 >>> |
| 98 >>> p.nice |
| 99 0 |
| 100 >>> p.nice = 10 # set/change process priority |
| 101 >>> p.nice |
| 102 10 |
55 >>> | 103 >>> |
56 >>> p.suspend() | 104 >>> p.suspend() |
57 >>> p.resume() | 105 >>> p.resume() |
| 106 >>> |
| 107 >>> p.terminate() |
| 108 >>> p.wait(timeout=3) |
| 109 0 |
| 110 >>> |
58 >>> psutil.test() | 111 >>> psutil.test() |
59 UID PID %CPU %MEM VSZ RSS START TIME COMMAND | 112 UID PID %CPU %MEM VSZ RSS START TIME COMMAND |
60 0 0 0.0 0.0 0 0 00:12 00:00 [sched] | 113 0 0 0.0 0.0 0 0 00:12 00:00 [sched] |
61 0 1 0.0 0.3 1740 600 00:12 00:04 /sbin/init | 114 0 1 0.0 0.3 1740 600 00:12 00:04 /sbin/init |
62 0 2 0.0 0.0 0 0 00:12 00:00 [kthreadd] | 115 0 2 0.0 0.0 0 0 00:12 00:00 [kthreadd] |
63 0 3 0.0 0.0 0 0 00:12 00:00 [migration/0] | 116 0 3 0.1 0.0 0 0 00:12 00:00 [migration/0] |
64 ... | 117 ... |
65 0 13239 0.0 2.6 13604 1044 00:38 00:00 /usr/sbin/smbd -D | 118 0 13239 0.0 2.6 13604 1044 00:38 00:00 /usr/sbin/smbd -D |
66 1000 23648 0.0 2.4 12512 2008 14:43 00:06 sshd: user@pts/2 | 119 1000 23648 1.1 2.4 12512 2008 14:43 00:06 sshd: user@pts/2 |
67 1000 23649 0.0 1.2 5944 3340 14:43 00:00 -bash | 120 1000 23649 0.0 1.2 5944 3340 14:43 00:00 -bash |
68 0 25926 0.0 1.1 5432 3072 17:55 00:00 -su | 121 0 25926 0.3 1.1 5432 3072 17:55 00:00 -su |
69 0 28655 0.0 1.0 4932 3204 21:58 00:00 python _psutil.py | 122 0 28655 0.0 1.0 4932 3204 21:58 00:00 python _psutil.py |
70 >>></pre><h3><a name="System_monitoring_(CPU_and_memory)"></a>System mo
nitoring (CPU and memory)<a href="#System_monitoring_(CPU_and_memory)" class="se
ction_anchor"></a></h3><pre class="prettyprint">>>> import psutil, time | 123 >>></pre><h1><a name="Donate"></a>Donate<a href="#Donate" class="sectio
n_anchor"></a></h1><p>A lot of time and effort went into making psutil as it is
right now. If you feel psutil is useful to you or your business and want to supp
ort it's future development please consider donating us (Giampaolo Rodolà a
nd Jay Loden) some money. We only ask for a small donation, but of course we app
reciate any amount. </p><p><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s
-xclick&hosted_button_id=A9ZS7PKKRM3S8" rel="nofollow"></a> </p><h2><a name=
"People_who_donated_so_far"></a>People who donated so far<a href="#People_who_do
nated_so_far" class="section_anchor"></a></h2><ul><li>Kim Gräsman </li></ul><h1>
<a name="Mailing_lists"></a>Mailing lists<a href="#Mailing_lists" class="section
_anchor"></a></h1><p><strong>Users</strong><br><a href="http://groups.google.com
/group/psutil/" rel="nofollow">http://groups.google.com/group/psutil/</a> </p><p
><strong>Developers</strong><br><a href="http://groups.google.com/group/psutil-d
ev/" rel="nofollow">http://groups.google.com/group/psutil-dev/</a> </p><p><stron
g>SVN commits and issue tracker changes</strong><br><a href="http://groups.googl
e.com/group/psutil-commits/" rel="nofollow">http://groups.google.com/group/psuti
l-commits/</a> </p><h1><a name="Contribute"></a>Contribute<a href="#Contribute"
class="section_anchor"></a></h1><p>If you want to help or just give us suggestio
ns about the project and other related things, subscribe to the <a href="http:/
/groups.google.com/group/psutil" rel="nofollow">discussion mailing list</a>. If
you want to talk with project team members about psutil and other related things
feel free to contact us at the following addresses: </p><p><table class="wikita
ble"><tr><td style="border: 1px solid #ccc; padding: 5px;"> <strong>Name</strong
> </td><td style="border: 1px solid #ccc; padding: 5px;"> <strong>Country</stron
g> </td><td style="border: 1px solid #ccc; padding: 5px;"> <strong>E-mail</stron
g> </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;"> Giampaolo R
odola' </td><td style="border: 1px solid #ccc; padding: 5px;"> Turin (Italy
) </td><td style="border: 1px solid #ccc; padding: 5px;"> g.rodola at gmail dot
com </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;"> Jay Loden
</td><td style="border: 1px solid #ccc; padding: 5px;"> New Jersey (USA) </td><t
d style="border: 1px solid #ccc; padding: 5px;"> jloden at gmail dot com </td><
/tr> </table></p><p>Feedbacks and suggestions are greatly appreciated as well as
new testers and coders willing to join the development.<br> For any bug report,
patch proposal or feature request, add an entry into the <a href="http://code.g
oogle.com/p/psutil/issues/list" rel="nofollow">Issue Tracker</a>.<br> </p><p>Tha
nk you. </p> |
71 >>> print psutil.cpu_times() | |
72 softirq=50.87; iowait=39.63; system=1130.67; idle=164171.41; user=965.15; irq=7.
08; nice=0.0 | |
73 >>> | |
74 >>> while 1: | |
75 ... print round(psutil.cpu_percent(), 1) | |
76 ... time.sleep(1) | |
77 ... | |
78 5.4 | |
79 3.2 | |
80 7.3 | |
81 7.1 | |
82 2.5 | |
83 Traceback (most recent call last): | |
84 File "<stdin>", line 3, in <module> | |
85 KeyboardInterrupt | |
86 >>> | |
87 >>> psutil.TOTAL_PHYMEM | |
88 526458880 | |
89 >>> psutil.avail_phymem() | |
90 153530368 | |
91 >>> psutil.total_virtmem() | |
92 197365760 | |
93 >>> psutil.avail_virtmem() | |
94 194277376</pre><h1><a name="Mailing_lists"></a>Mailing lists<a href="#Mailing_li
sts" class="section_anchor"></a></h1><p><strong>Users</strong><br><a href="http:
//groups.google.com/group/psutil/topics" rel="nofollow">http://groups.google.com
/group/psutil/topics</a> </p><p><strong>Developers</strong><br><a href="http://g
roups.google.com/group/psutil-dev/topics" rel="nofollow">http://groups.google.co
m/group/psutil-dev/topics</a> </p><p><strong>SVN commits and issue tracker chang
es</strong><br><a href="http://groups.google.com/group/psutil-commits/topics" re
l="nofollow">http://groups.google.com/group/psutil-commits/topics</a> </p><h1><a
name="Contribute"></a>Contribute<a href="#Contribute" class="section_anchor"></
a></h1><p>If you want to help or just give us suggestions about the project and
other related things, subscribe to the <a href="http://groups.google.com/group/
psutil" rel="nofollow">discussion mailing list</a>. If you want to talk with pro
ject team members about psutil and other related things feel free to contact us
at the following addresses: </p><p><table><tr><td style="border: 1px solid #aaa;
padding: 5px;"> <strong>Name</strong> </td><td style="border: 1px solid #aaa; p
adding: 5px;"> <strong>Country</strong> </td><td style="border: 1px solid #aaa;
padding: 5px;"> <strong>E-mail</strong> </td></tr> <tr><td style="border: 1px so
lid #aaa; padding: 5px;"> Jay Loden </td><td style="border: 1px solid #aaa; padd
ing: 5px;"> New Jersey (USA) </td><td style="border: 1px solid #aaa; padding: 5p
x;"> jloden at gmail dot com </td></tr> <tr><td style="border: 1px solid #aaa;
padding: 5px;"> Giampaolo Rodola' </td><td style="border: 1px solid #aaa; p
adding: 5px;"> Turin (Italy) </td><td style="border: 1px solid #aaa; padding: 5p
x;"> g.rodola at gmail dot com </td></tr> </table></p><p>Feedbacks and suggestio
ns are greatly appreciated as well as new testers and coders willing to join the
development.<br> For any bug report, patch proposal or feature request, add an
entry into the <a href="http://code.google.com/p/psutil/issues/list" rel="nofoll
ow">Issue Tracker</a>.<br> </p><p>Thank you. </p> | |
95 | |
96 | |
97 </body> | 124 </body> |
98 </html> | 125 </html> |
99 | |
OLD | NEW |