跨平台 获取系统信息的python库 http://support.hyperic.com/disp
生活随笔
收集整理的這篇文章主要介紹了
跨平台 获取系统信息的python库 http://support.hyperic.com/disp
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
跨平臺 獲取系統信息的python庫 http://support.hyperic.com/disp - 張沈鵬,在路上... - ITeye技術網站
跨平臺 獲取系統信息的python庫 http://support.hyperic.com/disp
博客分類:PythonPythonGitLinuxOSWindowsThe 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
總結
以上是生活随笔為你收集整理的跨平台 获取系统信息的python库 http://support.hyperic.com/disp的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JSON.stringify 语法实例讲
- 下一篇: 关于测试行业的零星思考