How can I return system information in Python?
Regarding cross-platform: your best bet is probably to write platform-specific code, and then import it conditionally. e.g.
import sys
if sys.platform == 'win32':
import win32_sysinfo as sysinfo
elif sys.platform == 'darwin':
import mac_sysinfo as sysinfo
elif 'linux' in sys.platform:
import linux_sysinfo as sysinfo
#etc
print 'Memory available:', sysinfo.memory_available()
For specific resources, as Anthony points out you can access /proc
under linux. For Windows, you could have a poke around at the Microsoft Script Repository. I'm not sure where to get that kind of information on Macs, but I can think of a great website where you could ask :-)
In a Linux environment you could read from the /proc file system.
~$ cat /proc/meminfo
MemTotal: 2076816 kB
MemFree: 130284 kB
Buffers: 192664 kB
Cached: 1482760 kB
SwapCached: 0 kB
Active: 206584 kB
Inactive: 1528608 kB
HighTotal: 1179484 kB
HighFree: 120768 kB
LowTotal: 897332 kB
LowFree: 9516 kB
SwapTotal: 2650684 kB
SwapFree: 2650632 kB
Dirty: 64 kB
Writeback: 12 kB
AnonPages: 59668 kB
Mapped: 22008 kB
Slab: 200744 kB
PageTables: 1220 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
CommitLimit: 3689092 kB
Committed_AS: 263892 kB
VmallocTotal: 114680 kB
VmallocUsed: 3604 kB
VmallocChunk: 110752 kB
psutil should provide what you need:
[...] cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network) [...]
[...] supports Linux, Windows, OSX, FreeBSD and Sun Solaris, both 32-bit and 64-bit architectures [...]