跨平台 获取系统信息的python库 http://support.hyperic.com/disp

The Sigar API provides a portable interface for gathering system information such as:

    * System memory, swap, cpu, load average, uptime, logins
    * Per-process memory, cpu, credential info, state, arguments, environment, open files
    * File system detection and metrics
    * Network interface detection, configuration info and metrics
    * Network route and connection tables

Linux Windows 都可以用


内存检测的库 http://support.hyperic.com/display/SIGAR/Home
git clone git://github.com/hyperic/sigar.git sigar.git
./autogen.sh
./configure
make
make install
cd bindings/python/
python setup.py install




xxx@xxxx~/hypertable/sigar.git/bindings/python/examples $ cat free.py
import os, sigar;

sg = sigar.open()
mem = sg.mem()
swap = sg.swap()
sg.close()

print "\tTotal\tUsed\tFree"

print "Mem:\t",\
    (mem.total() / 1024), \
    (mem.used() / 1024), \
    (mem.free() / 1024)

print "Swap:\t", \
    (swap.total() / 1024), \
    (swap.used() / 1024), \
    (swap.free() / 1024)

print "RAM:\t", mem.ram(), "MB"

xxx@xxxx~/hypertable/sigar.git/bindings/python/examples $ python free.py
Total Used Free
Mem: 33018784 20918484 12100300
Swap: 0 0 0
RAM: 32248 MB
xxx@xxxx~/hypertable/sigar.git/bindings/python/examples $ cat df.py
import os, sigar;

sg = sigar.open()
fslist = sg.file_system_list()

def format_size(size):
    return sigar.format_size(size * 1024)

print 'Filesystem\tSize\tUsed\tAvail\tUse%\tMounted on\tType\n'

for fs in fslist:
    dir_name = fs.dir_name()
    usage = sg.file_system_usage(dir_name)

    total = usage.total()
    used = total - usage.free()
    avail = usage.avail()
    pct = usage.use_percent() * 100
    if pct == 0.0:
        pct = '-'

    print fs.dev_name(), format_size(total), format_size(used), format_size(avail),\
        pct, dir_name, fs.sys_type_name(), '/', fs.type_name()
xxx@xxxx~/hypertable/sigar.git/bindings/python/examples $ python df.py
Filesystem Size Used Avail Use% Mounted on Type

/dev/md/2  37G  26G  12G 69.0 / reiserfs / local
proc   0    0    0  - /proc proc / none
sysfs   0    0    0  - /sys sysfs / none
udev  10M 208K 9.8M - /dev tmpfs / none
devpts   0    0    0  - /dev/pts devpts / none
/dev/sda4 391G 321G  70G 83.0 /log2 reiserfs / local
/dev/sdd1 931G 281G 650G 31.0 /mp4 reiserfs / local
/dev/sde1 1.4T 1.3T  75G 95.0 /backup1 xfs / local
/dev/sdf1 1.4T 157G 1.2T 12.0 /backup2 xfs / local
shm  16G   0   16G - /dev/shm tmpfs / none
tmpfs  40M   0   40M - /tmplog tmpfs / none
usbfs   0    0    0  - /proc/bus/usb usbfs / none
/dev/sdb1 1.4T 566G 831G 41.0 /mp5 vfat / local
/dev/sdc1 200G  82G 118G 41.0 /mp3 reiserfs / local

你可能感兴趣的:(linux,windows,python,git,OS)