Simon
I'll answer for Unix:
processor load => uptime
disk usage => df
RAM usage: I don't believe you can do this portably on Unix. On Linux,
you can evaluate the output of 'free' or read /proc/meminfo directly
(with commands.getoutput or os.popen).
For Windows, you'll probably want to download the win32 extensions and
look what goodies there are in the win32api module.
Gerhard
--
Favourite database: http://www.postgresql.org/
Favourite programming language: http://www.python.org/
Combine the two: http://pypgsql.sf.net/
Embedded database for Python: http://pysqlite.sf.net/
Most troublesome is "memory usage", which is not a portable
concept at all, let alone one implemented with portable
access. In fact, what *do* you mean by "memory usage"? Is
that per process? Or are you asking how much RAM the host
recognizes? Or ...?
--
Cameron Laird <Cam...@Lairds.com>
Business: http://www.Phaseit.net
Personal: http://phaseit.net/claird/home.html
Simon
--
http://www.rendermania.com/
"Cameron Laird" <cla...@lairds.com> wrote in message
news:v1c2ppk...@corp.supernews.com...
> by RAM usage I mean total free memory - eg what free gives you under Linux.
> Unix/Linux isn't really the problem, but Windows is as I don't know any
> win32 programming.
As others have pointed out, there are a lot of variables in terms of
just what you want to report in terms of memory usage. But if you
want values that are basically what the Windows Task Manager (at least
under NT/2K/XP - but the API is documented for the 9x series too)
reports, you can use the GlobalMemoryStatus Win32 API function (see
MSDN for the API definition). I believe it still remains unwrapped by
the win32all package, but here's some example code accessing it with
the available calldll module. I'm sure you could also use you can
access it with the available ctypes module (and perhaps more simply),
but that didn't exist when I originally wrote this code.
- - - - - - - - - - - - - - - - - - - - - - - - -
import calldll, struct
result = {}
kernel32 = calldll.load_library('kernel32')
memstat = calldll.get_proc_address(kernel32,'GlobalMemoryStatus')
if memstat:
buf = calldll.membuf(32)
buf.write(struct.pack('1L',32))
calldll.call_foreign_function(memstat,'l','',(buf.address(),))
rtuple = struct.unpack('8L',buf.read())
result['MemoryLoad'] = rtuple[1] # [0] is len
result['TotalPhys'] = rtuple[2]
result['AvailPhys'] = rtuple[3]
result['TotalPageFile'] = rtuple[4]
result['AvailPageFile'] = rtuple[5]
result['TotalVirtual'] = rtuple[6]
result['AvailVirtual'] = rtuple[7]
return result
- - - - - - - - - - - - - - - - - - - - - - - - -
The memory load is in percentage - the other values are all bytes.
This API may not be accurate with more than 2GB of memory in a machine
(it rounds some values down to 2GB) and it will overflow at 4GB -
there's a GlobalMemoryStatusEx call that uses 64-bit return values if
you are worried about such cases, but that's unsupported on the Win 9x
series.
--
-- David
--
/-----------------------------------------------------------------------\
\ David Bolen \ E-mail: db...@fitlinxx.com /
| FitLinxx, Inc. \ Phone: (203) 708-5192 |
/ 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \
\-----------------------------------------------------------------------/