python/psutil/README

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/python/psutil/README	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,217 @@
     1.4 +===========
     1.5 +Quick links
     1.6 +===========
     1.7 +
     1.8 +* `Home page <http://code.google.com/p/psutil>`_
     1.9 +* `Download <http://code.google.com/p/psutil/downloads/list>`_
    1.10 +* `Documentation <http://code.google.com/p/psutil/wiki/Documentation>`_
    1.11 +
    1.12 +=======
    1.13 +Summary
    1.14 +=======
    1.15 +
    1.16 +psutil is a module providing an interface for retrieving information on all
    1.17 +running processes and system utilization (CPU, memory, disks, network, users) in
    1.18 +a portable way by using Python, implementing many functionalities offered by
    1.19 +command line tools such as:  **ps, top, df, kill, free, lsof, free, netstat,
    1.20 +ifconfig, nice, ionice, iostat, iotop, uptime, pidof, tty, who, taskset, pmap**.
    1.21 +
    1.22 +It currently supports **Linux**, **Windows**, **OSX**, **FreeBSD**,
    1.23 +**Sun Solaris** both **32-bit** and **64-bit** with Python versions from **2.4**
    1.24 +to **3.3** by using a single code base.
    1.25 +
    1.26 +==============
    1.27 +Example usages
    1.28 +==============
    1.29 +
    1.30 +CPU
    1.31 +===
    1.32 +
    1.33 +>>> import psutil
    1.34 +>>> psutil.cpu_times()
    1.35 +cputimes(user=3961.46, nice=169.729, system=2150.659, idle=16900.540,
    1.36 +         iowait=629.509, irq=0.0, softirq=19.422, steal=0.0, guest=0, nice=0.0)
    1.37 +>>>
    1.38 +>>> for x in range(3):
    1.39 +...     psutil.cpu_percent(interval=1)
    1.40 +...
    1.41 +4.0
    1.42 +5.9
    1.43 +3.8
    1.44 +>>>
    1.45 +>>> for x in range(3):
    1.46 +...     psutil.cpu_percent(interval=1, percpu=True)
    1.47 +...
    1.48 +[4.0, 6.9]
    1.49 +[7.0, 8.5]
    1.50 +[1.2, 9.0]
    1.51 +>>>
    1.52 +>>> for x in range(3):
    1.53 +...     psutil.cpu_times_percent(interval=1, percpu=False)
    1.54 +...
    1.55 +cpupercent(user=1.5, nice=0.0, system=0.5, idle=96.5, iowait=1.5, irq=0.0,
    1.56 +           softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0)
    1.57 +cpupercent(user=1.0, nice=0.0, system=0.0, idle=99.0, iowait=0.0, irq=0.0,
    1.58 +           softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0)
    1.59 +cpupercent(user=2.0, nice=0.0, system=0.0, idle=98.0, iowait=0.0, irq=0.0,
    1.60 +           softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0)
    1.61 +
    1.62 +Memory
    1.63 +======
    1.64 +
    1.65 +>>> psutil.virtual_memory()
    1.66 +vmem(total=8374149120L, available=2081050624L, percent=75.1, used=8074080256L,
    1.67 +     free=300068864L, active=3294920704, inactive=1361616896, buffers=529895424L,
    1.68 +     cached=1251086336)
    1.69 +>>> psutil.swap_memory()
    1.70 +swap(total=2097147904L, used=296128512L, free=1801019392L, percent=14.1,
    1.71 +     sin=304193536, sout=677842944)
    1.72 +>>>
    1.73 +
    1.74 +
    1.75 +Disks
    1.76 +=====
    1.77 +
    1.78 +>>> psutil.disk_partitions()
    1.79 +[partition(device='/dev/sda1', mountpoint='/', fstype='ext4', opts='rw,nosuid'),
    1.80 + partition(device='/dev/sda2', mountpoint='/home', fstype='ext, opts='rw')]
    1.81 +>>>
    1.82 +>>> psutil.disk_usage('/')
    1.83 +usage(total=21378641920, used=4809781248, free=15482871808, percent=22.5)
    1.84 +>>>
    1.85 +>>> psutil.disk_io_counters()
    1.86 +iostat(read_count=719566, write_count=1082197, read_bytes=18626220032,
    1.87 +       write_bytes=24081764352, read_time=5023392, write_time=63199568)
    1.88 +>>>
    1.89 +
    1.90 +
    1.91 +Network
    1.92 +=======
    1.93 +
    1.94 +>>> psutil.net_io_counters(pernic=True)
    1.95 +{'lo': iostat(bytes_sent=799953745, bytes_recv=799953745,
    1.96 +              packets_sent=453698, packets_recv=453698),
    1.97 + 'eth0': iostat(bytes_sent=734324837, bytes_recv=4163935363,
    1.98 +                packets_sent=3605828, packets_recv=4096685)}
    1.99 +>>>
   1.100 +
   1.101 +Other system info
   1.102 +=================
   1.103 +
   1.104 +>>> psutil.get_users()
   1.105 +[user(name='giampaolo', terminal='pts/2', host='localhost', started=1340737536.0),
   1.106 + user(name='giampaolo', terminal='pts/3', host='localhost', started=1340737792.0)]
   1.107 +>>>
   1.108 +>>> psutil.get_boot_time()
   1.109 +1365519115.0
   1.110 +
   1.111 +
   1.112 +Process management
   1.113 +==================
   1.114 +
   1.115 +>>> import psutil
   1.116 +>>> psutil.get_pid_list()
   1.117 +[1, 2, 3, 4, 5, 6, 7, 46, 48, 50, 51, 178, 182, 222, 223, 224,
   1.118 +268, 1215, 1216, 1220, 1221, 1243, 1244, 1301, 1601, 2237, 2355,
   1.119 +2637, 2774, 3932, 4176, 4177, 4185, 4187, 4189, 4225, 4243, 4245,
   1.120 +4263, 4282, 4306, 4311, 4312, 4313, 4314, 4337, 4339, 4357, 4358,
   1.121 +4363, 4383, 4395, 4408, 4433, 4443, 4445, 4446, 5167, 5234, 5235,
   1.122 +5252, 5318, 5424, 5644, 6987, 7054, 7055, 7071]
   1.123 +>>>
   1.124 +>>> p = psutil.Process(7055)
   1.125 +>>> p.name
   1.126 +'python'
   1.127 +>>> p.exe
   1.128 +'/usr/bin/python'
   1.129 +>>> p.getcwd()
   1.130 +'/home/giampaolo'
   1.131 +>>> p.cmdline
   1.132 +['/usr/bin/python', 'main.py']
   1.133 +>>>
   1.134 +>>> str(p.status)
   1.135 +'running'
   1.136 +>>> p.username
   1.137 +'giampaolo'
   1.138 +>>> p.create_time
   1.139 +1267551141.5019531
   1.140 +>>> p.terminal
   1.141 +'/dev/pts/0'
   1.142 +>>>
   1.143 +>>> p.uids
   1.144 +user(real=1000, effective=1000, saved=1000)
   1.145 +>>> p.gids
   1.146 +group(real=1000, effective=1000, saved=1000)
   1.147 +>>>
   1.148 +>>> p.get_cpu_times()
   1.149 +cputimes(user=1.02, system=0.31)
   1.150 +>>> p.get_cpu_percent(interval=1.0)
   1.151 +12.1
   1.152 +>>> p.get_cpu_affinity()
   1.153 +[0, 1, 2, 3]
   1.154 +>>> p.set_cpu_affinity([0])
   1.155 +>>>
   1.156 +>>> p.get_memory_percent()
   1.157 +0.63423
   1.158 +>>>
   1.159 +>>> p.get_memory_info()
   1.160 +meminfo(rss=7471104, vms=68513792)
   1.161 +>>> p.get_ext_memory_info()
   1.162 +meminfo(rss=9662464, vms=49192960, shared=3612672, text=2564096, lib=0, data=5754880, dirty=0)
   1.163 +>>> p.get_memory_maps()
   1.164 +[mmap(path='/lib/x86_64-linux-gnu/libutil-2.15.so', rss=16384, anonymous=8192, swap=0),
   1.165 + mmap(path='/lib/x86_64-linux-gnu/libc-2.15.so', rss=6384, anonymous=15, swap=0),
   1.166 + mmap(path='/lib/x86_64-linux-gnu/libcrypto.so.1.0.0', rss=34124, anonymous=1245, swap=0),
   1.167 + mmap(path='[heap]', rss=54653, anonymous=8192, swap=0),
   1.168 + mmap(path='[stack]', rss=1542, anonymous=166, swap=0),
   1.169 + ...]
   1.170 +>>>
   1.171 +>>> p.get_io_counters()
   1.172 +io(read_count=478001, write_count=59371, read_bytes=700416, write_bytes=69632)
   1.173 +>>>
   1.174 +>>> p.get_open_files()
   1.175 +[openfile(path='/home/giampaolo/svn/psutil/somefile', fd=3)]
   1.176 +>>>
   1.177 +>>> p.get_connections()
   1.178 +[connection(fd=115, family=2, type=1, laddr=('10.0.0.1', 48776),
   1.179 +            raddr=('93.186.135.91', 80), status='ESTABLISHED'),
   1.180 + connection(fd=117, family=2, type=1, laddr=('10.0.0.1', 43761),
   1.181 +            raddr=('72.14.234.100', 80), status='CLOSING'),
   1.182 + connection(fd=119, family=2, type=1, laddr=('10.0.0.1', 60759),
   1.183 +            raddr=('72.14.234.104', 80), status='ESTABLISHED'),
   1.184 + connection(fd=123, family=2, type=1, laddr=('10.0.0.1', 51314),
   1.185 +            raddr=('72.14.234.83', 443), status='SYN_SENT')]
   1.186 +>>>
   1.187 +>>> p.get_num_threads()
   1.188 +4
   1.189 +>>> p.get_num_fds()
   1.190 +8
   1.191 +>>> p.get_threads()
   1.192 +[thread(id=5234, user_time=22.5, system_time=9.2891),
   1.193 + thread(id=5235, user_time=0.0, system_time=0.0),
   1.194 + thread(id=5236, user_time=0.0, system_time=0.0),
   1.195 + thread(id=5237, user_time=0.0707, system_time=1.1)]
   1.196 +>>>
   1.197 +>>> p.get_num_ctx_switches()
   1.198 +amount(voluntary=78, involuntary=19)
   1.199 +>>>
   1.200 +>>> p.get_nice()
   1.201 +0
   1.202 +>>> p.set_nice(10)
   1.203 +>>>
   1.204 +>>> p.suspend()
   1.205 +>>> p.resume()
   1.206 +>>>
   1.207 +>>> p.terminate()
   1.208 +>>> p.wait(timeout=3)
   1.209 +0
   1.210 +>>>
   1.211 +>>> psutil.test()
   1.212 +USER         PID %CPU %MEM     VSZ     RSS TTY        START    TIME  COMMAND
   1.213 +root           1  0.0  0.0   24584    2240 ?          Jun17   00:00  init
   1.214 +root           2  0.0  0.0       0       0 ?          Jun17   00:00  kthreadd
   1.215 +root           3  0.0  0.0       0       0 ?          Jun17   00:05  ksoftirqd/0
   1.216 +...
   1.217 +giampaolo  31475  0.0  0.0   20760    3024 /dev/pts/0 Jun19   00:00  python2.4
   1.218 +giampaolo  31721  0.0  2.2  773060  181896 ?          00:04   10:30  chrome
   1.219 +root       31763  0.0  0.0       0       0 ?          00:05   00:00  kworker/0:1
   1.220 +>>>

mercurial